Page 1 of 3
Changing variable names in several equations
Posted: Thu Mar 01, 2018 2:26 pm
by statsforecast
I changed the text string part of the name of a batch of series. For example, they were named XX1000... and now they are named YY1000... There is one equation per each series (For forecasting). Is there a way to write a program in order to modify the name of the series in the equations instead of having to manually change them one by one?
Thank you in advance to anyone who can help me with this!
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 2:48 pm
by EViews Gareth
Use @wlookup to get a list of all equations in your workfile. Loop through those equations one by one.
For each equation use eqname.@command to retrieve its estimation command. Then use @wreplace to replace the variables in the estimation command, then issue the command to re-estimate the equation.
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 3:21 pm
by statsforecast
Hi Gareth,
Thank you for replying! I have something like this from one of the threads on programming, but the replace part I am not sure where/how to place it
Code: Select all
%eqlist=@wlookup("*","equation") 'make a list of all equations in workfile
for !i=1 to @wcount(%eqlist) 'cycle through the list one at a time
%eq = @word(%eqlist,!i) 'current equation name
%estcmd = {%eq}.@command 'current equation's specification command
@wreplace XX* YY* ' not sure about how to do this step
{%eq}.{%estcmd} 're-estimate current equation with its command
next
Thank you again for your help.
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 3:27 pm
by EViews Gareth
Code: Select all
%estcmd = @replace(%estcmd, "YY", "XX")
{%eq}.{%estcmd}
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 3:39 pm
by statsforecast
Hi Gareth,
It gives me an error:
XX10000...is not defined in "DO_EQ_YY10000.LS (OPTMETHOD=OPG) XX10000 @EXPAND(@MONTH) @EVENT("2016M09") AR(1)"
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 4:19 pm
by statsforecast
I changed the code slightly to:
Code: Select all
%eqlist=@wlookup("*","equation") 'make a list of all equations in workfile
for !i=1 to @wcount(%eqlist) 'cycle through the list one at a time
%eq = @word(%eqlist,!i) 'current equation name
%estcmd = {%eq}.@command 'current equation's specification command
%estcmd = @wreplace(%estcmd, "*XX*" , "*YY*")
{%eq}.{%estcmd} 're-estimate current equation with its command
next
Now it makes the conversion but now an error says "insufficient number of observations" when it tries to estimate each equation
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 4:48 pm
by EViews Gareth
Do you have enough observations?
Re: Changing variable names in several equations
Posted: Thu Mar 01, 2018 8:42 pm
by statsforecast
Yes, I re-estimate these equations periodically and the sample is large enough. The only change is the name of the variables.
Re: Changing variable names in several equations
Posted: Fri Mar 02, 2018 1:08 pm
by statsforecast
I finally was able to figure out the problem. The last time I outputted the forecasts I did it defining the sample to output and that was causing the sample in the workfile to be defined as the forecast sample.
Thank you Gareth for all your help. It is really satisfactory to be able to accomplish a massive task with some lines of code.
Re: Changing variable names in several equations
Posted: Fri Mar 02, 2018 1:28 pm
by EViews Gareth
Great
Re: Changing variable names in several equations
Posted: Wed Mar 07, 2018 2:48 pm
by statsforecast
Hi Gareth,
How can I keep each equation sample estimation when estimating several equations at once?
Code: Select all
%eqlist=@wlookup("*","equation") 'make a list of all equations in workfile
for !i=1 to @wcount(%eqlist) 'cycle through the list one at a time
%eq = @word(%eqlist,!i) 'current equation name
%estcmd = {%eq}.@command 'current equation's estimation command
{%eq}.{%estcmd} 're-estimate current equation with its command
next
When I run this program, it estimates each equation with all the data that each series has instead of estimating each equation with its own estimation sample.
Thank you in advance for your help
Re: Changing variable names in several equations
Posted: Wed Mar 07, 2018 3:11 pm
by EViews Gareth
Retrieve the equation's sample using eq.@smpl, then set the workfile sample to that sample, then re-estimate.
Code: Select all
%eqsmpl = eq.@smpl
smpl {%eqsmpl}
'estimate
Re: Changing variable names in several equations
Posted: Wed Mar 07, 2018 3:34 pm
by statsforecast
It worked! Thank you!
Re: Changing variable names in several equations
Posted: Thu Mar 08, 2018 11:13 am
by statsforecast
Hi Gareth,
In the same line, how can I forecast from all the equations and store the forecasts (defining a forecast sample as fore? For example, For each series in the equation, store the forecast in a new series adding _f to the name. I don't know how to retrieve the name of the series in each equation.
So far I have this
Code: Select all
%eqlist=@wlookup("*","equation") 'make a list of all equations in workfile
for !i=1 to @wcount(%eqlist) 'cycle through the list one at a time
%eq = @word(%eqlist,!i) 'current equation name
smpl fore
{%eq}.forecast {%series}_f 'I don't know how to retrieve %series
series {%series}_f
next
Re: Changing variable names in several equations
Posted: Thu Mar 08, 2018 11:20 am
by EViews Gareth
Use equation.@varlist and @word