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

Re: Changing variable names in several equations

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

That seems to work but the equations in which I use Log generate errors: LOG is an illegal or reserved name in "DO_ EQ_XX10012503.
FORECAST LOG(XX10012503)_F". Below is the code I am using:

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
   %var = {%eq}.@varlist
    %var = @word(%var,1)
smpl fore
{%eq}.forecast {%var}_f
series  {%var}_f
next

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

Re: Changing variable names in several equations

Postby EViews Gareth » Thu Mar 08, 2018 12:11 pm

use @makevalidname
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 » Fri Mar 09, 2018 10:44 am

Hi Gareth,

This works but is not exactly what I need given the set up I already have in E-views and it would mean further work. I am trying to include and IF statement in order to trim the invalid names in order to make valid ones (since all the names follow the same pattern and the ones that are invalids are the ones with log). It would be something like this, but since I am new in E-views programming I am not sure about how to include if statements. Could you help me out please?

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
   %var = {%eq}.@varlist
    %var = @word(%var,1)
if %var = "invalid name" then    'I don't know how to include the error
   %var = @wmid(%var,10,4)
  smpl fore
{%eq}.forecast {%var}f
next

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

Re: Changing variable names in several equations

Postby statsforecast » Fri Mar 09, 2018 10:53 am

Or perhaps loop through both the equations and the series names? but I am not sure how to get the two loops to work properly

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
 %serieslist=@wlookup("*","series")   'make a list of all series in workfile
for !j=1 to @wcount(%serieslist)     'cycle through the list one at a time
   %series =  @word(%serieslist,!j) 'current series name
  smpl fore
{%eq}.forecast  {%series}f
       next
  next

This doesn't seem to do the trick

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

Re: Changing variable names in several equations

Postby statsforecast » Fri Mar 09, 2018 10:58 am

I got it! this worked:

Code: Select all

%serieslist=@wlookup("*","series")   'make a list of all series in workfile
for !j=1 to @wcount(%serieslist)     'cycle through the list one at a time
   %series =  @word(%serieslist,!j) 'current series name
  smpl fore
eq_{%series}.forecast  {%series}f
       next

It was so simple! Thanks anyway.

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

Re: Changing variable names in several equations

Postby statsforecast » Tue Mar 13, 2018 8:58 am

Hi Gareth,

As the following step in this process, I am trying to write a program that after estimating an equation (or rather a batch of equations), looks at the residuals and if the last data point is outside the bands of the residuals graph, put a dummy in the equation with the date associated with that observation. For example, since I have monthly data, a dummy of the type: @event("2018.02") for the last month of data.

Perhaps accessing the residuals table: eqname.resids(t)?
I just don't know how to access the elements of that table in order to write a IF statement or something similar.

Thank you in advance for any help that you can provide.

EViews Matt
EViews Developer
Posts: 302
Joined: Thu Apr 25, 2013 7:48 pm

Re: Changing variable names in several equations

Postby EViews Matt » Tue Mar 13, 2018 9:40 am

Hello,

It would probably be easier to use the makeresids proc to copy the residuals to a series and then access that series.

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

Re: Changing variable names in several equations

Postby statsforecast » Wed Mar 28, 2018 1:58 pm

Hi Gareth,

I have been trying with the makeresids proc and it works for generating series for each equation's residuals, but when I try to generate series for the dates of those series, the dates are shifted. I can't figure out why isn't working properly.

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
  %eqsmpl =  {%eq}.@smpl
   smpl {%eqsmpl}
     'estimate ecuation keeping each estimation sample
   {%eq}.{%estcmd}  're-estimate current equation with its command
  {%eq}.makeresids res{%eq} 'generate series with residuals
  series dateres{%eq}=@date(res{%eq}) 'generate a series of the dates of the residuals
  next
 smpl @all 'reset sample


Thank you in advance for your help.

EViews Matt
EViews Developer
Posts: 302
Joined: Thu Apr 25, 2013 7:48 pm

Re: Changing variable names in several equations

Postby EViews Matt » Wed Mar 28, 2018 2:40 pm

