For Loop of Regressions using a wild card

For questions regarding programming in the EViews programming language.

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

PacNW
Posts: 21
Joined: Fri Apr 01, 2011 4:31 pm

For Loop of Regressions using a wild card

Postby PacNW » Wed Apr 06, 2011 1:02 pm

Is it possible to do a loop that executes a regression for each of the variables in a workfile that begin with a specific string of characters? In the below code I am trying to run a regression for each of the dependent variables that starts with "key", i.e. Key1 Key2, Key3, etc.

I could write out the dependent variables but unfortunately this vector changes each time.

for %0 Key*
equation eq_{%0}.ls c A B
forecast {%0}f
next

Is there some other way to perform this loop? EViews does not allow the wildcard expression (*) to be used since it is an illegal or reserved name.

Thanks!
PacNW

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

Re: For Loop of Regressions using a wild card

Postby EViews Gareth » Wed Apr 06, 2011 1:06 pm

Code: Select all

%deplist = @wlookup("key*", "series") 'create a list of all series that match the pattern key* for %dep %deplist 'cycle through the members of the list one at a time. equation eq_{%dep}.ls {%dep} c a b next

PacNW
Posts: 21
Joined: Fri Apr 01, 2011 4:31 pm

Re: For Loop of Regressions using a wild card

Postby PacNW » Wed Apr 06, 2011 2:32 pm

Thanks for the quick reply!

I tried your code and I get a Syntax Error message at the "For" line

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

Re: For Loop of Regressions using a wild card

Postby EViews Gareth » Wed Apr 06, 2011 2:39 pm

My bad:

Code: Select all

%deplist = @wlookup("key*", "series") 'create a list of all series that match the pattern key* for %dep {%deplist} 'cycle through the members of the list one at a time. equation eq_{%dep}.ls {%dep} c a b next

PacNW
Posts: 21
Joined: Fri Apr 01, 2011 4:31 pm

Re: For Loop of Regressions using a wild card

Postby PacNW » Wed Apr 06, 2011 2:53 pm

worked like a charm, thank you

PacNW
Posts: 21
Joined: Fri Apr 01, 2011 4:31 pm

Re: For Loop of Regressions using a wild card

Postby PacNW » Wed Apr 06, 2011 5:45 pm

I might be reaching here, but I'll give it a shot...

How would I change the code you posted...

%deplist = @wlookup("key*", "series") 'create a list of all series that match the pattern key*
for %dep {%deplist} 'cycle through the members of the list one at a time.
equation eq_{%dep}.ls {%dep} c a b
next

...if I wanted to repeat the process for another set of variables, in addition to "key"? So run the exact same process for "minor*". (Of course I could simply post a new set of code below it, but I'm really asking how to do it for 20 other sets of variables in a giant loop)

I tried a series of nested brackets but could not get it to execute.

Thanks!

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

For Loop of Regressions using a wild card

Postby EViews Gareth » Wed Apr 06, 2011 6:53 pm

Code: Select all

%keylist = @wlookup("key*", "series") %minorlist = @wlookup("minor*", "series") For %dep {%keylist} {%minorlist} 'same stuff here
(sent from my phone, so might have mistakes)

PacNW
Posts: 21
Joined: Fri Apr 01, 2011 4:31 pm

Re: For Loop of Regressions using a wild card

Postby PacNW » Wed Apr 06, 2011 7:17 pm

Excellent.

Sending code from a phone... whatever you get paid, they should double it.

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: For Loop of Regressions using a wild card

Postby EViews Glenn » Thu Apr 07, 2011 11:08 am

Not really. We only let him work from a phone. No computer. He can't get into as much trouble that way.
:lol:


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest