|
Examples / TVARSET.RPF |
TVARSET.RPF is an example of the use of the @TVARSET procedure for setting up a VAR model with time varying coefficients. It uses the same data set and underlying model as CANMODEL.RPF, and, similarly, computes forecast performance statistics over a hold-back sample.
This is a six variable, four lag VAR with primarily Canadian data, but with US GDP and the US-Canada exchange rate included. The VAR is set up with the prior and variances for time variation with
@tvarset(model=canmodel,lags=4,tight=.1,other=.5)
# logcangdp logcandefl logcanm1 logexrate can3mthpcp logusagdp
This uses the default settings for time variation for a VAR, which has the covariance matrix of the coefficient drift being \(10^{-8}\) times the original covariance matrix for the prior. While this seems remarkably small, experience has shown that substantially larger values work poorly.
This sets up the THEIL matrices to evaluate 12 steps of forecast through the end of the data (2006:4).
theil(model=canmodel,setup,steps=12,to=2006:4)
Unlike a model with fixed coefficients (that is, a model where the underlying coefficients in each equation are assumed to be the same throughout the sample), a time-varying parameters model needs to be estimated by Kalman filter from the start of the sample. The early estimates will be dominated by the prior (basically will be random walks for each variable) until a sufficient number of observations have been processed. You need to do a KALMAN with the START option at the first period, then do simple KALMAN instructions for each subsequent period in the initial sample.
compute estart=(1981:1)+4
do time=estart,1998:4
if time==estart
kalman(start=time)
else
kalman
end do time
The remainder of the program does the forecast evaluation over the remainder of the sample. A THEIL instruction, then KALMAN and THEIL for each data point.
theil
do time=1999:1,2006:3
kalman
theil
end do time
*
theil(dump)
Full Program
open data oecdsample.rat
calendar(q) 1981
data(format=rats) 1981:1 2006:4 can3mthpcp canexpgdpchs canexpgdpds canm1s canusxsr usaexpgdpch
*
set logcangdp = log(canexpgdpchs)
set logcandefl = log(canexpgdpds)
set logcanm1 = log(canm1s)
set logusagdp = log(usaexpgdpch)
set logexrate = log(canusxsr)
*
* Use @TVARSET to set up the VAR system allowing for time variation. This uses a
* symmetrical prior with a .5 weight on the other variables with the default
* settings for the controls for time variation.
*
@tvarset(model=canmodel,lags=4,tight=.1,other=.5)
# logcangdp logcandefl logcanm1 logexrate can3mthpcp logusagdp
*
theil(model=canmodel,setup,steps=12,to=2006:4)
*
* Kalman filter through the early part of the data set (skipping the number of
* initial data points required for the lags in the model) without doing THEIL
* instructions. We need to do a KALMAN(START=TIME) at the first time period in the
* estimation period.
*
compute estart=(1981:1)+4
do time=estart,1998:4
if time==estart
kalman(start=time)
else
kalman
end do time
*
* Do a THEIL instruction after each data point starting with 1998:4.
*
theil
do time=1999:1,2006:3
kalman
theil
end do time
*
theil(dump)
The results can be compared to the "Simple BVAR" output in CANMODEL.RPF, which is the same model without time-variation. This model is worse on the forecasts of US GDP, somewhat worse on the exchange rate, much better on the interest rate and M1, and similar on the other two.
Output
Step Mean Error Mean Abs Err RMS Error Theil U N Obs
Forecast Statistics for Series LOGCANGDP
1 -0.0003661 0.0037694 0.0044981 0.5054 32
2 -0.0010563 0.0075760 0.0088421 0.5158 31
3 -0.0018301 0.0115724 0.0133853 0.5329 30
4 -0.0027310 0.0155674 0.0184112 0.5618 29
5 -0.0042633 0.0199846 0.0232273 0.5840 28
6 -0.0062136 0.0239898 0.0276272 0.5971 27
7 -0.0087309 0.0278686 0.0318064 0.6067 26
8 -0.0122581 0.0310377 0.0357724 0.6149 25
9 -0.0162545 0.0338217 0.0398809 0.6202 24
10 -0.0196211 0.0381612 0.0442378 0.6264 23
11 -0.0230766 0.0423018 0.0488385 0.6331 22
12 -0.0278898 0.0459501 0.0530783 0.6324 21
Forecast Statistics for Series LOGCANDEFL
1 0.00105471 0.00644385 0.00806667 0.8259 32
2 0.00256428 0.01028081 0.01363334 0.7866 31
3 0.00433368 0.01506864 0.01820352 0.7486 30
4 0.00646046 0.01842435 0.02277138 0.7328 29
5 0.00936566 0.02136243 0.02629581 0.6996 28
6 0.01204078 0.02384330 0.02916686 0.6674 27
7 0.01387568 0.02604304 0.03162527 0.6431 26
8 0.01590498 0.02819668 0.03382931 0.6201 25
9 0.01821500 0.02974930 0.03651166 0.6085 24
10 0.02005221 0.03042779 0.03852992 0.5906 23
11 0.02218337 0.03080381 0.03959992 0.5603 22
12 0.02461233 0.03268887 0.04183033 0.5447 21
Forecast Statistics for Series LOGCANM1
1 0.00399288 0.00886220 0.01096149 0.4798 32
2 0.00858145 0.01564171 0.01906037 0.4333 31
3 0.01359413 0.02238841 0.02625892 0.4047 30
4 0.01833075 0.03016437 0.03386358 0.3946 29
5 0.02311806 0.03613403 0.04082304 0.3823 28
6 0.02699821 0.03969398 0.04498500 0.3544 27
7 0.03099672 0.04337477 0.05066212 0.3439 26
8 0.03435710 0.04688648 0.05677631 0.3380 25
9 0.03572880 0.04760778 0.05826965 0.3095 24
10 0.03814868 0.05013180 0.06228074 0.2980 23
11 0.04125203 0.05404017 0.06860779 0.2984 22
12 0.04230947 0.05802288 0.07253988 0.2899 21
Forecast Statistics for Series LOGEXRATE
1 0.00840784 0.02572092 0.03244488 1.0504 32
2 0.01871892 0.04097086 0.05218154 1.0936 31
3 0.03023856 0.04803396 0.06453382 1.1019 30
4 0.04377978 0.06649690 0.08208211 1.1382 29
5 0.05783894 0.08292401 0.10206840 1.1769 28
6 0.07153868 0.10131105 0.11871186 1.1965 27
7 0.08442205 0.11544181 0.13722866 1.2076 26
8 0.09984644 0.13037788 0.15776671 1.2210 25
9 0.11916204 0.14834884 0.17424298 1.2264 24
10 0.13276471 0.15904801 0.18557887 1.2136 23
11 0.14464641 0.16488413 0.19711869 1.1999 22
12 0.15802887 0.17123939 0.20906479 1.1851 21
Forecast Statistics for Series CAN3MTHPCP
1 -0.0958548 0.2912795 0.3793158 0.8815 32
2 -0.1970200 0.5464715 0.6900328 0.9071 31
3 -0.2671540 0.7829490 0.9503192 0.9233 30
4 -0.3444389 1.0230867 1.1960085 0.9493 29
5 -0.4298329 1.1964347 1.4086699 0.9788 28
6 -0.5259698 1.3167149 1.5471117 0.9969 27
7 -0.6462312 1.3416087 1.6036591 0.9928 26
8 -0.7380299 1.3699327 1.6071650 0.9627 25
9 -0.7804746 1.4190249 1.5495588 0.8997 24
10 -0.8497336 1.3744296 1.4805331 0.8302 23
11 -0.9221814 1.3489276 1.4148612 0.7545 22
12 -0.9605231 1.2056704 1.3459912 0.6774 21
Forecast Statistics for Series LOGUSAGDP
1 -0.0010014 0.0044025 0.0055725 0.6586 32
2 -0.0022190 0.0073769 0.0092610 0.5944 31
3 -0.0035251 0.0114808 0.0140573 0.6108 30
4 -0.0049895 0.0148961 0.0185316 0.6167 29
5 -0.0072761 0.0181665 0.0224627 0.6176 28
6 -0.0092267 0.0215457 0.0260265 0.6077 27
7 -0.0117716 0.0240278 0.0289902 0.5960 26
8 -0.0143140 0.0265895 0.0320683 0.5863 25
9 -0.0172559 0.0287978 0.0346542 0.5719 24
10 -0.0194753 0.0317643 0.0372614 0.5577 23
11 -0.0214338 0.0354078 0.0400049 0.5477 22
12 -0.0239222 0.0379913 0.0422312 0.5313 21
Copyright © 2026 Thomas A. Doan