An introduction to EViews programming.

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator

CharlieEVIEWS
Posts: 202
Joined: Tue Jul 17, 2012 9:47 am

Re: An introduction to EViews programming.

Postby CharlieEVIEWS » Sun Jul 28, 2013 2:45 pm

Many thanks as always! My next step was to estimate this recursively (where I want !j to represent an expanding window for periods 1,2,..20 -in this case using a bvar with NW priors) - which is a for loop inside a for loop I suppose (?):

Code: Select all

genr laaa=log(aaa)
genr lbbb=log(bbb)
genr lccc=log(ccc)
genr lddd=log(ddd)
for !j= 1 to 20
var bvar_4_n_{!j}
!aic = 99999999
!maxlags = 12
!bestlag = 0
smpl @first+!maxlags @last-34+!j
for !i=1 to !maxlags
  bvar_4_n_{!j}.bvar(prior=nw) 1 !i laaa lbbb lccc lddd
   if bvar_4_n_{!j}.@aic < !aic then
      !bestlag_{!j} = !i     
      !aic = bvar_4_n_{!j}.@aic
   endif
next
show bvar_4_n_{!j}.bvar(prior=nw) 1 !bestlag_{!j} laaa lbbb lccc lddd
next
'reset sample
smpl @all


which I thought I had done correctly when applying it to some actual data. However, upon closer inspection (clicking the menu for each of the twenty recursive windows), I realised that something was going wrong, in that when i clicked the lag length spec option through the menus, it would suggest a different lag length to the one which was actually being estimated in the VAR window for some of the windows.

Do you mind sharing what I am doing wrong? The learning curve is steeper than expected with this kind of thing!

trubador
Did you use forum search?
Posts: 1518
Joined: Thu Nov 20, 2008 12:04 pm

Re: An introduction to EViews programming.

Postby trubador » Mon Jul 29, 2013 1:56 am

Nothing is wrong there. EViews automatically specifies the maximum lag order for which you wish to test. It is not the result of the test and you can always change it.
I am not sure if this type of lag length selection approach is appropriate within the Bayesian VAR context, but the following would be doing what you want do do.

Code: Select all

...
for !j= 1 to 20
var bvar_4_n_{!j}
!maxlags = 12
!bestlag_{!j} = 0
smpl @first+!maxlags @last-34+!j
  bvar_4_n_{!j}.bvar(prior=nw) 1 !maxlags laaa lbbb lccc lddd
  bvar_4_n_{!j}.laglen(!maxlags,mname=lagcrit)
  !bestlag_{!j} = lagcrit(!maxlags+2,4)
  !aic = lagcrit(!maxlags+1,4)
    if !bestlag_{!j} = 0 then
       matrix aicvec = @subextract(lagcrit,2,4,!maxlags+1,4)
       !aic = @cmin(aicvec)
       !bestlag_{!j} = @cimin(aicvec)
       delete aicvec
    endif
show bvar_4_n_{!j}.bvar(prior=nw) 1 !bestlag_{!j} laaa lbbb lccc lddd
delete lagcrit
next
...

dreavis
Posts: 10
Joined: Fri Nov 15, 2013 3:52 pm

Re: An introduction to EViews programming.

Postby dreavis » Fri Nov 15, 2013 4:18 pm

I am new to Eviews and have programming experience in SAS and SQL, and I am stuck now. I am trying to simply estimate an equation, store the equation, and then create a forecast from that equation, and save it too.

I have my data in a workfile ready to go, my estimation commands ready to go... I run one and a results widow opens - a good sign I think. For what it is worth, I have tried to answer my own question before asking, but I can't find a post that is as simple as what I need to do. So, take pity on this newbie and help me if you can.

Thank you,

DR

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Fri Nov 15, 2013 4:36 pm

I'm not sure what your question is
Follow us on Twitter @IHSEViews

dreavis
Posts: 10
Joined: Fri Nov 15, 2013 3:52 pm

Re: An introduction to EViews programming.

Postby dreavis » Fri Nov 15, 2013 5:36 pm

I'm sorry... I am trying to figure out how to write my program to run my estimation, without having to click through the windows:

cointeg....
then store the results to an equation...
then create a forecast from the equation...
store that to a new variable

I am stuck because I don't know what order to write this, do I specify the equation first? I did figure out how to create an equation but it was empty, so I know I did something in the wrong order. That is as far as I have gotten.

Thank you

I have been meaning to post an update for anyone who may need the same information. This is what I ended up using (main source was the help documentation).

This executes the estimation to get the equation and stores the equation named "eq_a_2013q4"
equation eq_a_2013q4.COINTREG(METHOD=DOLS,LAG=0, LEAD=1, NODF) depvar_2013q4 indepvar1(-2) indepvar2(-2)

By the way, you can get the estimation command, if you have been using Quick > Estimate Equation from the resulting equation window click View Button > Representations and it is the first thing listed.

This uses that equation to create a forecast: (Yes, it is this easy.) The forecast is stored as a series named "fc_name_a_2013q4".
eq_a_2013q4.forecast fc_name_a_2013q4
Last edited by dreavis on Thu Apr 10, 2014 11:36 am, edited 1 time in total.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Fri Nov 15, 2013 7:07 pm

This guide has many examples of creating and estimating equations.
Follow us on Twitter @IHSEViews

Jirka
Posts: 6
Joined: Tue Nov 19, 2013 4:12 pm

Re: An introduction to EViews programming.

Postby Jirka » Tue Nov 19, 2013 4:45 pm

EViews Esther wrote:The code below will work.

Code: Select all

'create a workfile
wfcreate q 1990 2010

'create a dependent variable
series y = nrnd

'create 3 series
series x1 = nrnd
series x2 = nrnd
series x3 = nrnd

%regs = "x1 x2 x3"
!L = @wcount(%regs)

'create vector to store r-squares, AICs, BICs
vector(2^!L) r2s
vector(2^!L) aics
vector(2^!L) bics
svector(2^!L) specs

'create empty equation to be used inside the loop
equation eq

'1. Make an index vector which contains either 0 or 1 (Convert2Binary)
'2. drop x if index=0, otherwise take x
!rowcounter=1   'counter of how many equations we have run
for !i = 0 to (2^!L)-1
     vector(!L) index
     !temp= !i
   call Convert2Binary(index, !temp)   
   %xs = ""
   for !j = 1 to !L
      %reg = @word(%regs,!j)
      if index(!j)==1 then   
         %xs = %xs + %reg + " "
      endif
   next
   eq.ls y c {%xs}
   r2s(!rowcounter) = eq.@r2
   aics(!rowcounter) = eq.@aic
   bics(!rowcounter) = eq.@schwarz
   specs(!rowcounter) = eq.@spec
   !rowcounter = !rowcounter+1
next
d(noerr) index

subroutine local Convert2Binary(vector out, scalar N)
   if N<0 then
      stop
      return
   endif
   !i = @rows(out)
   while N > 1
      !a = @floor(N/2)
      out(!i) = N-2*!a
      !i = !i - 1
      N = !a
   wend
   out(!i) = N   
endsub


Hello,
I need to run the same type of program, it means regressions
Y= C(constant)
Y= C + X1
Y= C+ X2
Y= C+X3
Y= C+ X1+X2
Y= C+ X1+X3
Y= C+ X2+X3
Y= C+ X1+X2+X3
but I want to store also all coefficients (in a matrix, or in vectors) I have been never programming before, but I inspired myself on this forum and tried to add to your program a matrix for coeffs

matrix((2^!L), !L) coeffs

and comand to store them

rowplace(coeffs, eq.@coefs, !rowcounter)

But when I run the program, it shows a Matrix size mismatch... I spent a long time trying some other possibilities, but always with the same result. Please, could you help me? I would be werry grateful.
Best regards
Jirka from CZ

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Tue Nov 19, 2013 5:05 pm

