Changing variable names in several equations
Moderators: EViews Gareth, EViews Jason, EViews Moderator

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Changing variable names in several equations
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!
Thank you in advance to anyone who can help me with this!

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11811
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Changing variable names in several equations
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 reestimate the equation.
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 reestimate the equation.
Follow us on Twitter @IHSEViews

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
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
Thank you again for your help.
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} 'reestimate current equation with its command
next
Thank you again for your help.
Last edited by statsforecast on Thu Mar 01, 2018 3:29 pm, edited 1 time in total.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11811
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Changing variable names in several equations
Code: Select all
%estcmd = @replace(%estcmd, "YY", "XX")
{%eq}.{%estcmd}
Follow us on Twitter @IHSEViews

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
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)"
It gives me an error:
XX10000...is not defined in "DO_EQ_YY10000.LS (OPTMETHOD=OPG) XX10000 @EXPAND(@MONTH) @EVENT("2016M09") AR(1)"

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
I changed the code slightly to:
Now it makes the conversion but now an error says "insufficient number of observations" when it tries to estimate each equation
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} 'reestimate 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

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11811
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Changing variable names in several equations
Do you have enough observations?
Follow us on Twitter @IHSEViews

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
Yes, I reestimate these equations periodically and the sample is large enough. The only change is the name of the variables.

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
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.
Thank you Gareth for all your help. It is really satisfactory to be able to accomplish a massive task with some lines of code.

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

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
Hi Gareth,
How can I keep each equation sample estimation when estimating several equations at once?
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
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} 'reestimate 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

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11811
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Changing variable names in several equations
Retrieve the equation's sample using eq.@smpl, then set the workfile sample to that sample, then reestimate.
Code: Select all
%eqsmpl = eq.@smpl
smpl {%eqsmpl}
'estimate
Follow us on Twitter @IHSEViews

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
It worked! Thank you!

 Posts: 26
 Joined: Wed Feb 28, 2018 8:02 pm
Re: Changing variable names in several equations
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
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

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 11811
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Changing variable names in several equations
Use equation.@varlist and @word
Follow us on Twitter @IHSEViews
Who is online
Users browsing this forum: No registered users and 7 guests