Group Object in a loop

For questions regarding programming in the EViews programming language.

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

adam_77
Posts: 2
Joined: Thu Jan 22, 2009 11:25 pm

Group Object in a loop

Postby adam_77 » Fri Jan 23, 2009 12:21 am

Dear all,
my problem is the following: I running regressions for 10 countries where the time series named as follows. Country_y, Country_X. Where y is the left side var and x the right side var, country is just the county name. What i want to do now is running a loop in which i´m regressing y on x and some leads and lags of the first difference of x for each country. For model selection a info. criterion is to be minimized. So far, i put the y´s and x´s into a group object and also i have a group object with the first differences of the x-series: grp_y, grp_x and dgrp_x

My code looks roughly as follows where i used different example-codes posted in that forum here (by the way, thanks for that!):
for !i=1 to 10
for %country=grp_y.@seriesname(!i)
equation eq_{%country}
!mininfocrit=??? ' i don´t know what to include here
for !lag=2 to 4
eq_{%counry}.ls grp_y(!i) c grp_x(!i) dgrp_x(!i) 'here i want to include leads and lags but the group index seems not to work with the leads and lags
if eq_{%country}.@aic<!mininfocrit then
!bestlag=!lag
!mininfocrit=eq_{%country}.@aic
endif
next
next
eq_{%country}.ls grp_y(!i) c grp_x(!i) dgrp{%country}(-1 to -!bestlag) dgrp{%country}(1 to !bestlag)

Although it might look confused, hope you somehow get my idea and are able to help me or you can point out a different way to do it. Thanks a lot in advance

Gene
EViews Expert
Posts: 20
Joined: Wed Sep 24, 2008 1:08 pm

Re: Group Object in a loop

Postby Gene » Fri Jan 23, 2009 3:32 pm

Here is what I would do... with USA, UK and JPN as the example countries, assuming you have USA_Y, USA_X, UK_Y, UK_X, etc. in your workfile. Notice I don't use the groups.

Code: Select all

for %country USA UK JPN
    equation eq_{%country}
    !mininfocrit=999999
    for !lag=-4 to -2
          eq_{%country}.ls {%country}_y {%country}_x  d({%country}_x)(-1 to !lag)
          if eq_{%country}.@aic<!mininfocrit then
                !bestlag=-!lag
                !mininfocrit=eq_{%country}.@aic
          endif
    Next                           
    eq_{%country}.ls  {%country}_y {%country}_x  d({%country}_x)(-1 to !bestlag)
Next 


You'll have to check out which of the below is the correct syntax:

Code: Select all

d({%country}_x)(-1 to !lag)

or

d({%country}_x(-1 to !lag))

adam_77
Posts: 2
Joined: Thu Jan 22, 2009 11:25 pm

Re: Group Object in a loop

Postby adam_77 » Sat Jan 24, 2009 2:06 am

Hi gene,
thanks for your help. I see what you mean and working with a group object is indeed somewhat cumbersome. But still, there is a error massage saying that ...-1 to -4 is not a valid index. Do you have any further ideas? I tried the syntax both ways
Cheers, Adam

Gene
EViews Expert
Posts: 20
Joined: Wed Sep 24, 2008 1:08 pm

Re: Group Object in a loop

Postby Gene » Tue Jan 27, 2009 12:57 pm

adam_77 wrote:Hi gene,
thanks for your help. I see what you mean and working with a group object is indeed somewhat cumbersome. But still, there is a error massage saying that ...-1 to -4 is not a valid index. Do you have any further ideas? I tried the syntax both ways
Cheers, Adam


Then you'll have to build up the lag part of the equation. There are many ways to do this. One way is to build the equation specifcation string:

Code: Select all

for %country USA UK JPN
    equation eq_{%country}
    !mininfocrit=999999
    %eq_str = %country+"_y " + %country+"_x"
    %best_eq = %eq_str
    for !lag=1 to 4
          %eq_str = %eq_str + " d("+ %country+"_x(-" + @str(!lag)+"))"
          eq_{%country}.ls {%eq_str}
          if eq_{%country}.@aic<!mininfocrit then
                %best_eq=%eq_str
                !mininfocrit=eq_{%country}.@aic
          endif
    Next                           
    eq_{%country}.ls  {%best_eq}
Next 

calculus
Posts: 1
Joined: Wed Jan 07, 2009 3:29 am

Re: Group Object in a loop

Postby calculus » Fri Mar 06, 2009 12:51 am

Hi Gene,
worked out nice. And sorry, been abscent for a long time. Thanks a lot for your help


Return to “Programming”

Who is online

Users browsing this forum: Bob and 39 guests