An introduction to EViews programming.

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

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

Re: An introduction to EViews programming.

Postby EViews Gareth » Fri Aug 12, 2011 7:56 am

EViews doesn't have function plotting abilities yet.
Follow us on Twitter @IHSEViews

startz
Non-normality and collinearity are NOT problems!
Posts: 3584
Joined: Wed Sep 17, 2008 2:25 pm

Re: An introduction to EViews programming.

Postby startz » Fri Aug 12, 2011 7:58 am

You could define the values of x you'd like to see plotted. Create a new series using your formula, and then create an xy graph.

Hottax
Posts: 4
Joined: Tue Aug 09, 2011 1:13 am

Re: An introduction to EViews programming.

Postby Hottax » Fri Aug 12, 2011 11:14 pm

Thank you very much for your explanations. I successfully draw the graph based on the equation Y = X^3 + 2X^2 - X + 4 (using EViews 6)
My next problem is :

How to write an EViews program to find the solution for the equation Y = 0 (Y refers to Y = X^3 + 2X^2 - X +4)
I already read the EViews Command Reference but I did not find how to solve the problem.

Thank you very much.

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

An introduction to EViews programming.

Postby EViews Gareth » Sat Aug 13, 2011 2:10 am

For what you are doing you might be better off with a general mathematical application such as Mathematica
Follow us on Twitter @IHSEViews

aydinktu
Posts: 8
Joined: Mon May 09, 2011 4:41 am

Re: An introduction to EViews programming.

Postby aydinktu » Mon Nov 28, 2011 4:25 pm

EViews Gareth wrote:This program is estimates a number of different equations, each with the same dependent variable, but with different numbers of lags of the dependent variable as regressors. It then selects the number of lags that produces the highest Akaike Information Criterion (AIC). An important aspect of this program is the ability in EViews to specify multiple lags at once by using the form X(-i to -j), which tells EViews to include all lags of X from the ith lag to the jth.

Note that when comparing models with differing numbers of lags, it is important to ensure the sample (the number of observations) used in each model is the same. Thus the program sets the workfile sample to miss the first !maxlags observations, where !maxlags is the maximum number of lags that will be included in the models.

Code: Select all

'create a workfile
wfcreate q 1990 2010

'create a variable
series y = nrnd

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

'variable to store the minimum AIC.  Initialise it to a large number
!aic = 99999999

'variable saying how many lags to go up to
!maxlags = 12

'Variable to store the "best" number of lags
!bestlag = 0

'set sample to be the !maxlag'th value onwards
smpl @first+!maxlags @last

for !i=1 to !maxlags
   eq.ls y c y(-1 to -!i)        'run regression of Y on a constant and lagged values of itself up to the iTH lag.
   if eq.@aic < !aic then
      !bestlag = !i     'if this lag specification has the best AIC, then store this lag as !bestlag.
      !aic = eq.@aic
   endif
next

show eq.ls y c y(-1 to -!bestlag)

'reset sample
smpl @all


The program uses a program variable, !aic, to keep track of the lowest AIC value. This value is initialized to a large number (so that the first equation will definitely have an AIC lower than the initial value). The variable !maxlags is used to specify the maximum number of lags that will be compared. The variable !bestlag is used to keep track of the lag associated with the lowest AIC value.

The smpl command is used to change the workfile sample. The sample is specified by a pair of dates (separated by space), or observation numbers. The @first keyword to specifies the first observation of the workfile, and the @last keyword specifies the last. Thus the line smpl @first+!maxlags @last sets the sample to the !maxlags’th plus one observation to the last observation of the workfile . i.e. if !maxlags I set at 12, the sample will be the 13th observation onwards.

The FOR loop runs from 1 to !maxlags, and thus will run 12 times (since !maxlags has been set to 12). Each iteration re-specifies the equation EQ to include lags up to !i. Once the equation has been re-specified and estimated, an if condition is used to test whether the AIC value from that equation (referenced with the @aic data member) is smaller than the current “best” AIC value stored in !aic. If the current value is smaller, then the current lag is recorded as !bestlag, and the “best” AIC value is reset to the current AIC.

