Multistep ahead forecast
Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt
Multistep ahead forecast
m
Last edited by Nas1 on Sat Feb 01, 2014 8:48 am, edited 1 time in total.

 EViews Developer
 Posts: 2620
 Joined: Wed Oct 15, 2008 9:17 am
Re: Multistep ahead forecast
If it is asking you to expand the workfile range it's because you are trying to forecast for a period beyond the last date of the workfile. EViews has no place to put those results, hence the request for you to move the enddate further out.
Re: Multistep ahead forecast
thank you so much for your reply... and again, very simple questions however with significant importance (I am using eviews 8.1) :
I checked the examples posted on this great forum and I have the following inquiries:
I have 2 codes which are similar to one posted example in this forum where I want to make 4 period ahead forecast for Y.
For the first code, I want to perform the forecast by using unrestricted VAR: I am receiving an error message that matrix size mismatch in colplace, how to fix this issue??
I could not manage to perform the forecasting with Markov. I checked this forum and the command manual but with no solution of how correctly do it ...
I set the estimation window of 60, please confirm that this code will fix the rolling window to the starting point where the newly forecasted data will be included in the estimation for the next 4 periods(60+1)!
Is there a solution of the missing data during the rolling process without extending the sample range??
Please advice!!!!

'create some data
create u 100
series y=nrnd
series x1=nrnd
series x2=nrnd
series x3=nrnd
series z=nrnd
'define loop
for !i=1 to 60+!i
smpl @first @first+60+!i
var var1.ls 1 2 y x1 x2 x3 @ z
' VAR forecast
var1.makemodel(mod1)
smpl @first @first+60+!i+4
mod1.solve(d=d)
smpl @first+60+!i+4 @first+60+!i+4
series y_hat_4 = y_0
next
smpl @all
scalar rmse=@rmse(y, y_hat_4)
show (y, y_hat_4)

'create some data
create u 100
series p=nrnd
series x=nrnd
series z=nrnd
series y=nrnd
series dumm=nrnd
'define loop
for !i=1 to 60+!i
smpl @first @first+60+!i
switchreg(type=markov) y c p z x @nv ar(1) ar(2) ar(3) ar(4)
'markov switching forecast
switchreg(type=markov).makemodel(mod1)
smpl @first @first+60+!i+4
mod1.solve(d=d)
smpl @first+60+!i+4 @first+60+!i+4
series y_hat_4 = y_0
next
smpl @all
scalar rmse=@rmse(y, y_hat_4)
show (y, y_hat_4)
I checked the examples posted on this great forum and I have the following inquiries:
I have 2 codes which are similar to one posted example in this forum where I want to make 4 period ahead forecast for Y.
For the first code, I want to perform the forecast by using unrestricted VAR: I am receiving an error message that matrix size mismatch in colplace, how to fix this issue??
I could not manage to perform the forecasting with Markov. I checked this forum and the command manual but with no solution of how correctly do it ...
I set the estimation window of 60, please confirm that this code will fix the rolling window to the starting point where the newly forecasted data will be included in the estimation for the next 4 periods(60+1)!
Is there a solution of the missing data during the rolling process without extending the sample range??
Please advice!!!!

'create some data
create u 100
series y=nrnd
series x1=nrnd
series x2=nrnd
series x3=nrnd
series z=nrnd
'define loop
for !i=1 to 60+!i
smpl @first @first+60+!i
var var1.ls 1 2 y x1 x2 x3 @ z
' VAR forecast
var1.makemodel(mod1)
smpl @first @first+60+!i+4
mod1.solve(d=d)
smpl @first+60+!i+4 @first+60+!i+4
series y_hat_4 = y_0
next
smpl @all
scalar rmse=@rmse(y, y_hat_4)
show (y, y_hat_4)