The problem is that you have a matrix with !L columns. i.e. each row is of size !L. You're then trying to place into each row the coefficients from each equation. However the number of coefficients is different in each equation, so the rowplace fails - you can't put a vector of 5 coefficients into a row that is of size 7 (say).

You should use the matplace function instead of rowplace to only insert into a subset of your storage matrix.
Follow us on Twitter @IHSEViews

Jirka
Posts: 6
Joined: Tue Nov 19, 2013 4:12 pm

Re: An introduction to EViews programming.

Postby Jirka » Wed Nov 20, 2013 3:48 pm

Thank you very much for quick reply. After some bad attempts I found this way to do it:

Matrix to store:

matrix(!L+1, (2^!L)) coeffs

Add a colcounter
!colcounter=1

store coeffs
matplace(koeficienty, eq.@coefs, 1, !colcounter)
!colcounter=!colcounter+1

The matrix has 4 rows for C, X1, X2, X3 and each collum is for one equation (8 collums). Bud the problem is, that each coeff. has not its own row. The matrix looks like this (in free cells eviews places 0, which is OK):

C...C...C...C...C.....C....C ...C
....X3..X2..X2 ..X1...X1...X1..X1
..............X3........X3...X2..X2
....................................X3

Is there any way to make coeffs. to have each its own row? I need to make histogram for each coeff and it is not possible, if they are in various rows. (I need to run much more equations with more variables than only three... I am afraid, that there is no way to achieve this, but some researcher in a working paper run 32 000 regressions (with 15 variables) and made histogram for each parameter, so there must be a way to do this... If you know the way, I would appreciate, if you wrote me the command...

Thank you
Regards
Jirka

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Wed Nov 20, 2013 4:06 pm

You'll have to figure out the logic for that yourself, I'm afraid
Follow us on Twitter @IHSEViews

Jirka
Posts: 6
Joined: Tue Nov 19, 2013 4:12 pm

Re: An introduction to EViews programming.

Postby Jirka » Tue Nov 26, 2013 3:17 pm

I have come to a trick in Excel how to separate the coeffs, so it is OK now. Thanks.

Jirka
Posts: 6
Joined: Tue Nov 19, 2013 4:12 pm

Re: An introduction to EViews programming.

Postby Jirka » Thu Dec 19, 2013 4:03 am

Hi, I would have another question concerning to the program above (run number of regressions with all permutations of variables):
1) How can I do it on panel data with fixed effects? Is it possible? If so, could you write me a command please?
2) Suppose, I have one given equation Y = C + X1 + X2 with autocorelation and I need to test all possible combinations of AR or MA or both (ARMA), which is the best. For example to test
Y = C + X1 + X2 AR(1) MA(1) or AR(1) MA(2) and so on--------AR(8) MA(4).... for example all combinations of AR and MA to level 8 each.

Thank you
Jirka

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Thu Dec 19, 2013 8:47 am

Use the (cx=f) option with the LS command to include fixed effects.

