Basic Rolling Regression
Moderators: EViews Gareth, EViews Moderator

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
Each subsamples coefficients are stored in coefmat. You'll have to change the program to store the standard errors in the same way.
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
EViews Gareth wrote:Each subsamples coefficients are stored in coefmat. You'll have to change the program to store the standard errors in the same way.
Thanks Gareth! How to store subsamples Rsquared in Eviews?
Re: Basic Rolling Regression
Dear all,
I am new to use Eviews and I have been trying to replicated the basic rolling regression. After following all the steps mentioned in the first post, I find the message "!step not defined" when I reach to the following point:
!nrolls = @round((!length!window)/!step)
Although I do define !step=40 as done in the first post.
Sorry for naivety, please can anybody help me with this? Why do I get such message? I have tried many times.
Many thanks,
Mukhtar
I am new to use Eviews and I have been trying to replicated the basic rolling regression. After following all the steps mentioned in the first post, I find the message "!step not defined" when I reach to the following point:
!nrolls = @round((!length!window)/!step)
Although I do define !step=40 as done in the first post.
Sorry for naivety, please can anybody help me with this? Why do I get such message? I have tried many times.
Many thanks,
Mukhtar

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
Hard to say without seeing what you've done.
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
For anyone still looking for a code that does a 1period ahead recursive regression forecast (expanding window), I put together something from posts all over this forum. Most of the credits for these codes go to Esther and Gareth.
Try the code below. Note that I left out the coefficient matrix.
I have no real programming experience, so keep in mind that the code might not work 100% correctly. Any improvements are appreciated.
Try the code below. Note that I left out the coefficient matrix.
Code: Select all
'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)
'series to store forecast estimates
series fcast
'*EDITED: 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+!window2)
smpl {%first} {%last}
' estimate equation  where the equation is y =c(1) + c(2)*x1 +c(3)*x2
eq1.ls y c x1 x2
' 1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window1) 'end point
'*EDITED
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 4th period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
next
smpl @all
show fcast.line
d(noerr) yf
I have no real programming experience, so keep in mind that the code might not work 100% correctly. Any improvements are appreciated.
Re: Basic Rolling Regression
Hello,
Many thanks you for your help Gareth and Esther.
I am using EViews 7.2 and have been able to do a hperiod ahead recursive regression forecast thanks to this post. However, I would also like to add exogenous variables to my model, and these need to be forecasted for each step with an ARMA structure (say AR(1)). I am struggling with the organization of the code, could anyone help me ?
Many thanks you for your help Gareth and Esther.
I am using EViews 7.2 and have been able to do a hperiod ahead recursive regression forecast thanks to this post. However, I would also like to add exogenous variables to my model, and these need to be forecasted for each step with an ARMA structure (say AR(1)). I am struggling with the organization of the code, could anyone help me ?

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
I don't understand what you're trying to do
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
Hallo everyone!
I am new in the forum and I am not familiar with the EVIEWS programming language, so I would really appreciate some help!!
My forecasting equation is: Exchange rate=c+c(1)(log_cpi_uklog_cpi_us)
I want to run the outof sample forecasting test with recursive window forecasting scheme. I use some commands seen in the forum such as:
' set window size
!window = 576
' set step size
!step = 90
' 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
'series to store forecast estimates
series fcast
' set sample for estimation period
%start ="@first" ' @otod(@ifirst(ser))
%end="%last" '@otod(@ilast(ser))
smpl {%first} {%last}
'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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
' estimate equation  where the equation is y=c(1) + c(2)*x1
eq1.ls log_spot c (log_ipi_uklog_ipi_us)
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
' 1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point
'*EDITED
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 4th period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
next
smpl @all
show coefmat
show fcast.line
d(noerr) yf
But when I run the program I get the message "Matrix or vector given non positive dimensions in the "Matrix (2,0) COEFMAT" .
I am new in the forum and I am not familiar with the EVIEWS programming language, so I would really appreciate some help!!
My forecasting equation is: Exchange rate=c+c(1)(log_cpi_uklog_cpi_us)
I want to run the outof sample forecasting test with recursive window forecasting scheme. I use some commands seen in the forum such as:
' set window size
!window = 576
' set step size
!step = 90
' 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
'series to store forecast estimates
series fcast
' set sample for estimation period
%start ="@first" ' @otod(@ifirst(ser))
%end="%last" '@otod(@ilast(ser))
smpl {%first} {%last}
'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)+!i1)
%last = @otod(@dtoo(%start)+!i+!window2)
smpl {%first} {%last}
' estimate equation  where the equation is y=c(1) + c(2)*x1
eq1.ls log_spot c (log_ipi_uklog_ipi_us)
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
' 1periodahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window) 'end point
'*EDITED
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 4th period observation
smpl {%1pere} {%1pere}
' store forecasts
fcast = yf
next
smpl @all
show coefmat
show fcast.line
d(noerr) yf
But when I run the program I get the message "Matrix or vector given non positive dimensions in the "Matrix (2,0) COEFMAT" .

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
Looks like !length is the same as !window. i.e. your rolling size is the same size as the number of observations you have. Which makes no sense.
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
Thank you for your response. How can I deal with that? Which part of the programming shall I change? To make my self clear I will give you more details regarding my project: My sample consists of 576 have observations, starting from M1 1969 to M12 2013. The insample period is taken to be from the beginning to M12 1985 and the rest are the outofsample observations. I want to produce me first forecast on M1 1975 and then recursively estimate next coefficients. How do I change my code in order to adjust on the above?
Thank you very much for your time!
Thank you very much for your time!

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
Do you want a rolling regression or an expanding one?
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
A recursive regression (expanding)
Last edited by gsourop on Wed Nov 11, 2015 2:22 pm, edited 1 time in total.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
That I use a period of time to produce my first coefficient and then I add an observation and reestimate my model..I do these iterations until the end of the sample period.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12543
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
You'll need to completely rewrite the sample parts then, since you're not doing rolling regression.
Follow us on Twitter @IHSEViews
Return to “Program Repository”
Who is online
Users browsing this forum: No registered users and 3 guests