I have a question about my eviews code, which should perform a rolling regression.
I got yearly data over the years 1906-2005.
The equation that i want to fit is r1=c(1) + c(2)*regressor(-1).
Also, I want to compare this equation to the equation r1=c(1).
The code I'm using for this is given below. I got the following error:
"Unable to compute due to missing data in "DO_EQ1.FORECAST(F=NA) YF"
I really hope somebody can help me with this, since i spend some few days about it and can't find the error i make.
Code: Select all
'run rolling regression
' set window size
!window = 50
' 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(2,!nrolls) coefmat ' where 2 is the number of coefficients
matrix(1,!nrolls) coefmat2 ' where 1 is the number of coefficients
'series to store forecast estimates
series fcast
series fcastmean
'catching start and end points
%start = "@first" '@otod(@ifirst(ser))
%end = "@last" '@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)
%last = @otod(@dtoo(%start)+!i+!window-1)
smpl {%first} {%last}
' estimate equation - where the equation is r1 =c(1) + c(2)*regressor(-1)
eq1.ls r1 c regressor
' store coefficients
colplace(coefmat,eq1.@coefs,!j)
' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point
if @dtoo(%end) < @dtoo(%1pere) then
'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%1pers} {%1pere}
' forecast with command *forecast* (see also *fit*)
eq1.forecast(f=na) yf
' set sampl to obtain the 1 period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
'run rolling average regression
' set sample for estimation period
%first = @otod(@dtoo(%start)+!i)
%last = @otod(@dtoo(%start)+!i+!window-1)
smpl {%first} {%last}
' estimate equation - where the equation is r1 =c(1)
eq1.ls r1 c
' store coefficients
colplace(coefmat2,eq1.@coefs,!j)
' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point
if @dtoo(%end) < @dtoo(%1pere) then
'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%1pers} {%1pere}
' forecast with command *forecast* (see also *fit*)
eq1.forecast(f=na) yf
' set sampl to obtain the 1 period observation
smpl {%1pere} {%1pere}
' store forecasts
fcastmean = yf
next
smpl @all
'series to store squared errors
series se1=(r1-fcast)*(r1-fcast)
series se2=(r1-fcastmean)*(r1-fcastmean)
'series to store delta squared errors
series dt=se2-se1
'series to store mean squared errors
series mse1=(1/@obs(fcast))*@cumsum(se1)
series mse2=(1/@obs(fcast))*@cumsum(se2)
'series to store R2
series rsqrd = 1- mse1/mse2
'series to store delta mean absolute errors
series dmae=(1/@obs(fcast))*@cumsum( abs(r1-fcastmean) - abs(r1-fcast))
'series to store delta root mean squared errors
series drmse= sqr(mse2)-sqr(mse1)
d(noerr) yf
