## Basic Rolling Regression

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

### 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+!window-2)
smpl {%first} {%last}

' estimate equation - where the equation is y=c(1) + c(2)*x1
eq1.ls log_spot c (log_ipi_uk-log_ipi_us)

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

%1pers = @otod(@dtoo(%start)+!i+!window-1) '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}

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

gsourop
Posts: 18
Joined: Wed Nov 11, 2015 11:46 am

### 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 sample-I 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)) '+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}

' estimate equation - where the equation is y=ut
eq1.ls d(lspot) lspot(-1)
'store coefficients
colplace(coefmat,eq1.@coefs,!j)

%1pers = @otod(@dtoo(%start)+!i+!window-1) '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}

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: I-I* = (infl-infl*)+(output_gap-output_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?

Priyabrata
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+!i-1 @first+!i+!window-2
eq1.ls pca1 c usbe10 ustips10
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 12462
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

Priyabrata
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"

Thanks

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

### Re: Basic Rolling Regression

The line that starts with !i=1 is missing a for

Priyabrata
Posts: 5
Joined: Thu Jun 02, 2016 11:27 pm
Location: Bangalore, India

### Re: Basic Rolling Regression

Thanks a lot Gareth. It worked.

ahamm23
Posts: 1
Joined: Thu Jul 07, 2016 11:55 am

### 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.

tonach
Posts: 3
Joined: Mon Nov 14, 2016 10:00 am

### 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+!i-1 @first+!i+!window-2

' 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

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

### Re: Basic Rolling Regression

Looks ok to me.

tonach
Posts: 3
Joined: Mon Nov 14, 2016 10:00 am

### 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

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

### Re: Basic Rolling Regression

That's what it is doing.

Posts: 15
Joined: Wed Dec 07, 2016 4:59 am

### 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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 12462
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.

Posts: 15
Joined: Wed Dec 07, 2016 4:59 am