Just use "@date" instead of "@date(res{%eq})". You generate dates based on the workfile sample and frequency, not on a specific series. The "(res{%eq})" term shifts the dates by the amount of the first residual, which you observed.

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

Re: Changing variable names in several equations

Postby statsforecast » Wed Mar 28, 2018 3:05 pm

Thank you for replying Gareth. What I am trying to do is to get the last date for which the series have data (the data of the most recent data point), since I am trying to add a dummy for that date if certain conditions are met. I've been trying something like this but it doesn't work too well.

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
  %eqsmpl =  {%eq}.@smpl
   smpl {%eqsmpl}
     'estimate ecuation keeping each estimation sample
   {%eq}.{%estcmd}  're-estimate current equation with its command
  {%eq}.makeresids res{%eq}
 series dateres{%eq}=@date(res{%eq})
    if  @last(res{%eq}) > (res({%eq}) + @stderrs(res{%eq})) or @last(res{%eq})  < (res({%eq}) + @stderrs(res{%eq})) then
   %estcmd = {%eq}.@command +  "@event("@last(dates{%eq}")"
  endif
 next
 smpl @all 'rese

EViews Matt
EViews Developer
Posts: 302
Joined: Thu Apr 25, 2013 7:48 pm

Re: Changing variable names in several equations

Postby EViews Matt » Wed Mar 28, 2018 3:26 pm

x.@last will return the date (as a string) of the last non-NA observation in series x.

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

Re: Changing variable names in several equations

Postby statsforecast » Wed Mar 28, 2018 5:12 pm

Thank you for replying Matt.

When I try the following it generates an error:
NA found in matrix in "IF @LAST(RESEQ_XX001) >
RESEQ_XX001 + @STDERRS(RESEQ_XX001) OR
@LAST(RESEQ_XX001) < RESEQ_XX001 -
@STDERRS(RESEQ_XX001) THEN"

I am basically trying to put a dummy if the last data point is outside of the residuals' one standard error bands

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
  %eqsmpl =  {%eq}.@smpl
   smpl {%eqsmpl}
     'estimate ecuation keeping each estimation sample
   {%eq}.{%estcmd}  're-estimate current equation with its command
  {%eq}.makeresids res{%eq} 'generate residuals' series
     if  @last(res{%eq}) > res{%eq} + @stderrs(res{%eq}) or @last(res{%eq})  < res{%eq} - @stderrs(res{%eq}) then '
   %estcmd = {%eq}.@command +  "@event("res{%eq}.@last")"
  endif
 next
 smpl @all 'reset sample

EViews Matt
EViews Developer
Posts: 302
Joined: Thu Apr 25, 2013 7:48 pm

Re: Changing variable names in several equations

Postby EViews Matt » Thu Mar 29, 2018 10:46 am

I believe what you're after is:

Code: Select all

if @abs(@last(res{%eq})) > {%eq}.@se then
   %estcmd = {%eq}.@command + "@event(" + res{%eq}.@last + ")"
endif

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

Re: Changing variable names in several equations

Postby statsforecast » Thu Mar 29, 2018 1:35 pm

Thank you so much! This is exactly what I was trying to do. It only needed an extra pair of quote marks in the @event()

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
  %eqsmpl =  {%eq}.@smpl
   smpl {%eqsmpl}
     'estimate ecuation keeping each estimation sample
   {%eq}.{%estcmd}  're-estimate current equation with its command
  {%eq}.makeresids res{%eq}
    if @abs(@last(res{%eq})) > {%eq}.@se then
   %estcmd = {%eq}.@command + "@event(""" + res{%eq}.@last +""")"
 endif
'delete  res{%eq}
 next
 smpl @all 'reset sample to keep the original sample workfile


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

Re: Changing variable names in several equations

Postby statsforecast » Thu Aug 02, 2018 10:51 am

How could I generalized this for any observation outside the residuals bands? Something like

Code: Select all

if @abs(@date(res{%eq})) > {%eq}.@se then
   %estcmd = {%eq}.@command + "@event(""" + res{%eq}.@date +""")"


But I get an error " Non Numeric Argument".

Thank you.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 17 guests