bsvars / bsvarSIGNs

Bayesian SVARs with Sign, Zero, and Narrative Restrictions
http://bsvars.org/bsvarSIGNs/
Other
10 stars 2 forks source link

How can I add deterministics to a model identified by Sign restrictions? #55

Open JPablo1203 opened 1 week ago

JPablo1203 commented 1 week ago

I am trying to estimate a series of models with some deterministics - i.e., constant terms, dummies for the 2008 financial crises and some time trends.

After revising the documentation I have struggled to find examples of how to include them within the bsvarSIGNs workflow. I was therefore wondering if you could maybe workout a small example with one of the accompaniying vignettes.

For instance, taking the Arias, Rubio-Ramírez, & Waggoner (2018) series, it is noticeable that productivity is increasing throughout time and that there is a big deep on stock's prices on 2008:

library(bsvars)
library(bsvarSIGNs)

# investigate the effects of the optimism shock
data(optimism)

# plot the series
plot(optimism)

optimism evolution

If I were to include a constant for each variable, a time trend and a set of dummies for the 2008 observations, how would these fit within the workflow?

Thanks in advance for your kind help and for developing such a great package.

donotdespair commented 1 week ago

Hey @JPablo1203

Thanks so much for reaching out and your kind words about this work! We really appreciate this!

Here's a small example to illustrate the possible approach. It is based on the example available whn you xecute: ?bsvarSIGNs::estimate.BSVARSIGN. The extension includes the specification of the dymmy variable as a matrix with the number of rows the same as the input data in matrix optimism.

> library(bsvarSIGNs)
> data(optimism)
> 
> dummy = as.matrix(rep(0, nrow(optimism)))
> dummy[200:205] = 1
> 
> # specify identifying restrictions:
> # + no effect on productivity (zero restriction)
> # + positive effect on stock prices (positive sign restriction) 
> sign_irf       = matrix(c(0, 1, rep(NA, 23)), 5, 5)
> 
> # specify the model and set seed
> set.seed(123)
> specification  = specify_bsvarSIGN$new(
+   optimism * 100,
+   p        = 1,
+   sign_irf = sign_irf,
+   exogenous = dummy
+ )
> 
> # estimate the model
> posterior      = estimate(specification, S = 10)
**************************************************|
 bsvarSIGNs: Bayesian Structural VAR with sign,   |
             zero and narrative restrictions      |
**************************************************|
 Progress of simulation for 10 independent draws
 Press Esc to interrupt the computations
**************************************************|
0%   10   20   30   40   50   60   70   80   90   100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
> apply(posterior$posterior$A, 1:2, mean)
             [,1]         [,2]         [,3]       [,4]          [,5]       [,6]       [,7]
[1,]  0.991759947 1.786706e-03 -0.000645267 0.04606189 -0.0003360055  2.0976934  0.3231690
[2,] -0.003529415 9.969500e-01  0.004925880 0.01382317  0.0032667429  1.7007535  2.3772056
[3,] -0.009652161 7.392993e-04  1.000541694 0.02267975  0.0006105814  2.4073697  0.2329108
[4,] -0.028298626 1.384864e-03  0.007707101 0.60096218  0.0015731459  7.9172172  0.3241072
[5,]  0.001166160 5.287929e-05 -0.001627602 0.03320721  1.0005328484 -0.3894902 -0.0712389

The constant term is always included in our models. You can create any matrix of deterministic terms with any number of columns in dummy and provide it here. The $A$ matrix includes first all the autoregressive matrices, thn the constant term, and then your provided exogenous variables. Above the posterior mean of $A$ includes a 5x5 matrix for lag 1, then the column of constant terms, and then the slope on the dummy.

The use of the exogenous variables in bsvarSIGNs is the same as in package bsvars. I have recently issued its new version that includes extensive examples with exogenous variables available by executing ?bsvars::bsvars.

Let me know if this helps!

Greetings, T