Recursive BVAR help

Questions and discussions on Vector Autoregressions
Solstice
Posts: 6
Joined: Sat Mar 30, 2013 3:23 pm

Recursive BVAR help

Unread post by Solstice »

Dear all,

I have been given a rats .prg from a co-author and I am slightly confused, perhaps you can help - I would be eternally grateful. The goal is to create recursive (out of sample) forecasts from a BVAR. I have generated four random variables from 1980q1:2012q4 to help to make the exposition clearer. In the first example dataset (example1.xls), all data entries are present. This is the following code which attempts to generate pseudo real time OOS forecasts:

Code: Select all

*  Set Up Data
open data example1.xls
calendar(q) 1980
data(format=XLS,ORGANIZATION=COLUMNS) 1980:1 2012:4 var1 var2 var3 var4
procedure runtheil
option  choice    type        1    symmetric  general
option  rect      matrix
option  vector    mvector
option  real      tightness  
option  real      other      
option  real      decay      
option  string    window
local   integer  time
system(model=EXAMPLEMODEL)                                        ;*<<<<<<<
variables var1 var2 var3 var4
lags 1 to 2                                                    ;*<<<<<<<
det constant
specify(tightness=tightness,type=type,matrix=matrix,mvector=mvector,decay=decay)  other
end(system)
theil(model=EXAMPLEMODEL,SETUP) 177 8 2012:4                ;*<<<<<<<
estimate(noprint) * 2003:4                                    ;*<<<<<<<
theil
do time=2004:1,2012:4                                         ;*<<<<<<<
   kalman
   theil
