I am working with a workfile (attached) and I want to do a 4-period ahead forecast with a VAR. The data is quarterly from 1960q1 through 2017q4.
So, this is what I want it to do:
1. Estimate a VAR over 40 observations ((40/4) = 10 years) and then forecast 4 periods ahead.
2. The forecasted 4th-period-ahead value should be stored in a new series e_cpi against the last date of the estimation sample. So, for example, if a VAR was estimated till 1970q4, then the forecasted value should be stored against 1970q4 in e_cpi. That is basically finding the inflationary expectations.
I have written the following code:
Code: Select all
!window_length = 40
!no_rolls = 192 'The times it need to roll. Total observations to be rolled on =232-40=192
!steps_ahead = 4 '4 period year ahead forecast
series e_cpi 'This will store our forecasted values
for !i=0 to (!no_rolls)
'Specifying the VAR on 40 observations
smpl @first+!i @first+!window_length+!i-1 'You need -1 to push back the last quarter.
'So for first VAR, it will go from 1960q1 to 1970q4.
var var_!i.ls(noconst) 1 5 d(log_gdp_i1) d(d(cpi_log_i2)) d(reverse_rate_i1)
'I have differenced for stationarity.
'Forecasting over the next four periods
smpl @first+!window_length+!i @first+!window_length+!i+!steps_ahead-1
'Remember @first+windowlength lands you on 1971q1 for the first iteration.
'Storing the value into a separate series
%date1 = @otod(!window_length+!steps_ahead-1+!i)
scalar x = @elem(CPI_LOG_I2_!i, %date1) 'This takes the forecasted value from the forecasted series
e_cpi(39+!i) = x 'Because the forecasted value should be stored against 1965q4
I have tried to add comments where I could. When I did it with annual data, it worked just fine.
1. But with quarterly data, I am getting this error:
Log of non positive number in "VAR VAR_!I.LS(NOCONST) 1
5 D(LOG_GDP_I1) D(D(CPI_LOG_I2)) D(REVERSE_RATE_I1)".
Even though I have already taken the log of the required variables and there is no negative value in any of the series. I am using EViews 10.
2. Is there an easier way to do this? I know this code generates series and clogs the workfile, but I am just interested in e_cpi (inflationary expectations.
Any help would be appreciated. Thank you. I am stuck over this and have no clue.