First Program / Rolling Forecast

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

kcaron
Posts: 101
Joined: Wed Mar 04, 2015 11:46 am

First Program / Rolling Forecast

Postby kcaron » Tue Nov 24, 2015 3:40 pm

I'm using EViews 8.1 and working on my first program. I'm working on a rolling forecast...

I've got a workbook with monthly data from 1999m12 to the present. The series I'm forecasting is a calculated series that has several NA values early on and then begins to generate actual numbers... I've got some code that I want to start the sample estimation period at the first real (non "NA") number... In this code, there is a @first statement which is not getting the job done. Can someone help me write this code so that the estimation period starts with my first valid number?

Here is my "program" code:

' Set window size
!window = 30

' Get size of workfile
!length = @obsrange

' Declare equation for estimation
equation eq1

' Declare series for final results
series yhat 'Point estimates
series yhat_se 'Forecast std.err

' Set forecast range (step size)
!step = 4

' Move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
' set sample to estimatein period
smpl @first+!i-1 @first+!i+!window-2
' estimate equation
eq1.ls SPENDING c spending(-1 to -12)
' reset sample to forecast period
smpl @first+!i+!window-1 @first+!i+!window-2+!step
' make forecasts in temporary series first
eq1.forecast(f=na) tmp_yhat tmp_se
' copy data in current forecast sample
yhat = tmp_yhat
yhat_se = tmp_se
next

Thank you! I'm really stuck on this one...

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

Re: First Program / Rolling Forecast

Postby EViews Gareth » Tue Nov 24, 2015 5:03 pm

You're using @first in the sample statement, and it knows nothing about the values inside a specific series. You'll need to work out the date of the first non-na separately and then use it in the sample statement.

Something like:

Code: Select all

%spendfirst = spending.@first ' Move sample !step obs at a time for !i = 1 to !length-!window+1-!step step !step ' set sample to estimatein period smpl {%spendfirst}+!i-1 {%spendfirst}+!i+!window-2

kcaron
Posts: 101
Joined: Wed Mar 04, 2015 11:46 am

Re: First Program / Rolling Forecast

Postby kcaron » Wed Nov 25, 2015 10:28 am

Gareth,

Thank you so much! It works pretty well!!! It produces "forecasts" from the beginning of the spending series to the end of the series plus two more months beyond the end. I need to go 6 months past the end though...

Toward the end of the routine, however, I get the following message:

Unable to compute due to missing data in "DO_EQ1.FORECAST(F=NA) TMP_YHAT TMP_SE"

Here is the series output:

spending YHAT
1999M12 NA NA
2000M01 NA NA
2000M02 NA NA
2000M03 NA NA
2000M04 NA NA
2000M05 NA NA
2000M06 NA NA
2000M07 NA NA
2000M08 NA NA
2000M09 NA NA
2000M10 NA NA
2000M11 NA NA
2000M12 NA NA
2001M01 NA NA
2001M02 NA NA
2001M03 NA NA
2001M04 NA NA
2001M05 NA NA
2001M06 NA NA
2001M07 NA NA
2001M08 NA NA
2001M09 NA NA
2001M10 NA NA
2001M11 NA NA
2001M12 NA NA
2002M01 NA NA
2002M02 NA NA
2002M03 NA NA
2002M04 NA NA
2002M05 NA NA
2002M06 NA NA
2002M07 NA NA
2002M08 NA NA
2002M09 NA NA
2002M10 NA NA
2002M11 NA NA
2002M12 NA NA
2003M01 NA NA
2003M02 NA NA
2003M03 NA NA
2003M04 NA NA
2003M05 NA NA
2003M06 NA NA
2003M07 NA NA
2003M08 NA NA
2003M09 NA NA
2003M10 NA NA
2003M11 NA NA
2003M12 NA NA
2004M01 NA NA
2004M02 NA NA
2004M03 NA NA
2004M04 NA NA
2004M05 NA NA
2004M06 NA NA
2004M07 NA NA
2004M08 NA NA
2004M09 NA NA
2004M10 NA NA
2004M11 NA NA
2004M12 NA NA
2005M01 NA NA
2005M02 NA NA
2005M03 NA NA
2005M04 NA NA
2005M05 NA NA
2005M06 NA NA
2005M07 NA NA
2005M08 NA NA
2005M09 58.519 NA
2005M10 62.037 NA
2005M11 63.889 NA
2005M12 58.889 NA
2006M01 69.259 NA
2006M02 69.074 NA
2006M03 68.889 NA
2006M04 74.259 NA
2006M05 74.074 NA
2006M06 69.259 NA
2006M07 58.704 NA
2006M08 42.037 NA
2006M09 43.519 NA
2006M10 52.037 NA
2006M11 46.852 NA
2006M12 60.556 NA
2007M01 62.222 NA
2007M02 53.148 NA
2007M03 55.000 NA
2007M04 64.074 NA
2007M05 62.222 NA
2007M06 67.778 NA
2007M07 64.074 NA
2007M08 52.407 NA
2007M09 45.370 NA
2007M10 38.333 NA
2007M11 27.778 NA
2007M12 28.148 NA
2008M01 22.407 NA
2008M02 19.444 NA
2008M03 26.111 15.700
2008M04 25.926 24.002
2008M05 27.963 25.095
2008M06 30.926 34.710
2008M07 28.889 24.604
2008M08 24.259 20.502
2008M09 15.556 19.864
2008M10 5.185 1.173
2008M11 3.333 -5.572
2008M12 3.333 -6.375
2009M01 3.333 -4.394
2009M02 7.037 4.796
2009M03 20.926 5.171
2009M04 29.630 26.640
2009M05 43.704 41.889
2009M06 61.111 57.184
2009M07 78.333 72.897
2009M08 84.815 89.834
2009M09 89.815 90.180
2009M10 88.333 89.127
2009M11 84.815 83.917
2009M12 81.296 77.001
2010M01 79.630 78.467
2010M02 81.296 78.983
2010M03 84.444 86.261
2010M04 82.778 89.084
2010M05 80.741 83.508
2010M06 70.000 79.205
2010M07 52.778 52.901
2010M08 45.926 31.309
2010M09 46.111 36.040
2010M10 50.000 46.250
2010M11 56.667 56.861
2010M12 70.556 60.458
2011M01 82.593 78.302
2011M02 84.074 87.506
2011M03 80.000 79.837
2011M04 76.667 79.514
2011M05 71.481 72.854
2011M06 56.481 65.922
2011M07 49.444 47.781
2011M08 34.074 50.905
2011M09 20.370 24.917
2011M10 18.519 6.028
2011M11 21.852 28.779
2011M12 25.185 31.931
2012M01 31.852 37.996
2012M02 46.111 39.583
2012M03 54.815 55.970
2012M04 67.037 61.317
2012M05 68.889 79.520
2012M06 51.852 69.483
2012M07 41.296 33.084
2012M08 34.444 31.262
2012M09 39.444 19.828
2012M10 47.963 39.869
2012M11 56.667 56.386
2012M12 70.370 56.515
2013M01 82.407 78.193
2013M02 87.963 94.058
2013M03 80.926 80.361
2013M04 70.556 71.069
2013M05 65.556 56.835
2013M06 60.000 59.253
2013M07 62.037 54.240
2013M08 56.296 62.476
2013M09 61.852 50.996
2013M10 69.074 69.001
2013M11 65.370 71.437
2013M12 65.370 61.615
2014M01 66.852 53.781
2014M02 65.185 67.380
2014M03 61.481 59.674
2014M04 59.444 60.171
2014M05 59.444 56.088
2014M06 59.630 60.872
2014M07 71.852 62.959
2014M08 66.481 74.935
2014M09 65.185 63.457
2014M10 61.667 69.083
2014M11 53.148 58.126
2014M12 52.963 55.721
2015M01 44.444 49.277
2015M02 29.259 48.925
2015M03 29.074 35.747
2015M04 34.074 30.960
2015M05 46.111 32.552
2015M06 56.667 51.242
2015M07 51.296 63.770
2015M08 49.444 52.235
2015M09 42.407 52.414
2015M10 NA 36.646
2015M11 NA 47.854
2015M12 NA NA
2016M01 NA NA
2016M02 NA NA
2016M03 NA NA
2016M04 NA NA
2016M05 NA NA
2016M06 NA NA
2016M07 NA NA
2016M08 NA NA
2016M09 NA NA
2016M10 NA NA
2016M11 NA NA
2016M12 NA NA

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

Re: First Program / Rolling Forecast

Postby EViews Gareth » Wed Nov 25, 2015 5:22 pm

Try it without the f=na option.

lbrks
Posts: 1
Joined: Tue Apr 26, 2016 11:38 am

Re: First Program / Rolling Forecast

Postby lbrks » Tue Apr 26, 2016 11:43 am

Hello everyone,

I would like to forecast by rolling window. my data is monthly from 2006m02 to 2016m01. I am trying to create a forecast for last 12 months. (2015m01 to 2016m01). can somebody help to create the codes? thank you all.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests