Skipping NA values in Forecast
Posted: Wed May 04, 2016 2:32 am
Hi,
I am having the following problem.
When doing 1-day ahead forecast with expanding estimation window, the code blocks because for one of the regressor (pcr130) there are missing values.
The way I want to modify the code by making it "skip" the forecast when observation for regressor is not available. Forecasting is static so there shouldn't be any problem if a forecast is skipped, since the 1-day ahead uses actual lagged values and not forecasted ones.
If I remove the regressor with missing observation, the code runs smoothly.
Any suggestion?
Many thanks
I am having the following problem.
When doing 1-day ahead forecast with expanding estimation window, the code blocks because for one of the regressor (pcr130) there are missing values.
The way I want to modify the code by making it "skip" the forecast when observation for regressor is not available. Forecasting is static so there shouldn't be any problem if a forecast is skipped, since the 1-day ahead uses actual lagged values and not forecasted ones.
If I remove the regressor with missing observation, the code runs smoothly.
Any suggestion?
Many thanks
Code: Select all
'create series for forecast and standard error
series y
series ye
'forecasts start
%d = "12/30/2011"
'# obs until end - manually insert, calculated number of days until 8/31/2015
!end = 921
'1-step ahead forecast = 1 day
!step = 1
'first sample for estimating equation
smpl @first {%d}-{!step}+1
'set the cicle, from 0 to 921
for !i = 0 to {!end}-1
'define sample for equation
smpl @first {%d}-{!step}+1+!i
'estimate equation
eq1.ls _1future c _1future(-1) vixspot(-1) coma copa pcrall pcr130
'define forecast horizon - 1 day after the sample period
smpl {%d}+!i+1 {%d}+!i+1
'forecast the equation and store the predicted value and standard error
eq1.fit forecast forecast_se
y=forecast
ye=forecast_se
next
'sample for calculating performance stats
smpl 01/03/2012 8/31/2015
scalar mape = @mape( _1future, y)
scalar mae = @mae( _1future, y)
scalar theil = @theil( _1future, y)
scalar rmse = @rmse( _1future, y)
smpl 01/03/2012 8/31/2015
'smpl 8/03/2015 8/31/2015 when testing 1 month
group A y _1future ( y - 1.96*ye) ( y + 1.96*ye)
show a.line