Loops and text

For questions regarding programming in the EViews programming language.

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

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

Loops and text

Postby AnnH » Fri Mar 09, 2012 12:08 pm

I am trying to rework a program that had been written under a version of eviews before eviews 7. When I use the following code, I get estimates for all three equations and they appear in my workfile:

WORKFILE A1 q 1947:1 2014:2
READ(t=xls, b10, na=na) "H:\model\Data\input\data1.xls" Aa Ba Ca
GROUP ALL Aa Ba Ca
STORE ALL
WORKFILE A2 q 1947:1 2014:2
FETCH ALL
equation eq_Aa
eq_Aa.ls Aa c @trend^2 Aa(-1) ar(1)
STORE eq_Aa
equation eq_Ba
eq_Ba.ls Ba c @trend^2 Ba(-3) ar(1)
STORE eq_Ba
equation eq_Ca
eq_Aa.ls Aa c @trend^2 Ca(-1) ar(1)
STORE eq_Ca

I am trying to accomplish the same thing with a loop, and cannot figure out why the following does not work (there is an icon for each equation in the workfile, but when I click on each one I get the message "Equation does not have estimates":

WORKFILE A1 q 1947:1 2014:2
READ(t=xls, b10, na=na) "H:\model\Data\input\data1.xls" Aa Ba Ca
GROUP ALL Aa Ba Ca
STORE ALL
WORKFILE A2 q 1947:1 2014:2
FETCH ALL
FOR !k = 1 to All.@count
%k = All.@seriesname(!k)
equation eq_{%k}
IF %k = "Aa" THEN
eq_{%k}.ls {%k} c @trend^2 {%k}(-1) ar(1)
ENDIF
IF %k = "Ba" THEN
eq_{%k}.ls {%k} c @trend^2 {%k}(-3) ar(1)
ENDIF
IF %k = "Ca" THEN
eq_{%k}.ls Aa c @trend^2 {%k}(-1) ar(1)
ENDIF
STORE eq_{%k}
next

I think there may be some problem with my IF %k = "Aa" THEN statements, but I cannot seem to figure out what.

Thanks. :D

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

Re: Loops and text

Postby EViews Gareth » Fri Mar 09, 2012 12:22 pm

The .@seriesname(!k) datamember will return the name of the series in uppercase. Thus you should have a check along the lines of:

Code: Select all

if %k = "AA" then

AnnH
Posts: 22
Joined: Fri Mar 09, 2012 11:42 am

Re: Loops and text

Postby AnnH » Fri Mar 09, 2012 2:32 pm

How simple.... it works!
Thanks so much for the quick reply!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests