## Basic Rolling Regression

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

The Yoyo
Posts: 9
Joined: Thu Apr 04, 2013 2:30 pm

### Re: Basic Rolling Regression

Alice Thai wrote:Dear The Yoyo, thank you so much, I am making progress on this, I have successfully created the rolling window. However, another problem arises since the result only displays around 250 observations (I have attached an image for the issue, I think this could be my data is pooled panel data so the program can only run smoothly for the 170 observations of the first country.). In addition, I want to estimate the change of the coefficients over the time series, so is there any way to display the year on the x-axis instead of the observations? Thank you for your help.

I think this has to do with the fact that it is panel data. To see this, remove the CX=F and WGT=CXSUR options in the Least Squares estimation. It would result in a Sample Range error. I'd assume this is caused by stepping to the next cross-section, at which point the sample will have an end date which is earlier than the start date.

I never worked with panel data regressions, so I have no clue how to solve this. Perhaps someone else does?

Alice Thai
Posts: 6
Joined: Fri Apr 21, 2017 6:28 am

### Re: Basic Rolling Regression

The Yoyo wrote:
Alice Thai wrote:Dear The Yoyo, thank you so much, I am making progress on this, I have successfully created the rolling window. However, another problem arises since the result only displays around 250 observations (I have attached an image for the issue, I think this could be my data is pooled panel data so the program can only run smoothly for the 170 observations of the first country.). In addition, I want to estimate the change of the coefficients over the time series, so is there any way to display the year on the x-axis instead of the observations? Thank you for your help.

I think this has to do with the fact that it is panel data. To see this, remove the CX=F and WGT=CXSUR options in the Least Squares estimation. It would result in a Sample Range error. I'd assume this is caused by stepping to the next cross-section, at which point the sample will have an end date which is earlier than the start date.

I never worked with panel data regressions, so I have no clue how to solve this. Perhaps someone else does?

Thank you The Yoyo for your help. I hope somebody in the forum can give some advice for this problem soon.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

Hi

thank you to the entire team for such a wonderful forum. i am doing a 3-period ahead forecast for my series using arima model. my problem is that the program that i run do not give me the same series as the one i would obtain if i would do the entire exercise manually in eviews. can u help??
my estimation period is 1984:m1 1996m1 and i want to obtain 3 period ahead forecast from 1996:m4 to 2017:m2. my program is as follows

series y=cpii

'run rolling regression

' set window size
!window = 145

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare equation for estimation
equation eq2

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

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

'series to store forecast estimates
series fcast

'redundant series for 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))
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}

' estimate equation - where the equation is y=c(1) + c(2)*x1
eq2.ls(arma=gls, optmethod=gauss-newton) d(y) c ar(1) ma(1)

' store coefficients
colplace(coefmat,eq2.@coef,!j)

%3pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%3pere = @otod(@dtoo(%start)+!i+!window+1) 'end point

if @dtoo(%end) < @dtoo(%3pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif

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

eq2.forecast(f=na) yf

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

' store forecasts
fcast = yf
next

smpl @all
show coefmat
show fcast.line

d(noerr) yf

where am i going wrong?? can't just figure out

deepika

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

### Re: Basic Rolling Regression

Nothing looks particularly wrong.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

Thanks for a quick reply. but then why am i not getting the same values as with manually obtaining the recursive forecasts. if the algorithms are the same then same software should be giving similar values. Or do u suggest that i should do this exercise maually?
i am using eviews 9

Thanks
Deepika

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

### Re: Basic Rolling Regression

Hard to say. Perhaps you're doing something wrong.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

sorry to ask again but could you help me in identifying the problem. i am also attaching my workfile and my program. in the workfile the subworkfile named recursiveestimation is used.

thanks
Deepika
Attachments
recursive estimation.prg
data on wpi for arima.wf1

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

### Re: Basic Rolling Regression

Having the program and data doesn't help identify what you're doing wrong when you do it manually.

But if I take your equation eq2 and estimate it until 2016m11, then forecast it 3 month (2016m12 2017m2), the compare the forecasted value for 2017m2 with the one generated by the program, they are identical. Which would suggest the program is doing what you want it to.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

Shouldnt the eq2 stop estimating at 2016m111` but it stops estimating at 2016m12. i think something is wrong there

Deepika

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

Also could you pls tell me how you did it manually so that i can check whether i am doing some mistake while doing it manually

Thanks for all the help
Deepika

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

### Re: Basic Rolling Regression

Open the equation. Hit the Estimate button. Change the sample so that the end point is 2016m11.

Then hit the forecast button. Set the forecast to 2016m12 to 2017m2.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

The manual procedure that i am following is right according to what you have suggested. But if i see the coefficient matrix i m getting 252nd equation which is not desired as it is doing estimation upto 2016m12 whereas the loop should exit after 251th equation only. am i right??

Deepika
Last edited by deepika@econdse.org on Thu Dec 21, 2017 7:59 pm, edited 1 time in total.

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

sorry for troubling but one more question. for a 6-period ahead forecast how will the program change?
will it be
%6pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%6pere = @otod(@dtoo(%start)+!i+!window+4) 'end point

if @dtoo(%end) < @dtoo(%6pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif

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

eq2.forecast(f=na) yf

' set sampl to obtain the 4th period observation
smpl {%6pere} {%6pere}
or something else?

Deepika

deepika@econdse.org
Posts: 11
Joined: Tue Jul 26, 2016 3:39 am

### Re: Basic Rolling Regression

Hi

i am trying to do 3 month ahead forecast using single exponential forecast by writing a program. but somehow it seems to run into errors. can you please help on this

Regards
Deepika