On Sat, 16 Feb 2019, Artur T. wrote:
I am trying to do some forecasting exercise using a panel data set. I
am a
bit puzzled as the fcast command does not behave as I would have thought.
However, I am not sure I am using fcast correctly in this example -- the
manual doesn't include anything on the fcast command in connection with panel
data currently. Please, see the sample script below.
<hansl>
clear
set verbose off
open abdata.gdt -q
# Set training set
smpl time<=7 --restrict
# Estimate a model
list reg = const CAP WAGE
ols INDOUTPT reg --quiet
# Forecast out-of-sample
#-----------------------
# These options don't work
catch fcast --out-of-sample
catch fcast 1:8 140:9 --out-of-sample
catch fcast 1:8 140:9 --static
# In-sample fit: works
# fcast --static
# Forecast of the 8th and 9th entry only
fcast 8 9 --static
# Set test set manually
smpl time>7 --restrict --replace
# FIXME: By the way, note that the selected sample
# shown is "1:1 - 140:2" instead of "1:8 - 140:9"
# call fcast: RESULTS IN ERROR
catch fcast --out-of-sample # --> doesn't work
catch fcast --static # --> doesn't work
</hansl>
True, the "fcast" facilities we have for time-series data are not
available for panel data. That's no doubt something we should work
on. In the meantime one can do an out-of-sample forecast manually. I
show an example below, for pooled OLS, fixed effects and random
effects. (But note that the latter is not consistent in this case.)
<hansl>
open abdata.gdt -q
# Set training set
smpl time <= 7 --restrict
# Estimate a model
list reg = const n k
# OLS
ols ys reg --quiet
matrix b_ols = $coeff
# fixed effects
panel ys reg --quiet
matrix b_fe = $coeff
matrix a_fe = pshrink($ahat)
# random effects
panel ys reg --random --quiet
matrix b_re = $coeff
matrix a_re = pshrink($ahat)
# Forecast out-of-sample
smpl time > 7 --restrict --replace
# OLS
yhat1 = lincomb(reg, b_ols)
# fixed effects
series ahat = pexpand(a_fe)
b_fe[1] = 0 # skip the global intercept
yhat2 = ahat + lincomb(reg, b_fe)
# random effects
ahat = pexpand(a_re)
yhat3 = ahat + lincomb(reg, b_re)
print YEAR yhat1 yhat2 yhat3 -o
T = nelem(values(YEAR))
MSE1 = sum((ys - yhat1)^2) / T
MSE2 = sum((ys - yhat2)^2) / T
MSE3 = sum((ys - yhat3)^2) / T
printf "Out of sample MSE: OLS %g, F.E. %g, R.E. %g\n",
MSE1, MSE2, MSE3
</hansl>
Allin