Take a look at the ARIMASel add-in (http://www.eviews.com/Addins/addins.shtml) for automatic ARIMA selection.
Follow us on Twitter @IHSEViews

rileyjiang
Posts: 2
Joined: Mon Mar 11, 2013 7:51 pm

Re: An introduction to EViews programming.

Postby rileyjiang » Fri Dec 20, 2013 7:54 pm

Dear Garath,

I’m a PhD student and fairly new to EViews programing. But I have been reading and learning the programs you posted up here in the past several days. I found them very helpful.
I have a question in relation to EViews programing. It’s for my PhD study and I was hoping you that could help me. Part of my PhD study involves testing statistical robustness of explanatory regressors in explaining dependent variable. When testing variable’s robustness, one often encounters the following situation: x1 (an explanatory regressor) may be statistically significant in explaining the dependent variable when the regression includes x2 and x3, but not when x4 is included. So, which combination of all available x’s do we choose? To tackle this, we use extreme bound analysis (hereafter EBA) which is a liner regression based analysis to find out if there is robustness in the determinants of the dependent variable.
EBA estimates liner regression in a fashion that it tests all combinations of the available regressors as opposed to selectively test some combinations and report the ones that “favour” the most (in the situation above, the most favourable combo to x1 would be x1,x2,x3). Because EBA stretches variable combination to an extreme, it can get tricky sometimes when modelling regression equation under EBA because the amount of regressions estimated can get potentially very large (in some cases exponentially).
In terms of data, my data sample (cross sectional) contains 1 dependent variable and 21 regressors, if we were to include 11 regressors in our model, according to EBA, the total combinations of the available regressors to be tested will be 352,716. This is determined by the mathematical formula “n!/[(n-r)!*r!]”. Now fix one regressor in our model because we want to test how robust it is when put against all the other regressors, we then have 10 regressors (11 minus 1) readily free to choose from 20 regressors (i.e. 21 minus 1, since 1 is locked-in now) in forming the regressor part of our model. The total combinations now become 184,756.
While having found a way to tackle the challenge in which led me into running over 3.8 million regressions*, I was hoping if there is any way to program it, in terms of running the regressions more efficiently as well as extracting key stats such as R^2, beta coefficient and t-stats with no need to open every single equation. This came after I read the programs you post up here, in particular Program No.2 which runs pairwise regressions between each X and every other X.
*3.8m=184,756 combinations for testing 1 regressor * 21 regressors
Just to quickly show you the way I did it (v tedious, but I guess it’s still better than manually typing up some 184 thousand regressions one by one):
The process is fairly straight forward. Since I have discovered a website-based combination calculator and it uses letters to represent combination entry, I coded the name of all 21 regressors in letter for easy modelling. Next, generating combinations; since we want to test each regressor’s robustness against a combination of 10 other regressors, we need to run 184,756 regressions in order to test them all. This number represents the total possibility of a 10 regressor combination choosing from a set of 20 regressors. The first combination is “a b c d e f g h i j”.
Because we want to have one regressor that appears in each and every regression equation in order to test its statistical robustness, I put one non-conflict letter in the model to represent it, namely “z”. The regressor combination of our first equation now becomes “z a b c d e f g h i j”.
The next step is to construct a model that EViews Program understands; the first equation is constructed as follows (I used “aa” instead of only “a” because some of the names are reserved in EViews, e.g. “c” for beta coefficient):
“equation zabcdefghij.ls score c zz aa bb cc dd ee ff gg hh ii jj” (“score” is my dependent var)
And the last equation:
“equation zklmnopqrst.ls score c zz kk ll mm nn oo pp qq rr ss tt“
As soon as all the combinations are properly formatted into equation, I plugged them into the EViews Program and let the program generates equation output itself. It turns out EViews Program has a limit. Apparently I can only type in somewhere around 10,000 equations at a time. Nonetheless, I managed to finish it. For every 184,756 regressions I run, I create a new workfile and change the “zz” for the next regressor to be tested.
For statistics reporting (e.g. R^2, beta coefficient etc.), I used Add-in “EqTab”. However, I discover that this giant spreadsheet also has a limit and it takes literally hours to generate the output and crashes the whole system very often.
In my opinion, the process I used is to some extent manageable. However, it is by no mean replicable or re-usable. For instance, if we want to change the total number of regressors from 21 to say 15 and decrease the regressors included in the model from 11 to 5, we then have to go back to Day 1 and re-write the whole model because the number of combinations is no longer the same.

Thank you very much for your help in advance and I look forward to hearing from you.

Any thoughts and comments are greatly appreciated.

Merry Christmas and Happy New Year!

Kind Regards,
Riley

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 11373
Joined: Tue Sep 16, 2008 5:38 pm

Re: An introduction to EViews programming.

Postby EViews Gareth » Sat Dec 21, 2013 3:50 pm

To be honest, you're crazy for trying to do this operation in a canned regression package. For such a structured procedure, you're much better off writing an algorithm in a matrix language (even the EViews matrix language) that takes advantage of all the tricks you can perform on the moment matrix to swap variables in and out.
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: Bing [Bot] and 5 guests