Page 1 of 1

For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 1:02 pm
by PacNW
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

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 1:06 pm
by EViews Gareth

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

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 2:32 pm
by PacNW
Thanks for the quick reply!

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

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 2:39 pm
by EViews Gareth
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

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 2:53 pm
by PacNW
worked like a charm, thank you

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 5:45 pm
by PacNW
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!

For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 6:53 pm
by EViews Gareth

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)

Re: For Loop of Regressions using a wild card

Posted: Wed Apr 06, 2011 7:17 pm
by PacNW
Excellent.

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

Re: For Loop of Regressions using a wild card

Posted: Thu Apr 07, 2011 11:08 am
by EViews Glenn
Not really. We only let him work from a phone. No computer. He can't get into as much trouble that way.
:lol: