Page 1 of 1

recursive estimation by choosing lag followed by forecasting

Posted: Mon Jul 18, 2011 8:40 am
by mjfl
Dear EviewsTeam,

thank you so much but im falling asleep trying to do this to finalise some papers.
the steps:

1.Choose the best model of y and x-lags by sic. Estimate it from 1990Q1 to 1999Q1 then forecast for 1999Q2 value.
2. Program should then run recursively. This means next will be estimation of 1990Q1 to 1999Q2, choose lags by SC then forecast 1999Q3.
3. Forecast a list of 1999Q2 to 2005Q1 and use y - forecasted y to find RMSE.

i have tried the following but cant seem to join:

'create a variable
series y = dlhs
series x = dpiet

'create empty equation to be used inside the loop
equation eq

'variable to store the minimum AIC. Initialise it to a large number
!sc = 99999999

'variable saying how many lags to go up to
!maxlags = 10

'Variable to store the "best" number of lags
!bestlag = 0

'set sample to be the !maxlag'th value onwards
smpl 1990q1+!maxlags 1999q1

for !i=1 to !maxlags
eq.ls(cov=hac) y c x( to -!i) 'run regression of Y on a constant and lagged values of itself up to the iTH lag.
if eq.@sc < !sc then
!bestlag = !i 'if this lag specification has the best AIC, then store this lag as !bestlag.
!sc = eq.@sc
endif
next

show eq.ls(cov=hac) y c x( to -!bestlag)

'reset sample
smpl @all
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I cant seem to make the date run. How can i do that? How can i also ask for the forecasted value instead of the eqn? i tried to read the rolling out of sample but it gives only coefficients i cant comprehend.
I need a list of forecasted value by recurvsive est. this is for RMSE later.

'create some data
create u 800

series y=nrnd
series x1=nrnd
series x2=nrnd
series z=nrnd

'-------------------------------------------------------------------------------------
'run rolling regression

' set window size
!window = 750

' set step size
!step = 40

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq1

'calculate number of rolls
!nrolls = @round((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat ' where 3 is the number of coefficients

'variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1

-------------------------------------------------------------im so sorry for asking but i have tried part by part.

Re: recursive estimation by choosing lag followed by forecas

Posted: Mon Jul 18, 2011 10:21 am
by EViews Gareth
Your first problem is with this line:

Code: Select all

smpl 1990q1+!maxlags 1999q1
EViews can't interpret a date plus an integer. You'll have to use the @dtoo and @otod functions to convert the date into an integer, do the calculation, and then convert back. Something like:

Code: Select all

!temp = @dtoo("1990q1") !temp = !temp + !maxlags %date = @otod(!temp) smpl {%date} 1999q1

Re: recursive estimation by choosing lag followed by forecas

Posted: Mon Jul 18, 2011 8:07 pm
by mjfl
hi there,

thank you for your reply. i understand what it means.
have been looking at
[quote'create some data
create u 100

series y=nrnd
series x1=nrnd
series x2=nrnd
series z=nrnd

'-------------------------------------------------------------------------------------
'run rolling regression

' set window size
!window = 20

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq1

'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)

'matrix to store coefficient estimates
matrix(3,!nrolls) coefmat ' where 3 is the number of coefficients

'series to store forecast estimates
series fcast

'redundant series for catching start and end points
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))

'variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1

' set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}

' estimate equation - where the equation is y=c(1) + c(2)*x1 + c(3)*x2
eq1.ls y c x1 x2

' store coefficients
colplace(coefmat,eq1.@coefs,!j)

' 4-period-ahead forecast
%4pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%4pere = @otod(@dtoo(%start)+!i+!window+2) 'end point: %4pere - %4pers +1 = 4
if {%end} < {%4pere} then 'check whether the forecast end point is greater than the workfile end point
return
endif

' set smpl for forecasting period
smpl {%4pers} {%4pere}

' forecast with command *forecast* (see also *fit*)
eq1.forecast(f=na) yf

' set sampl to obtain the 4th period observation
smpl {%4pere} {%4pere}

' store forecasts
fcast = yf
next

smpl @all
show coefmat
show fcast.line

d(noerr) ser


EViews Esther
EViews Developer

Posts: 39
Joined: Fri Sep 03, 2010 7:57 amTop][/quote]


but i cant seem to integrate both of them together. moroever, this program has internal error invalid return on return. i would like to do 1 step ahead at each time. but when i look at the fcast and yf, i seriously dont know what are the values generated there. back to same question of can i choose best model (SIC) recursively when the time period is increasing? thank you for the reply. much appreciated.