Finally after the loop has finished, the equation is re-estimated using a number of lags equal to !bestlag.


is this possible?

show eq.ls y c y(-1 to -!bestlag)
eq.wald C(2 to !bestlags)=0

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

Re: An introduction to EViews programming.

Postby EViews Gareth » Mon Nov 28, 2011 4:29 pm

No, you'll have to build up the string for the wald test:

Code: Select all

%waldstring = ""
for !i=2 to !bestlags
   %waldstring = %waldstring + "C(" + @str(!i) + ") = 0, "
next
%waldstring = @left(%waldstring, @length(%waldstring)-2)  'trim off the last comma and space
eq.wald {%waldstring}
Follow us on Twitter @IHSEViews

niluki
Posts: 11
Joined: Wed Mar 30, 2011 3:24 am

Re: An introduction to EViews programming.

Postby niluki » Thu Feb 23, 2012 5:05 am

Hi Gareth,

Is there an easy way of 'watching' how the E-Views programme is run.
For example in the for loop below, is there an easy way of getting the following output the "Value of !i(outer loop), Value of !j(inner loop), Resulting Equation Name"

Thanks,
Niluki

EViews Gareth wrote:Program 3 is almost the same as the second program, above, but rather than creating series via numerical program variables, a string variable is used instead:

Code: Select all

'create a workfile
wfcreate q 1990 2010

'create a group which will contain the xs
group xs

'create 5 series
for %i GDP UNEMP INFL CPI M1
   series {%i}=nrnd
   xs.add {%i}
next

'run pairwise regressions between each series
for !i=1 to xs.@count-1
   %iname = xs.@seriesname(!i)
   for !j=!i+1 to xs.@count
      %jname = xs.@seriesname(!j)
      equation eq_{%iname}_{%jname}.ls {%iname} c {%jname}
   next
next


In this program, after creating the workfile we create an empty group that will later be used to hold all of the X variables. We name this group XS.

The FOR loop that creates the series loops through the %i string variable which takes the values of “GDP”, “”UNEMP”, “INFL”, “CPI” and finally “M1”. Each iteration of the loop creates a series with a name equal to the current value of %i. The newly created series is then added to the XS group. Thus the first time through the loop a series called GDP is created, and then added to the XS group. The second time through the loop, a variable called UNEMP is created and added to the XS group.

The second FOR loop is a little more complicated than Program 2. The first thing to notice is the use of the @count group data member in the loops. The @count member returns the number of series in a group.
Thus since there are 5 series in the XS group, xs.@count will equal 5, and xs.@count-1 will equal 4.

The second element of note in the second loop is the use of the @seriesname(i) data member. This data member returns the name of the ith series in the group. Thus xs.@seriesname(1) would return “GDP”.

The first time through the outer loop, %iname will be equal to “GDP” (since !i = 1, xs.@seriesname(!i) will return the name of the first series in XS). The first time through the inner loop, %jname will be equal to “UNEMP” (since !j=!i+1 = 2, xs.@seriesname(!j) will return the name of the second series). The second time through the inner loop, %jname will equal “INFL”, and so on.

At the end of the outer for loop, we will have a number of equations created:

Code: Select all

Value of !i(outer loop)   Value of !j(inner loop)                Resulting Equation Name
1                                       2                                 EQ_GDP_UNEMP
1                                       3                                 EQ_GDP_INFL
1                                       4                                 EQ_GDP_CPI
1                                       5                                 EQ_GDP_M1
2                                       3                                 EQ_UNEMP_INFL
2                                       4                                 EQ_UNEMP_CPI
2                                       5                                 EQ_UNEMP_M1
3                                       4                                 EQ_INFL_CPI
3                                       5                                 EQ_INFL_M1
4                                       5                                 EQ_CPI_M1

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

Re: An introduction to EViews programming.

