Page 2 of 3
Re: Changing variable names in several equations
Posted: Thu Mar 08, 2018 11:44 am
by statsforecast
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
Re: Changing variable names in several equations
Posted: Thu Mar 08, 2018 12:11 pm
by EViews Gareth
use @makevalidname
Re: Changing variable names in several equations
Posted: Fri Mar 09, 2018 10:44 am
by statsforecast
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
Re: Changing variable names in several equations
Posted: Fri Mar 09, 2018 10:53 am
by statsforecast
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
Re: Changing variable names in several equations
Posted: Fri Mar 09, 2018 10:58 am
by statsforecast
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.
Re: Changing variable names in several equations
Posted: Tue Mar 13, 2018 8:58 am
by statsforecast
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.
Re: Changing variable names in several equations
Posted: Tue Mar 13, 2018 9:40 am
by EViews Matt
Hello,
It would probably be easier to use the makeresids proc to copy the residuals to a series and then access that series.
Re: Changing variable names in several equations
Posted: Wed Mar 28, 2018 1:58 pm
by statsforecast
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.
Re: Changing variable names in several equations
Posted: Wed Mar 28, 2018 2:40 pm
by EViews Matt
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.
Re: Changing variable names in several equations
Posted: Wed Mar 28, 2018 3:05 pm
by statsforecast
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
Re: Changing variable names in several equations
Posted: Wed Mar 28, 2018 3:26 pm
by EViews Matt
x.@last will return the date (as a string) of the last non-NA observation in series x.
Re: Changing variable names in several equations
Posted: Wed Mar 28, 2018 5:12 pm
by statsforecast
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
Re: Changing variable names in several equations
Posted: Thu Mar 29, 2018 10:46 am
by EViews Matt
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
Re: Changing variable names in several equations
Posted: Thu Mar 29, 2018 1:35 pm
by statsforecast
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
Re: Changing variable names in several equations
Posted: Thu Aug 02, 2018 10:51 am
by statsforecast
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.