Page 5 of 9

Re: Basic Rolling Regression

Posted: Tue Nov 26, 2013 8:56 am
by EViews Gareth
Each subsamples coefficients are stored in coefmat. You'll have to change the program to store the standard errors in the same way.

Re: Basic Rolling Regression

Posted: Tue Nov 26, 2013 7:07 pm
by lscx411
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?

Re: Basic Rolling Regression

Posted: Mon Jul 07, 2014 1:04 am
by S Mukhtar
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

Re: Basic Rolling Regression

Posted: Mon Jul 07, 2014 8:17 am
by EViews Gareth
Hard to say without seeing what you've done.

Re: Basic Rolling Regression

Posted: Tue Jul 15, 2014 8:11 am
by The Yoyo
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.

Re: Basic Rolling Regression

Posted: Sat May 23, 2015 5:41 am
by EVG
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 ?

Re: Basic Rolling Regression

Posted: Sat May 23, 2015 7:54 am
by EViews Gareth
I don't understand what you're trying to do

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 11:59 am
by gsourop
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" .

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 12:20 pm
by EViews Gareth
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.

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 1:54 pm
by gsourop
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!

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 2:16 pm
by EViews Gareth
Do you want a rolling regression or an expanding one?

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 2:20 pm
by gsourop
A recursive regression (expanding)

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 2:21 pm
by EViews Gareth
Could you explain what that means?

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 2:25 pm
by gsourop
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.

Re: Basic Rolling Regression

Posted: Wed Nov 11, 2015 3:01 pm
by EViews Gareth
You'll need to completely re-write the sample parts then, since you're not doing rolling regression.