Page 1 of 1
Loop over all variables
Posted: Thu Nov 05, 2015 8:33 am
by bdamasio
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.
Re: Loop over all variables
Posted: Thu Nov 05, 2015 8:47 am
by EViews Gareth
Either create a group containing all series:
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.
Re: Loop over all variables
Posted: Thu Nov 12, 2015 1:12 pm
by gsourop
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.
Re: Loop over all variables
Posted: Thu Nov 12, 2015 1:16 pm
by EViews Gareth
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.
Re: Loop over all variables
Posted: Thu Nov 12, 2015 3:33 pm
by gsourop
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.
Re: Loop over all variables
Posted: Thu Nov 12, 2015 4:55 pm
by EViews Gareth
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?
Re: Loop over all variables
Posted: Thu Nov 12, 2015 5:06 pm
by gsourop
I will try to regress them in my models. Each model has many specifications thus I will produce 50 models
Re: Loop over all variables
Posted: Thu Nov 12, 2015 5:15 pm
by EViews Gareth
So if you have variables Y, X1 and X2 and you want to estimate in logs, just use this as the estimation command:
You don't need to create the logged series themselves.
Re: Loop over all variables
Posted: Fri Nov 13, 2015 6:02 am
by gsourop
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?
Re: Loop over all variables
Posted: Fri Nov 13, 2015 8:42 am
by EViews Gareth
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
Re: Loop over all variables
Posted: Fri Nov 13, 2015 8:51 am
by gsourop
Thank you very much!!!!