end do time
theil(dump,window=window)
end
@runtheil(tightness=0.1237,other=1,decay=1,window="BVAR")
FORECAST(MODEL=EXAMPLEMODEL,window="1") 4 8 2004:1
FORECAST(MODEL=EXAMPLEMODEL,window="2") 4 8 2004:2
FORECAST(MODEL=EXAMPLEMODEL,window="3") 4 8 2004:3
FORECAST(MODEL=EXAMPLEMODEL,window="4") 4 8 2004:4
FORECAST(MODEL=EXAMPLEMODEL,window="5") 4 8 2005:1
FORECAST(MODEL=EXAMPLEMODEL,window="6") 4 8 2005:2
FORECAST(MODEL=EXAMPLEMODEL,window="7") 4 8 2005:3
FORECAST(MODEL=EXAMPLEMODEL,window="8") 4 8 2005:4
FORECAST(MODEL=EXAMPLEMODEL,window="9") 4 8 2006:1
FORECAST(MODEL=EXAMPLEMODEL,window="10") 4 8 2006:2
FORECAST(MODEL=EXAMPLEMODEL,window="11") 4 8 2006:3
FORECAST(MODEL=EXAMPLEMODEL,window="12") 4 8 2006:4
FORECAST(MODEL=EXAMPLEMODEL,window="13") 4 8 2007:1
FORECAST(MODEL=EXAMPLEMODEL,window="14") 4 8 2007:2
FORECAST(MODEL=EXAMPLEMODEL,window="15") 4 8 2007:3
FORECAST(MODEL=EXAMPLEMODEL,window="16") 4 8 2007:4
FORECAST(MODEL=EXAMPLEMODEL,window="17") 4 8 2008:1
FORECAST(MODEL=EXAMPLEMODEL,window="18") 4 8 2008:2
FORECAST(MODEL=EXAMPLEMODEL,window="19") 4 8 2008:3
FORECAST(MODEL=EXAMPLEMODEL,window="20") 4 8 2008:4
FORECAST(MODEL=EXAMPLEMODEL,window="21") 4 8 2009:1
FORECAST(MODEL=EXAMPLEMODEL,window="22") 4 8 2009:2
FORECAST(MODEL=EXAMPLEMODEL,window="23") 4 8 2009:3
FORECAST(MODEL=EXAMPLEMODEL,window="24") 4 8 2009:4
FORECAST(MODEL=EXAMPLEMODEL,window="25") 4 8 2010:1
FORECAST(MODEL=EXAMPLEMODEL,window="26") 4 8 2010:2
FORECAST(MODEL=EXAMPLEMODEL,window="27") 4 8 2010:3
FORECAST(MODEL=EXAMPLEMODEL,window="28") 4 8 2010:4
FORECAST(MODEL=EXAMPLEMODEL,window="29") 4 8 2011:1
FORECAST(MODEL=EXAMPLEMODEL,window="30") 4 8 2011:2
FORECAST(MODEL=EXAMPLEMODEL,window="31") 4 8 2011:3
FORECAST(MODEL=EXAMPLEMODEL,window="32") 4 8 2011:4
FORECAST(MODEL=EXAMPLEMODEL,window="33") 4 8 2012:1
FORECAST(MODEL=EXAMPLEMODEL,window="34") 4 8 2012:2
FORECAST(MODEL=EXAMPLEMODEL,window="35") 4 8 2012:3
FORECAST(MODEL=EXAMPLEMODEL,window="36") 4 8 2012:4
*
Which I thought would be correct. However, if we compare this with the second code file below, and instead use the data in the example2.xls which is for just one recursion, and is missing all of the out of sample data (to fit in with our ex-ante 'psuedo realtime exercise', we can see that for the first recursion (in-sample estimation from 1980q1:2003q4 and the first OOS for 8 steps is 2004q1:2005:q4), the results are markedly different from the first forecast produced from the above code when 'window = 1'.

Code: Select all

*  Set Up Data
*
open data example2.xls
calendar(q) 1980
data(format=XLS,ORGANIZATION=COLUMNS) 1980:1 2012:4 var1 var2 var3 var4
*
*  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  
option  real      other      
option  real      decay      
option  string    window
*
local   integer  time
*
system(model=EXAMPLEMODEL)                                        ;*<<<<<<<
variables var1 var2 var3 var4
lags 1 to 2                                                    ;*<<<<<<<
det constant
specify(tightness=tightness,type=type,matrix=matrix,mvector=mvector,decay=decay)  other
end(system)
*
theil(model=EXAMPLEMODEL,SETUP) 177 8 2012:4                ;*<<<<<<<
estimate(noprint) * 2003:4                                    ;*<<<<<<<
theil
do time=2004:1,2012:4                                         ;*<<<<<<<
   kalman
   theil
end do time
theil(dump,window=window)
end
*
***********************************************************************
*
@runtheil(tightness=0.1237,other=1,decay=1,window="BVAR")
FORECAST(MODEL=EXAMPLEMODEL,window="1") 4 8 2004:1

*
It is my suspicion that the program is not creating dynamic OOS forecasts from recursive re-estimations, but is instead using in-sample static 'fits' for a model estimated across the whole period. However, this is contradictory to my understanding of the FORECAST command.

Attached are the two datasets, and any help would be just great if you can spare the time to consider the matter.
Attachments
example2.xls
(37.5 KiB) Downloaded 593 times
example1.xls
(40 KiB) Downloaded 570 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Recursive BVAR help

Unread post by TomDoan »

All those FORECAST instructions will be computed using the end-of-sample estimates. If you want a print of the forecasts as they are generated, add a PRINT option to the THEIL instruction inside the procedure as shown:

do time=2004:1,2012:4 ;*<<<<<<<
kalman
theil(PRINT)
end do time
Solstice
Posts: 6
Joined: Sat Mar 30, 2013 3:23 pm

Re: Recursive BVAR help

Unread post by Solstice »

Dear Tom,

Thanks for your help. I modified the important lines of the runtheil code, and I was wondering if you could confirm if it is doing that which I hope it is:

Code: Select all

system(model=testmodel)                                        ;*<<<<<<<
variables v1 v2 v3 v4
lags 1 to 2                                                    ;*<<<<<<<
det constant
specify(tightness=0.1237,type=type,matrix=matrix,mvector=mvector,decay=decay)  other
end(system)
theil(model=testmodel,SETUP) 177 8 2012:4                ;*<<<<<<<
estimate(noprint) * 2003:3                                    ;*<<<<<<<
theil
do time=2004:1,2012:4                                         ;*<<<<<<<
   kalman
   theil(print)
end do time
theil(dump,window=window)
end
@runtheil(tightness=0.1237,other=1,decay=1,window="BVAR")
It is my hope that the code is running 36 in-sample estimations between 2003q4 and 2012q3 and producing H=8 out of sample forecasts at each recursive step (i.e. for the first recursion, the model is esimated using all data up until 2003q4, and then forecasts for h=1...8 are for 2004q1:2005q4, as claims to be printed). At each recursive step, the model is being re-estimated with tightness=0.1237, and forecasts are being generated accordingly. As an econometrician who is slightly unfamiliar with RATs (but hoping to learn more), my only confusion is the fact that @runtheil command is outside of the do loop, which leads me to believe the forecasts could be static in nature.

Any advice or comments of course would be hugely and wholly appreciated, as always
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Recursive BVAR help

Unread post by TomDoan »

RUNTHEIL is a procedure which includes the loop, but the loop isn't executed until you do the @RUNTHEIL. If you're just doing one model setup, there isn't too much point to writing the procedure rather than just doing the SYSTEM, ESTIMATE, loop with KALMAN and THEIL lines, but if you have it you might as well use it.
Solstice
Posts: 6
Joined: Sat Mar 30, 2013 3:23 pm

Re: Recursive BVAR help

Unread post by Solstice »

Thanks Tom, I hadnt realised that the system and theil/kalman commands were encapsulated within the runtheil procedure. Is there any small chance you could verify that my understanding of the time horizons of the in-sample estimations and out of sample forecast generation is correct, as per above? Very grateful for your help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Recursive BVAR help

Unread post by TomDoan »

I'm not sure what the 177 is supposed to be, though it will be ignored when you're using the MODEL option (it's the parameter for the number of equations).

The more modern syntax on the THEIL(SETUP...) instruction would be

theil(model=testmodel,SETUP,steps=8,to=2012:4)

which is easier to understand. It's 8 step horizon on the forecast evaluating against data through 2012:4. It's the same as what you have, just easier to read.

Your final KALMAN takes you through 2012:4, so there will be no forecasts at that point to evaluate (since the data also end there), but I assume that's what you want anyway.
Post Reply