Changing variable names in several equations

For questions regarding programming in the EViews programming language.

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

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Changing variable names in several equations

Postby statsforecast » Thu Mar 01, 2018 2:26 pm

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!

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

Re: Changing variable names in several equations

Postby EViews Gareth » Thu Mar 01, 2018 2:48 pm

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.
Follow us on Twitter @IHSEViews

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 01, 2018 3:21 pm

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.
Last edited by statsforecast on Thu Mar 01, 2018 3:29 pm, edited 1 time in total.

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

Re: Changing variable names in several equations

Postby EViews Gareth » Thu Mar 01, 2018 3:27 pm

Code: Select all

%estcmd = @replace(%estcmd, "YY", "XX")
{%eq}.{%estcmd}
Follow us on Twitter @IHSEViews

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 01, 2018 3:39 pm

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)"

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 01, 2018 4:19 pm

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

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

Re: Changing variable names in several equations

Postby EViews Gareth » Thu Mar 01, 2018 4:48 pm

Do you have enough observations?
Follow us on Twitter @IHSEViews

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 01, 2018 8:42 pm

Yes, I re-estimate these equations periodically and the sample is large enough. The only change is the name of the variables.

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Fri Mar 02, 2018 1:08 pm

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.

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

Re: Changing variable names in several equations

Postby EViews Gareth » Fri Mar 02, 2018 1:28 pm

Great
Follow us on Twitter @IHSEViews

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Wed Mar 07, 2018 2:48 pm

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

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

Re: Changing variable names in several equations

Postby EViews Gareth » Wed Mar 07, 2018 3:11 pm

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
Follow us on Twitter @IHSEViews

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Wed Mar 07, 2018 3:34 pm

It worked! Thank you!

statsforecast
Posts: 26
Joined: Wed Feb 28, 2018 8:02 pm

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 08, 2018 11:13 am

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

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

Re: Changing variable names in several equations

Postby EViews Gareth » Thu Mar 08, 2018 11:20 am

Use equation.@varlist and @word
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 27 guests