|
Examples / CANMODEL.RPF |
CANMODEL.RPF is an example for setting up and choosing a Bayesian VAR (BVAR) for forecasting purposes. It chooses a prior for the BVAR based upon simulated out-of-sample forecasting performance using the "Simple Procedure" for this purpose, that is:
1.Run a system of univariate OLS models to get benchmark Theil U’s.
2.Run a system of univariate models with a standard value for TIGHTNESS.
3.Run a standard SYMMETRIC prior.
Based upon these, adjust the prior (switching to a GENERAL prior):
•If the Theil U’s in an equation are worse in 2 than in 1, loosen up on the own lags by setting the diagonal element to 1.5 or 2.0.
•If the Theil U’s in an equation are worse in 3 than in 2, tighten up on the other variables by reducing the off-diagonal elements.
Most of the work is done by the (easily modified model-specific) @RunTheil procedure, which sets up a Bayesian VAR for the six variable system, and runs the simulated out-of-sample forecasts using KALMAN to roll through the evaluation sample.
The univariate "OLS" models are done by
@runtheil(tightness=2.0,other=.001,window="Univariate OLS")
which has a (very) loose prior with the OTHER contribution effectively shut down. (You can't put in OTHER=0 because it would cause a divide by zero).
The general impression from the results is that LOGCANM1 and LOGEXRATE (the 3rd and 4th variables in the list of six) are forecast better by univariate models and the others by multivariate models. So the GENERAL prior basically uses the SYMMETRIC prior values for variables 1, 2, 5 and 6 and the univariate "BVAR" (that is, with a prior rather than OLS) values for variables 3 and 4. Variable 5 (interest rate) is a bit of a blend, with smaller off-diagonals (thus not as much interaction) and a larger than 1.0 diagonal.
Full Program
*********************************************************************
*
* Set Up Data
*
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)
*
**********************************************************************
*
* RunTheil Procedure
* Needs modification of the lines tagged with ;*<<<<<<< to accomodate
* different models. Computes Theil U's for a VAR using either a
* symmetric or general prior.
*
* By setting TIGHTNESS to a large value (such as 2.00), you effectively
* eliminate the "Bayesian" part, and thus look at an OLS VAR.
*
* By setting OTHER to a very small value (such as .001), you effectively
* eliminate the "Vector" part, and thus look at an autoregression only.
*
procedure runtheil
option choice type 1 symmetric general
option rect matrix
option vector mvector
option real tightness .1
option real other .5
option string window
*
local integer time
*
system(model=canmodel) ;*<<<<<<<
variables logcangdp logcandefl logcanm1 logexrate can3mthpcp logusagdp ;*<<<<<<<<
lags 1 to 4 ;*<<<<<<<
det constant
specify(tightness=tightness,type=type,matrix=matrix,mvector=mvector) other
end(system)
*
theil(model=canmodel,setup,steps=12,to=2006:4) ;*<<<<<<<
estimate(noprint) * 1998:4 ;*<<<<<<<
theil
do time=1999:1,2006:3 ;*<<<<<<<
kalman
theil
end do time
theil(dump,window=window)
end
*
***********************************************************************
*
@runtheil(tightness=2.0,other=.001,window="Univariate OLS")
@runtheil(tightness=0.1,other=.001,window="Univariate BVAR")
@runtheil(tightness=0.1,other=0.5,window="Simple BVAR")
@runtheil(tightness=2.0,other=1.0,window="OLS VAR")
*
@runtheil(tight=.10,type=general,window="General")
# 1.00 0.50 0.50 0.50 0.50 0.50 $
0.50 1.00 0.50 0.50 0.50 0.50 $
0.01 0.01 1.00 0.01 0.01 0.01 $
0.01 0.01 0.01 1.00 0.01 0.01 $
0.20 0.20 0.20 0.20 2.00 0.20 $
0.50 0.50 0.50 0.50 0.50 1.00
Copyright © 2025 Thomas A. Doan