Recursive Forecasting Scheme
Posted: Sun Aug 26, 2012 5:48 pm
Dear eviews programming experts,
i have the following problem. I'm a beginner in eviews and have to program for my master thesis in econometrics. So far, i have modelled a vectorautoregression with three variables. Now, i want to calculate one-step-ahead and six-step-ahead forecasts for this model in order to get the forecast errors. For this purpose, the forecasts should be based on a recursive forecasting scheme.
I have tried to write a corresponding program. I'm relatively sure, that this program contains errors. First, i have seen, that only the last one-step-ahead-forecast was saved, for example in the stahl_bereinigt_0 series. How can I manage, that the forecasts over the entire loop are saved in table or a series? How can i store the forecasts? And second, is the conversion from the system to the model right, because i simply defined a system, estimated the system, and then built the model. Third, are there other problems with my program? I thank you very much in advance. Below the code:
wfcreate Masterarbeit m "1991-01" "2012-02"
' creates workfile
!first=@dateval("1991-01")
!last=@dateval("2012-02")
!varnr = 3
matrix(254,!varnr) datamat
' generates matrix for data
datamat.read(a2,s=sheet2) "E:\Empirische Wirtschaftsforschung\Masterarbeit\Datensatz Masterarbeit.xls"
' read the data from the excel dataset into a data matrix
series stahl_bereinigt
series pkw_bereinigt
series logmaschinenbau
' generates series for the different variables
group variables stahl_bereinigt pkw_bereinigt logmaschinenbau
' generates a group including the individual series
mtos(datamat,variables)
' convert the data matrix to the group defined above
genr DS2 = @seas(2)-1/12
genr DS3 = @seas(3)-1/12
genr DS4 = @seas(4)-1/12
genr DS5 = @seas(5)-1/12
genr DS6 = @seas(6)-1/12
genr DS7 = @seas(7)-1/12
genr DS8 = @seas(8)-1/12
genr DS9 = @seas(9)-1/12
genr DS10 = @seas(10)-1/12
genr DS11 = @seas(11)-1/12
genr DS12 = @seas(12)-1/12
' generates centered seasonal dummies
genr DLS_masch_1 = @recode(@date>@dateval("1992-11"),1,0)
genr DLS_pkw = @recode(@date>@dateval("1992-12"),1,0)
genr DLS_stahl = @recode(@date>@dateval("2008-10"),1,0)
genr DLS_masch_2 = @recode(@date>@dateval("2008-12"),1,0)
genr DLS_masch_3 = @recode(@date>@dateval("2009-03"),1,0)
' generates dummies for the level shifts
system VAR_system
VAR_system.append stahl_bereinigt = C(1)+C(2)*@trend(1991M01)+C(3)*stahl_bereinigt(-1)+C(4)*stahl_bereinigt(-2)+C(5)*stahl_bereinigt(-3)+C(6)*pkw_bereinigt(-3)+C(7)*pkw_bereinigt(-5)+C(8)*pkw_bereinigt(-6)+C(9)*pkw_bereinigt(-7)+C(10)*logmaschinenbau(-2)+C(11)*logmaschinenbau(-3)+C(12)*logmaschinenbau(-5)+C(13)*logmaschinenbau(-6)+C(14)*DS2+C(15)*DS7+C(16)*DS8+C(17)*DS9+C(18)*DS11+C(19)*DS12+C(20)*DLS_stahl
VAR_system.append pkw_bereinigt = C(21)+C(22)*@trend(1991M01)+C(23)*stahl_bereinigt(-1)+C(24)*stahl_bereinigt(-2)+C(25)*stahl_bereinigt(-6)+C(26)*stahl_bereinigt(-7)+C(27)*pkw_bereinigt(-2)+C(28)*pkw_bereinigt(-3)+C(29)*pkw_bereinigt(-5)+C(30)*pkw_bereinigt(-7)+C(31)*logmaschinenbau(-4)+C(32)*logmaschinenbau(-5)+C(33)*logmaschinenbau(-6)+C(34)*logmaschinenbau(-7)+C(35)*DS2+C(36)*DS3+C(37)*DS4+C(38)*DS8+C(39)*DS9+C(40)*DS10+C(41)*DS11+C(42)*DS12+C(43)*DLS_pkw
VAR_system.append logmaschinenbau = C(44)+C(45)*@trend(1991M01)+C(46)*stahl_bereinigt(-1)+C(47)*stahl_bereinigt(-5)+C(48)*stahl_bereinigt(-7)+C(49)*pkw_bereinigt(-1)+C(50)*pkw_bereinigt(-5)+C(51)*pkw_bereinigt(-6)+C(52)*pkw_bereinigt(-7)+C(53)*logmaschinenbau(-1)+C(54)*logmaschinenbau(-2)+C(55)*logmaschinenbau(-3)+C(56)*DS2+C(57)*DS3+C(58)*DS4+C(59)*DS5+C(60)*DS6+C(61)*DS7+C(62)*DS8+C(63)*DS9+C(64)*DS10+C(65)*DS11+C(66)*DS12+C(67)*DLS_masch_1+C(68)*DLS_masch_2+C(69)*DLS_masch_3
' defines the systems of equations of the VAR model
!obstotal = @obssmpl
' counting the number of observations in the sample
!window = 30
' sets the forecast window
!hori = 1
' sets the forecast horizon
!foreper = !window-!hori+1
' determines the length of the forecast period and hence the series of forecasts
matrix(!foreper,!varnr) foremat
' generates matrix for the model forecasts
for !j=1 to !foreper step 1
' starts a loop for the calculation of the model forecasts
smpl "1991-01" "2012-02"-!window+!j-1
VAR_system.sur
' estimates the VAR model
VAR_system.makemodel(VAR_model)
'transforms the estimated VAR system into a model
smpl "2012-02"-!window+!j "2012-02"-!window+!j+!hori-1
' sets the forecast period
VAR_model.solve
' calculates forecasts by solving the specified VAR model
next
i have the following problem. I'm a beginner in eviews and have to program for my master thesis in econometrics. So far, i have modelled a vectorautoregression with three variables. Now, i want to calculate one-step-ahead and six-step-ahead forecasts for this model in order to get the forecast errors. For this purpose, the forecasts should be based on a recursive forecasting scheme.
I have tried to write a corresponding program. I'm relatively sure, that this program contains errors. First, i have seen, that only the last one-step-ahead-forecast was saved, for example in the stahl_bereinigt_0 series. How can I manage, that the forecasts over the entire loop are saved in table or a series? How can i store the forecasts? And second, is the conversion from the system to the model right, because i simply defined a system, estimated the system, and then built the model. Third, are there other problems with my program? I thank you very much in advance. Below the code:
wfcreate Masterarbeit m "1991-01" "2012-02"
' creates workfile
!first=@dateval("1991-01")
!last=@dateval("2012-02")
!varnr = 3
matrix(254,!varnr) datamat
' generates matrix for data
datamat.read(a2,s=sheet2) "E:\Empirische Wirtschaftsforschung\Masterarbeit\Datensatz Masterarbeit.xls"
' read the data from the excel dataset into a data matrix
series stahl_bereinigt
series pkw_bereinigt
series logmaschinenbau
' generates series for the different variables
group variables stahl_bereinigt pkw_bereinigt logmaschinenbau
' generates a group including the individual series
mtos(datamat,variables)
' convert the data matrix to the group defined above
genr DS2 = @seas(2)-1/12
genr DS3 = @seas(3)-1/12
genr DS4 = @seas(4)-1/12
genr DS5 = @seas(5)-1/12
genr DS6 = @seas(6)-1/12
genr DS7 = @seas(7)-1/12
genr DS8 = @seas(8)-1/12
genr DS9 = @seas(9)-1/12
genr DS10 = @seas(10)-1/12
genr DS11 = @seas(11)-1/12
genr DS12 = @seas(12)-1/12
' generates centered seasonal dummies
genr DLS_masch_1 = @recode(@date>@dateval("1992-11"),1,0)
genr DLS_pkw = @recode(@date>@dateval("1992-12"),1,0)
genr DLS_stahl = @recode(@date>@dateval("2008-10"),1,0)
genr DLS_masch_2 = @recode(@date>@dateval("2008-12"),1,0)
genr DLS_masch_3 = @recode(@date>@dateval("2009-03"),1,0)
' generates dummies for the level shifts
system VAR_system
VAR_system.append stahl_bereinigt = C(1)+C(2)*@trend(1991M01)+C(3)*stahl_bereinigt(-1)+C(4)*stahl_bereinigt(-2)+C(5)*stahl_bereinigt(-3)+C(6)*pkw_bereinigt(-3)+C(7)*pkw_bereinigt(-5)+C(8)*pkw_bereinigt(-6)+C(9)*pkw_bereinigt(-7)+C(10)*logmaschinenbau(-2)+C(11)*logmaschinenbau(-3)+C(12)*logmaschinenbau(-5)+C(13)*logmaschinenbau(-6)+C(14)*DS2+C(15)*DS7+C(16)*DS8+C(17)*DS9+C(18)*DS11+C(19)*DS12+C(20)*DLS_stahl
VAR_system.append pkw_bereinigt = C(21)+C(22)*@trend(1991M01)+C(23)*stahl_bereinigt(-1)+C(24)*stahl_bereinigt(-2)+C(25)*stahl_bereinigt(-6)+C(26)*stahl_bereinigt(-7)+C(27)*pkw_bereinigt(-2)+C(28)*pkw_bereinigt(-3)+C(29)*pkw_bereinigt(-5)+C(30)*pkw_bereinigt(-7)+C(31)*logmaschinenbau(-4)+C(32)*logmaschinenbau(-5)+C(33)*logmaschinenbau(-6)+C(34)*logmaschinenbau(-7)+C(35)*DS2+C(36)*DS3+C(37)*DS4+C(38)*DS8+C(39)*DS9+C(40)*DS10+C(41)*DS11+C(42)*DS12+C(43)*DLS_pkw
VAR_system.append logmaschinenbau = C(44)+C(45)*@trend(1991M01)+C(46)*stahl_bereinigt(-1)+C(47)*stahl_bereinigt(-5)+C(48)*stahl_bereinigt(-7)+C(49)*pkw_bereinigt(-1)+C(50)*pkw_bereinigt(-5)+C(51)*pkw_bereinigt(-6)+C(52)*pkw_bereinigt(-7)+C(53)*logmaschinenbau(-1)+C(54)*logmaschinenbau(-2)+C(55)*logmaschinenbau(-3)+C(56)*DS2+C(57)*DS3+C(58)*DS4+C(59)*DS5+C(60)*DS6+C(61)*DS7+C(62)*DS8+C(63)*DS9+C(64)*DS10+C(65)*DS11+C(66)*DS12+C(67)*DLS_masch_1+C(68)*DLS_masch_2+C(69)*DLS_masch_3
' defines the systems of equations of the VAR model
!obstotal = @obssmpl
' counting the number of observations in the sample
!window = 30
' sets the forecast window
!hori = 1
' sets the forecast horizon
!foreper = !window-!hori+1
' determines the length of the forecast period and hence the series of forecasts
matrix(!foreper,!varnr) foremat
' generates matrix for the model forecasts
for !j=1 to !foreper step 1
' starts a loop for the calculation of the model forecasts
smpl "1991-01" "2012-02"-!window+!j-1
VAR_system.sur
' estimates the VAR model
VAR_system.makemodel(VAR_model)
'transforms the estimated VAR system into a model
smpl "2012-02"-!window+!j "2012-02"-!window+!j+!hori-1
' sets the forecast period
VAR_model.solve
' calculates forecasts by solving the specified VAR model
next