'create some data
create u 100
series p=nrnd
series x=nrnd
series z=nrnd
series y=nrnd
series dumm=nrnd
'define loop
for !i=1 to 60+!i
smpl @first @first+60+!i
switchreg(type=markov) y c p z x @nv ar(1) ar(2) ar(3) ar(4)
'markov switching forecast
switchreg(type=markov).makemodel(mod1)
smpl @first @first+60+!i+4
mod1.solve(d=d)
smpl @first+60+!i+4 @first+60+!i+4
series y_hat_4 = y_0
next
smpl @all
scalar rmse=@rmse(y, y_hat_4)
show (y, y_hat_4)

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Multistep ahead forecast
Given you're not using the colplace function in the first program, I doubt you are seeing an error stating that colplace isn't working.
For the second one, since you're using an equation object to do the estimation, there is no need to use a model for the forecast. You can forecast directly from the equation using equation.forecast.
For the second one, since you're using an equation object to do the estimation, there is no need to use a model for the forecast. You can forecast directly from the equation using equation.forecast.
Follow us on Twitter @IHSEViews
Re: Multistep ahead forecast
EViews Gareth wrote:Given you're not using the colplace function in the first program, I doubt you are seeing an error stating that colplace isn't working.
For the second one, since you're using an equation object to do the estimation, there is no need to use a model for the forecast. You can forecast directly from the equation using equation.forecast.
sorry for the mistake, I was opening multiple eviews workfiles and I copied the wrong codes!!! it was among many trial to forecast . But I think if I want to forecast from equation, I cant forecast 4 periods ahead??

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Multistep ahead forecast
Sure you can. It is shown in the thread I posted before
Follow us on Twitter @IHSEViews
Re: Multistep ahead forecast
OK...thanks for the quick reply, I will dig more in the threads.
Re: Multistep ahead forecast
Hello,
I attached a sample data . I want to forecast 4 periods ahead .
the issue that I am getting a zeros in the coefmat. may you please check why I am having this problem??
regards,
I attached a sample data . I want to forecast 4 periods ahead .
the issue that I am getting a zeros in the coefmat. may you please check why I am having this problem??
regards,

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Multistep ahead forecast
At no point are you storing any information into the matrix coefmat.
Follow us on Twitter @IHSEViews
Re: Multistep ahead forecast
Dear Gareth, i think the codes now are running smoothly concerning the forecast; however, I tried to fix the issue of the zero coefmat but with no success. May you please take a look at this point; It seems I am missing one step which I could not figure and I am getting an error message that matrix size mismatch in colplace.
I want to forecast 4 periods a head directly from equation recursively.
'run rolling regression
' set window size
!window = 142
' set step size
' declare equation for estimation
equation eq01
' get size of workfile
!length = @obsrange
%cmnd = _this.@command 'EDIT: get the equation specification stored in eviews
!step = 4
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(6,!nrolls) coefmat ' where 6 is the number of coefficients
'series to store forecast estimates
series fcast
'redundant series for 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 recursive window
%first = @otod(@dtoo(%start))
%last = @otod(@dtoo(%start)+!i+!window1)
smpl {%first} {%last}
' estimate equation 
!maxerr = @maxerrcount
setmaxerrs !maxerr+1
_this.{%cmnd} 'estimated equation
colplace(coefmat,eq01.@coefs,!j) 'store coefficients
' 4periodahead forecast
%4pers = @otod(@dtoo(%start)+!i+!window1) 'start point
%4pere = @otod(@dtoo(%start)+!i+!window+3) 'end point
if @dtoo(%end) < @dtoo(%4pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%4pers} {%4pere}
' forecast with command *forecast* (see also *fit*)
eq01.forecast(f=na) yf
' set sampl to obtain the 4th period observation
smpl {%4pere} {%4pere}
' store forecasts
fcast = yf
next
smpl @all
show coefmat
show fcast.line
d(noerr) yf
'calculate RMSE
scalar rmse=@rmse(y, fcast)
' plot actual and recursive forecasts
graph graph1.line y fcast
graph1.addtext(t) forecast
show graph1
I want to forecast 4 periods a head directly from equation recursively.
'run rolling regression
' set window size
!window = 142
' set step size
' declare equation for estimation
equation eq01
' get size of workfile
!length = @obsrange
%cmnd = _this.@command 'EDIT: get the equation specification stored in eviews
!step = 4
'calculate number of rolls
!nrolls = @floor((!length!window)/!step)
'matrix to store coefficient estimates
matrix(6,!nrolls) coefmat ' where 6 is the number of coefficients
'series to store forecast estimates
series fcast
'redundant series for 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 recursive window
%first = @otod(@dtoo(%start))
%last = @otod(@dtoo(%start)+!i+!window1)
smpl {%first} {%last}
' estimate equation 
!maxerr = @maxerrcount
setmaxerrs !maxerr+1
_this.{%cmnd} 'estimated equation
colplace(coefmat,eq01.@coefs,!j) 'store coefficients
' 4periodahead forecast
%4pers = @otod(@dtoo(%start)+!i+!window1) 'start point
%4pere = @otod(@dtoo(%start)+!i+!window+3) 'end point
if @dtoo(%end) < @dtoo(%4pere) then 'check whether the forecast end point is greater than the workfile end point
exitloop
endif
' set smpl for forecasting period
smpl {%4pers} {%4pere}
' forecast with command *forecast* (see also *fit*)
eq01.forecast(f=na) yf
' set sampl to obtain the 4th period observation
smpl {%4pere} {%4pere}
' store forecasts
fcast = yf
next
smpl @all
show coefmat
show fcast.line
d(noerr) yf
'calculate RMSE
scalar rmse=@rmse(y, fcast)
' plot actual and recursive forecasts
graph graph1.line y fcast
graph1.addtext(t) forecast
show graph1
Last edited by Nas1 on Wed Jan 29, 2014 2:44 pm, edited 1 time in total.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Multistep ahead forecast
How many coefficients do you have in your equation?
Follow us on Twitter @IHSEViews
Re: Multistep ahead forecast
EViews Gareth wrote:How many coefficients do you have in your equation?
Hello Gareth, thank you for your attention, I uploaded the WF.
 Attachments

 test.WF1
 (26.46 KiB) Downloaded 214 times

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Re: Multistep ahead forecast
I'm asking you, how many coefficients do you have?
Follow us on Twitter @IHSEViews
Re: Multistep ahead forecast
EViews Gareth wrote:I'm asking you, how many coefficients do you have?
I should have 6 coefficients, I put 6 in coefmat (matrix(6,!nrolls) coefmat) and I got the same error message about the number of the coefficients.

 Fe ddaethom, fe welon, fe amcangyfrifon
 Posts: 12339
 Joined: Tue Sep 16, 2008 5:38 pm
Who is online
Users browsing this forum: No registered users and 4 guests