CALENDAR(M) 1965:7
DATA(FORMAT=XLSX,ORG=COLUMNS) 1965:07 2010:12 month MktRF RF Divyield500 Divyield Term Default SL SM SH $
BL BM BH
clear rhat
do fstart=1980:1,2004:12
linreg(noprint) sl fstart-59 fstart-1
# constant mktrf smb hml
uforecast rhat fstart fstart
end do
@uforeerrors sl rhat 19801:1 2004:12
*
* Diebold-Mariano test
*
set naive 1980:1 2004:12 = 0.78
@dmariano sl naive rhat
TomDoan wrote:@uforeerrors sl rhat 19801:1 2004:12
You have a typo in your date.
clear rhat1
do fstart=1988:4,2010:12
linreg(noprint) r11 fstart-273 fstart-1
# constant mktrf smb hml
uforecast rhat1 fstart fstart
end do
@uforeerrors r11 rhat1 1988:4 2010:12
clear rhat2
do fstart=1988:4,2010:12
linreg(noprint) r11 fstart-273 fstart-1
# constant snew(1) snew(2) snew(3)
uforecast rhat2 fstart fstart
end do
@uforeerrors r11 rhat2 1988:4 2010:12
@dmariano r11 rhat1 rhat2
set foreerror1sq = (r11-rhat1)**2
set foreerror2sq = (r11-rhat2)**2
set diff = foreerror1sq-foreerror2sq
stat diff
Forecast Analysis for R11
From 1988:04 to 2010:12
Mean Error 0.09607337
Mean Absolute Error 3.06732641
Root Mean Square Error 4.87751621
Mean Square Error 23.790164
Theil's U 0.434008
Forecast Analysis for R11
From 1988:04 to 2010:12
Mean Error 0.01344721
Mean Absolute Error 1.76551429
Root Mean Square Error 2.40882310
Mean Square Error 5.802429
Theil's U 0.214340
Diebold-Mariano Forecast Comparison Test
Forecasts of R11 over 1988:04 to 2010:12
Forecast MSE Test Stat P(DM>x)
RHAT1 23.7901644 2.7072 0.00339
RHAT2 5.8024287 -2.7072 0.99661
fan wrote:in addition, could you please kindly help me compute DM-STAT to test null hypothesis H0: diff=0? Many Thanks
* MASE (Mean Absolute Scaled Error)
if startl == 1 {
comp %%MASE = %na; * undefined
}
else {
set num startl endl = actual-forecast
set den / = abs(actual-actual{1})
SSTATS(mean) startl endl den>>mean_den;
*disp mean_den
* or alternatively by-hand
*SSTATS startl endl den>>sum_den; * SSTATS computes the sum, without any option
*comp mean_den = sum_den/%NOBS
*disp mean_den
set ratio = abs(num/mean_den)
SSTATS(mean) startl endl ratio>>%%MASE
}
* MASE reported in nonpos==0 section as MASE is defined as a ratio. MASE is always calculated.
if (h==1)
report(use=ureport,row=new,atcol=1) "MASE" %%MASE
else
report(use=ureport,row=new,atcol=1)
TomDoan wrote:1. What is H?
TomDoan wrote:2. The denominator is the mean absolute no change error through the training sample. Nothing else in @UFOREERRORS uses training (i.e. regression) sample data so there is nothing in the design to let you compute it within the procedure. It's probably simpler to compute it once and pass it through as an option.
procedure acUForeErrors actual forecast MANCE start end
TYPE REAL MANCE
option integer MASE 0
local series RATIO
if (MASE==1)
set RATIO = abs(ferrors/MANCE)
SSTATS(mean) startl endl RATIO>>%%FERRMASE
* MASE reported in nonpos==0 section as MASE is defined as a ratio. %%FERRMASE is always calculated.
if (MASE==1)
report(use=ureport,row=new,atcol=1) "MASE" %%FERRMASE
else
report(use=ureport,row=new,atcol=1)
end acUForeErrors
* MANCE is calculated from the training period:
set den / = abs(actual-actual{1})
sstats(mean) regstart regend den>>MANCE
* and then
@acUForeErrors(MASE=1) actual forecast MANCE start end
Users browsing this forum: No registered users and 2 guests