Postby EViews Gareth » Thu Feb 23, 2012 8:46 am

The only thing you can do is use the statusline command, or the logmsg command to send messages to your screen as the program is running, so you can keep track of where you are.
Follow us on Twitter @IHSEViews

niluki
Posts: 11
Joined: Wed Mar 30, 2011 3:24 am

Re: An introduction to EViews programming.

Postby niluki » Thu Feb 23, 2012 9:24 am

Thanks. Thats very useful!

alafetolu
Posts: 3
Joined: Mon Jun 25, 2012 1:59 am

Re: An introduction to EViews programming.

Postby alafetolu » Mon Jun 25, 2012 3:44 am

Hi, this is my first time on here and I have never done programming before. Please I want to estimate a dependent variable on the permutations of the independent variables. It is like the first example you gave of y and 15x. but in my case I want to run a regression of y on k number of regressors giving 2^k models. for example, y and x1, x2, x3. I want to create a loop where i can estimate:
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
and store the R^2, AIC, and SIC for each model
Please I would be grateful if I can be directed on how to go about this on eviews 6,

EViews Esther
EViews Developer
Posts: 149
Joined: Fri Sep 03, 2010 7:57 am

Re: An introduction to EViews programming.

Postby EViews Esther » Mon Jun 25, 2012 4:19 pm

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

alafetolu
Posts: 3
Joined: Mon Jun 25, 2012 1:59 am

Re: An introduction to EViews programming.

Postby alafetolu » Fri Jul 06, 2012 7:30 am

thank you, since it is not possible do the estimation in the previous versions of e-views, I have decided to type in all the equations i need to run for each sample. i ran this;

wfopen new.wf1
smpl 1979m12 2001m12
equation eq1.ls Y C
equation eq2.ls Y C X1
equation eq3.ls Y C X2
equation eq4.ls Y C X3
equation eq5.ls Y C X1X2
equation eq6.ls Y C X1 X3
equation eq7.ls Y C X2 X3
equation eq8.ls Y C X1 X2 X3

running this program would produce. the output from the eight equations but I also want to store the R^2, AIC, and SIC for each model, instead of having to open all the equation outputs to extract them.
thank you

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

Re: An introduction to EViews programming.

Postby EViews Gareth » Fri Jul 06, 2012 7:51 am

Create a vector/matrix to store the statistics you want, then loop through the equations extracting those statistics from the equations and putting them into the vector/matrix - in the same way the example programs do.
Follow us on Twitter @IHSEViews

alafetolu
Posts: 3
Joined: Mon Jun 25, 2012 1:59 am

Re: An introduction to EViews programming.

Postby alafetolu » Thu Jul 12, 2012 3:57 am

Hello, I have tried running the program, this is an example

wfopen new.wf1
smpl 1979m12 2001m12
equation eq1.ls reit C
equation eq2.ls reit C lreit
equation eq3.ls reit C lterm
equation eq4.ls reit C ldiv
equation eq5.ls reit C lterm ldiv
equation eq6.ls reit C lreit lterm
equation eq7.ls reit C lreit ldiv
equation eq8.ls reit C lreit lterm ldiv

'create vector to store r-squares, AICs, BICs
vector(8) r2s
vector(8) aics
vector(8) bics

!rowcounter=1
r2s(!rowcounter) = eq1.@r2
aics(!rowcounter) = eq1.@aic
bics(!rowcounter) = eq1.@schwarz

!rowcounter=2
r2s(!rowcounter) = eq2.@r2
aics(!rowcounter) = eq2.@aic
bics(!rowcounter) = eq2.@schwarz
!rowcounter = !rowcounter+1

This is just an example of two equations, i have 32 equations to run in each period, does this mean i have to loop through the 32 equations or is there a simpler way of doing this?

Thank you

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

Re: An introduction to EViews programming.

Postby EViews Gareth » Thu Jul 12, 2012 8:00 am

You can loop through the equations (with a FOR loop, as in the examples).
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 15 guests