Basic Rolling Regression
Moderators: EViews Gareth, EViews Moderator
Re: Basic Rolling Regression
I denote with asterisks "***" the corrections made. Is this correct?:
' set window size
!window = 90
' 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
'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)) '****
%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
' set window size
!window = 90
' 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
'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)) '****
%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
Re: Basic Rolling Regression
Hi everyone,
I want to estimate a Random Walk model under a recursive window (expanding). My observations are from 1973M01 to 2014M12, and sum into 504 observartions (from which I want to exclude the first 12 from my sampleI just used them to calculate the inflation rate). I want my first estimation to start at 1978M01, and take into account the observations from 1974M01 until 1977M12. Until now I have made the above:
' set window size
!window = 60
' 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
'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=ut
eq1.ls d(lspot) lspot(1)
'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
If I want to do the same with a Taylor rule, let's say the following specifications: II* = (inflinfl*)+(output_gapoutput_gap*) , the "*" is for the foreign country, I will have to reestimate the output gap for every new estimation that come as I expand my window. Does anyone know how can I do that?
Thank you for your time!
I want to estimate a Random Walk model under a recursive window (expanding). My observations are from 1973M01 to 2014M12, and sum into 504 observartions (from which I want to exclude the first 12 from my sampleI just used them to calculate the inflation rate). I want my first estimation to start at 1978M01, and take into account the observations from 1974M01 until 1977M12. Until now I have made the above:
' set window size
!window = 60
' 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
'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=ut
eq1.ls d(lspot) lspot(1)
'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
If I want to do the same with a Taylor rule, let's say the following specifications: II* = (inflinfl*)+(output_gapoutput_gap*) , the "*" is for the foreign country, I will have to reestimate the output gap for every new estimation that come as I expand my window. Does anyone know how can I do that?
Thank you for your time!

 Posts: 5
 Joined: Thu Jun 02, 2016 11:27 pm
 Location: Bangalore, India
Re: Basic Rolling Regression
Hi,
I wrote this command in the command window to find rolling coefficients of the regression pca1 c usbe10 ustips10. But unfortunately I couldn't find the results. I ve no basic training in programming language. Please advice. Thanks a lot.
!window = 24
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length!window)/!step)
matrix(3,!nrolls) coefmat
!j=0
!i = 1 to !length!window+1!step step !step
!j=!j+1
smpl @first+!i1 @first+!i+!window2
eq1.ls pca1 c usbe10 ustips10
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
I wrote this command in the command window to find rolling coefficients of the regression pca1 c usbe10 ustips10. But unfortunately I couldn't find the results. I ve no basic training in programming language. Please advice. Thanks a lot.
!window = 24
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length!window)/!step)
matrix(3,!nrolls) coefmat
!j=0
!i = 1 to !length!window+1!step step !step
!j=!j+1
smpl @first+!i1 @first+!i+!window2
eq1.ls pca1 c usbe10 ustips10
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12540
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
You have to use a program (file>new program) rather than the command window
Follow us on Twitter @IHSEViews

 Posts: 5
 Joined: Thu Jun 02, 2016 11:27 pm
 Location: Bangalore, India
Re: Basic Rolling Regression
Hi Gareth,
Thanks a lot for such prompt response.
When I run the new program, it says that "Next found outside of loop or IF statement"
Please suggest.
Thanks
Thanks a lot for such prompt response.
When I run the new program, it says that "Next found outside of loop or IF statement"
Please suggest.
Thanks

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12540
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
The line that starts with !i=1 is missing a for
Follow us on Twitter @IHSEViews

 Posts: 5
 Joined: Thu Jun 02, 2016 11:27 pm
 Location: Bangalore, India
Re: Basic Rolling Regression
Thanks a lot Gareth. It worked.
Re: Basic Rolling Regression
Hi everyone.
So I am trying to forecast the volatility of the S&P 500 and S&P 100 and I need to create a in and out of sample forecast using a rolling regression. However this is my first time using EVIEWS and was wondering what I will need to do before conducting the Roll regression.
At this moment in time, I've collected my data and I have imported it into my EVIEWS workbook and made them into logs. What is the next step for me ? what equation do I need to make? what is the basic roll regression code?
Any help would be much appreciated!
Thank you.
So I am trying to forecast the volatility of the S&P 500 and S&P 100 and I need to create a in and out of sample forecast using a rolling regression. However this is my first time using EVIEWS and was wondering what I will need to do before conducting the Roll regression.
At this moment in time, I've collected my data and I have imported it into my EVIEWS workbook and made them into logs. What is the next step for me ? what equation do I need to make? what is the basic roll regression code?
Any help would be much appreciated!
Thank you.
Re: Basic Rolling Regression
Hello , I need some help trying to make this rolling in a 156 data moving window, I need to adjust the start and end point so each regression takes 156 observations , any help is appreciated ,regards
'run rolling regression
' set window size
!window = 156
' set step size
!step = 1
' 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
' set sample to estimation period
smpl @first+!i1 @first+!i+!window2
' estimate equation  where the equation is y=x1 x2 x3
eq1.ls y x1 x2 x3
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
'run rolling regression
' set window size
!window = 156
' set step size
!step = 1
' 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
' set sample to estimation period
smpl @first+!i1 @first+!i+!window2
' estimate equation  where the equation is y=x1 x2 x3
eq1.ls y x1 x2 x3
'store coefficients
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12540
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
The regressions seems not be to be a 156 window. I think I need to set an @first and @last to tell Eviews to make a regression of a moving 156 window.
For example, I woulld like something like
reg1 : 2010m01  2016m01
reg2 : 2010m02  2016m02
reg3 : 2010m03  2016m03
....
....
so the window remains the same, regards
For example, I woulld like something like
reg1 : 2010m01  2016m01
reg2 : 2010m02  2016m02
reg3 : 2010m03  2016m03
....
....
so the window remains the same, regards

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12540
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
Hello Gareth,
Thank you for the code.
I'm interested by running a rolling regression (with one explanatory variable) but for 35 stocks.
I have 35 stocks (Y1,Y2...Y35) and one market index (X).
Is it possible ?
Thank you
Thank you for the code.
I'm interested by running a rolling regression (with one explanatory variable) but for 35 stocks.
I have 35 stocks (Y1,Y2...Y35) and one market index (X).
Is it possible ?
Thank you

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12540
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Basic Rolling Regression
You'll have to write a loop that loops over the stocks and runs the regression on each.
Follow us on Twitter @IHSEViews
Re: Basic Rolling Regression
thank you for your reply.
I see how to write a loop that loops over the stocks and runs a simple regression but i don't see how to do it with a rolling regression.
I don't see how to do it.
can you give me a simple example?
I see how to write a loop that loops over the stocks and runs a simple regression but i don't see how to do it with a rolling regression.
I don't see how to do it.
can you give me a simple example?
Return to “Program Repository”
Who is online
Users browsing this forum: No registered users and 2 guests