Basic Rolling Regression

For posting your own programs to share with others

Moderators: EViews Gareth, EViews Moderator

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

Re: Basic Rolling Regression

Postby EViews Gareth » Tue Nov 26, 2013 8:56 am

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

lscx411
Posts: 9
Joined: Fri Sep 06, 2013 7:42 pm

Re: Basic Rolling Regression

Postby lscx411 » Tue Nov 26, 2013 7:07 pm

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 R-squared in Eviews?

S Mukhtar
Posts: 1
Joined: Mon Jul 07, 2014 12:29 am

Re: Basic Rolling Regression

Postby S Mukhtar » Mon Jul 07, 2014 1:04 am

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

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

Re: Basic Rolling Regression

Postby EViews Gareth » Mon Jul 07, 2014 8:17 am

Hard to say without seeing what you've done.
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby The Yoyo » Tue Jul 15, 2014 8:11 am

For anyone still looking for a code that does a 1-period 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.

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

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

' 1-period-ahead forecast
%1pers = @otod(@dtoo(%start)+!i+!window-1) 'start point
%1pere = @otod(@dtoo(%start)+!i+!window-1) '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.

EVG
Posts: 3
Joined: Fri May 22, 2015 3:39 pm

Re: Basic Rolling Regression

Postby EVG » Sat May 23, 2015 5:41 am

Hello,

Many thanks you for your help Gareth and Esther.

I am using EViews 7.2 and have been able to do a h-period 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 ?

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

Re: Basic Rolling Regression

Postby EViews Gareth » Sat May 23, 2015 7:54 am

I don't understand what you're trying to do
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby gsourop » Wed Nov 11, 2015 11:59 am

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_uk-log_cpi_us)

I want to run the out-of 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)+!i-1)
%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)

' 1-period-ahead forecast
%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}

' 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" .

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

Re: Basic Rolling Regression

Postby EViews Gareth » Wed Nov 11, 2015 12:20 pm

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

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

Re: Basic Rolling Regression

Postby gsourop » Wed Nov 11, 2015 1:54 pm

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 in-sample period is taken to be from the beginning to M12 1985 and the rest are the out-of-sample 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!

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

Re: Basic Rolling Regression

Postby EViews Gareth » Wed Nov 11, 2015 2:16 pm

Do you want a rolling regression or an expanding one?
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby gsourop » Wed Nov 11, 2015 2:20 pm

A recursive regression (expanding)
Last edited by gsourop on Wed Nov 11, 2015 2:22 pm, edited 1 time in total.

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

Re: Basic Rolling Regression

Postby EViews Gareth » Wed Nov 11, 2015 2:21 pm

Could you explain what that means?
Follow us on Twitter @IHSEViews

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

Re: Basic Rolling Regression

Postby gsourop » Wed Nov 11, 2015 2:25 pm

That I use a period of time to produce my first coefficient and then I add an observation and re-estimate my model..I do these iterations until the end of the sample period.

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

Re: Basic Rolling Regression

Postby EViews Gareth » Wed Nov 11, 2015 3:01 pm

You'll need to completely re-write 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 2 guests