Loop over all variables

For questions regarding programming in the EViews programming language.

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

bdamasio
Posts: 20
Joined: Tue Nov 05, 2013 4:49 am

Loop over all variables

Postby bdamasio » Thu Nov 05, 2015 8:33 am

Hello, I want to apply certain procedures to all variables in my data set.
So I want to loop over all variables in my dataset.
How should I build the loop?
How can I evoque all variables?

One possible way is to store all variable names into a string using "names=@wlookup("*","series")" and then build the loop over the string "names". Am I right?

How can I do that?

Thank you.
B.
Last edited by bdamasio on Thu Nov 05, 2015 8:59 am, edited 1 time in total.

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

Re: Loop over all variables

Postby EViews Gareth » Thu Nov 05, 2015 8:47 am

Either create a group containing all series:

Code: Select all

group g *
and loop through the members of the group, or use the @wlookup function to retrieve the names of every series in the workfile and loop through them.


Either way, remember that RESID is a series in your workfile, and you probably don't want to do whatever you're doing to RESID.

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

Re: Loop over all variables

Postby gsourop » Thu Nov 12, 2015 1:12 pm

Hi everyone,

I have series as independent variables x1,x2...x150 and I want to create the log of these series. Does anyone know if there is any other efficient way instead of doing it manually (meaning, to write for every single variable log_xi=log(xi), for i=1,2..150)? Is it possible to keep the name of the variable as it is and just add a term for example log_x1,log_x2...log_x150.

Thank you very much, in advance.

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

Re: Loop over all variables

Postby EViews Gareth » Thu Nov 12, 2015 1:16 pm

Are you sure you want to create series that are equal to the log of the original series? It is pretty rare that you would want to do that in EViews, since you can just use the expression log(x1) inline.

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

Re: Loop over all variables

Postby gsourop » Thu Nov 12, 2015 3:33 pm

Yes, because I would prefer to do it on that way than manually, it also looks more professional :D !! I will omit the transformation of certain variables, that are not needed to be logged, such as interest rates, though, all the others have to be transformed.

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

Re: Loop over all variables

Postby EViews Gareth » Thu Nov 12, 2015 4:55 pm

No, the point is that you don't need to create new series in EViews.

What are you going to do with all the transformed variables?

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

Re: Loop over all variables

Postby gsourop » Thu Nov 12, 2015 5:06 pm

I will try to regress them in my models. Each model has many specifications thus I will produce 50 models

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

Re: Loop over all variables

Postby EViews Gareth » Thu Nov 12, 2015 5:15 pm

So if you have variables Y, X1 and X2 and you want to estimate in logs, just use this as the estimation command:

Code: Select all

ls log(y) c log(x1) log(x2)
You don't need to create the logged series themselves.

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

Re: Loop over all variables

Postby gsourop » Fri Nov 13, 2015 6:02 am

Thank you very much Gareth for the help. One last try on this issue...If I write something like:

group xs
for %i x1 x2 x3 x4 'up to 150
xs.add {%i}
next

for !i=1 to xs.@count
series x{!i}=log({!i})
next

EVIEWS creates 4 series and gives me log(1), log(2) and not log(x1), log(x2) etc.

If I change the code to

group xs
for %i x1 x2 x3 x4 'up to 150
xs.add {%i}
next

for !i=1 to xs.@count
series x{!i}=log({%i})
next

EVIEWS creates 4 series (as in my example I create only x1 x2 x3 x4), each one is identical to the other, and they are all equal to log(x4) ...ie the last variable of the group. What am I missing here?

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

Re: Loop over all variables

Postby EViews Gareth » Fri Nov 13, 2015 8:42 am

Code: Select all

group xs for %i x1 x2 x3 x4 'up to 150 xs.add {%i} next for !i=1 to xs.@count series x{!i}=log(xs({!i})) next

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

Re: Loop over all variables

Postby gsourop » Fri Nov 13, 2015 8:51 am

Thank you very much!!!!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests