Page 1 of 2

Rolling Regression

Posted: Sun May 26, 2013 6:02 am
by marcel1410
Hi!

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

Re: Rolling Regression

Posted: Sun May 26, 2013 12:51 pm
by EViews Gareth
Do you have data for your regressors for the forecast period?

Re: Rolling Regression

Posted: Sun May 26, 2013 1:29 pm
by marcel1410
Yes I got data of r1 over the period 1906-2005 and I got data of the regressor over the period 1906-2005.

Re: Rolling Regression

Posted: Sun May 26, 2013 2:08 pm
by marcel1410
If it helps, I uploaded here my workfile and the program.

Re: Rolling Regression

Posted: Sun May 26, 2013 4:49 pm
by EViews Gareth
If I run that program on that workfile, it works without erroring.

Re: Rolling Regression

Posted: Mon May 27, 2013 12:44 am
by marcel1410
How strange. I am using eviews 7, so that's not a problem right?
I also used eviews 5, but then '@cumsum' is not defined. What version of eviews do you use?

Re: Rolling Regression

Posted: Mon May 27, 2013 11:07 am
by EViews Gareth
7. Is your copy up to date?

Re: Rolling Regression

Posted: Mon May 27, 2013 2:13 pm
by marcel1410
No I don't think so. But it doesn't seem logic to me that that would be the problem, since I don't use (as far I know) codes that eviews does not know. However I will update eviews and try it again. You will hear from me (maybe end of the week) whether it has helped me. Anyway thanks for your help untill now.

Re: Rolling Regression

Posted: Fri May 31, 2013 12:25 pm
by marcel1410
I want to apologize for wasting your time, since the program does indeed work fine after updating eviews.

However, I have another question.
How should I adjust this code such that the equation r1=c(1)+c(2)*regressor(-1) is not estimated by OLS, but with GLS instead?

Re: Rolling Regression

Posted: Sun Jun 23, 2013 6:50 am
by Mahdi
Hi every one
I am new to the forum. Is there any chance some one help me with the program I have written for the rolling window estimation. The code is:

smpl @all
scalar n=@obs(rsp)
scalar window=200
series rspf
equation z
for !i=0 to n-200-1
smpl @first+!i @first+!i+200-1
z.ls rsp=rsp(-1)+(((exp(c(1)*c(2)*pof))/(exp(c(1)*c(2)*pof)+exp(c(1)*c(3)*poco)+exp(c(1)*c(3)*pocten)))*c(2)*dof)+(((exp(c(1)*c(3)*poco))/(exp(c(1)*c(2)*pof)+exp(c(1)*c(3)*poco)+exp(c(1)*c(3)*pocten)))*c(3)*doco)+(((exp(c(1)*c(3)*pocten))/(exp(c(1)*c(2)*pof)+exp(c(1)*c(3)*poco)+exp(c(1)*c(3)*pocten)))*c(3)*docten)
smpl @first+!i+200 @first+!i+200
rspf=rsp(-1)+(((exp(@coefs(1)*@coefs(2)*pof))/(exp(@coefs(1)*@coefs(2)*pof)+exp(@coefs(1)*@coefs(3)*poco)+exp(@coefs(1)*@coefs(3)*pocten)))*@coefs(2)*dof)+(((exp(@coefs(1)*@coefs(3)*poco))/(exp(@coefs(1)*@coefs(2)*pof)+exp(@coefs(1)*@coefs(3)*poco)+exp(@coefs(1)*@coefs(3)*pocten)))*@coefs(3)*doco)+(((exp(@coefs(1)*@coefs(3)*pocten))/(exp(@coefs(1)*@coefs(2)*pof)+exp(@coefs(1)*@coefs(3)*poco)+exp(@coefs(1)*@coefs(3)*pocten)))*@coefs(3)*docten)
next

I have eviews 7.1

Thanks in advance

Re: Rolling Regression

Posted: Tue Jul 02, 2013 8:27 am
by sdgdas
I am using Eviews 5.1 and the roiling regression commands like @obsrange does not seem to be there.. Can anyone help how to write an rolling regression program in Eviews 5.1

Re: Rolling Regression

Posted: Tue Jul 02, 2013 8:30 am
by EViews Gareth
If you click on Help->Quick Help Reference->Sample Programs and Data, there should be a rolling regression example that works in EV5.

Re: Rolling Regression

Posted: Wed Aug 07, 2013 12:36 pm
by economist12
Hi

I am currently developing a program for the rolling regression estimation. I have a quick question using eviews 7 or 8 is it possible to set the program in command mode to make the observations decrease by one after each estimation and in the same program after the decrease in observations has reached the shortest model to be estimated rolled forward and then repeat the same process until the same is exhausted.

To further explain the question,imagine the shortest estimate is at two years(24months) ahead of the first observation and the longest model to be estimated is 10years(about120months), the loop in stead of starting from 24-120 it goes from 120-24 (decreasing after each estimation)., then after this the data rolls forward a moth ahead and then the exact process of estimation is repeated again (.i.e 120-24 decreasing estimations) until the sample is exhausted, and after each estimation one period ahead and twelve period ahead forecasts generated. I have done everything apart from acheiving creating a loop within the loop that allows the observations to decrease after each estimation.

Can someone please give assistance to acheive this procedure using loops? Thanks in advance.

Re: Rolling Regression

Posted: Fri Sep 06, 2013 8:15 pm
by lscx411
I am running rolling regression and have 161 observations. It says I have insufficient number of observations in Do_eq1.ls lqt itd ygtd pitd vtd. If I define series lqt=nrnd,series itd=nrnd,series pitd=nrnd,series ygtd=nrnd the code could work. I have data for lqt,itd,pitd and ygtd. How could I define these data in the program?
I am fresh in using Eviews. Could someone help me to revise this code? Thanks a lot!

'create data file
create u 161

series lqt
series itd
series pitd
series ygtd
series vt=nrnd
series vtstar=nrnd
series vtd=vt-vtstar

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

' set window size
!window = 60

' set step size
!step =5

' 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(5,!nrolls) coefmat ' where 5 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

' set sample to estimation period
smpl @first+!i-1 @first+!i+!window-2

' estimate equation - where the equation is y= c(1)+c(2)*x1+c(3)*x2+c(4)*x3+c(5)*x4
eq1.ls lqt itd ygtd pitd vtd

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

show coefmat

Re: Rolling Regression

Posted: Fri Sep 06, 2013 8:22 pm
by EViews Gareth
Your variables have no data.