| 1 |
# Example script for sign restrictions in gretl's SVAR addon |
| 2 |
|
| 3 |
set verbose off |
| 4 |
set seed 909090 |
| 5 |
|
| 6 |
include SVAR.gfn |
| 7 |
|
| 8 |
### |
| 9 |
### --- Uhlig (2005) example |
| 10 |
### |
| 11 |
|
| 12 |
# data handling |
| 13 |
|
| 14 |
open UhligData.gdt --quiet --frompkg=SVAR |
| 15 |
series y = 100 * log(RealGDP) |
| 16 |
series p = 100 * log(CPI) |
| 17 |
series cp = 100 * log(CommodityPrice) |
| 18 |
series r = FedFund |
| 19 |
series nbr = 100 * log(NonBorrReserves) |
| 20 |
series res = 100 * log(TotalReserves) |
| 21 |
|
| 22 |
# set up the model |
| 23 |
|
| 24 |
list X = y p cp r nbr res |
| 25 |
list Z = const |
| 26 |
scalar order = 12 |
| 27 |
|
| 28 |
if 0 |
| 29 |
### replicate page 395 (sort of) |
| 30 |
|
| 31 |
# set up a "classically-identified" Cholesky model |
| 32 |
bundle mod0 = SVAR_setup("plain", X, Z, order) |
| 33 |
mod0.horizon = 60 |
| 34 |
mod0.snames[4] = "Monetary" |
| 35 |
|
| 36 |
SVAR_estimate(&mod0) |
| 37 |
bfail = SVAR_boot(&mod0, 1024, 0.63) |
| 38 |
loop i = 1..6 |
| 39 |
IRFplot(&mod0, 4, i) |
| 40 |
endloop |
| 41 |
endif |
| 42 |
|
| 43 |
# Switch to a sign restriction model |
| 44 |
|
| 45 |
bundle mod = SVAR_setup("SR", X, Z, order) |
| 46 |
mod.horizon = 60 |
| 47 |
mod.snames[4] = "Monetary" |
| 48 |
|
| 49 |
/* |
| 50 |
Above the shock #4 is labeled Monetary, and below some sign |
| 51 |
restrictions are given for it, and no other shock. |
| 52 |
*/ |
| 53 |
|
| 54 |
# set up the sign restictions |
| 55 |
|
| 56 |
SVAR_SRplain(&mod, "p", "Monetary", "-", 5) # negative from 0 to 5 |
| 57 |
SVAR_SRplain(&mod, "nbr", "Monetary", "-", 5) # ditto |
| 58 |
SVAR_SRplain(&mod, "cp", "Monetary", "-", 5) # ditto |
| 59 |
SVAR_SRplain(&mod, "r", "Monetary", "+", 5) # positive from 0 to 5 |
| 60 |
|
| 61 |
# do the rotations (this is the computationally intensive part) |
| 62 |
# (creating all bundles 'moo' is unnecessary in principle) |
| 63 |
bundles moo = SVAR_SRdraw(&mod, 256, 1, 0.75) # coverage 75% |
| 64 |
|
| 65 |
# draw the irfs (page 397) |
| 66 |
|
| 67 |
strings IRFPlots = array(0) # array for storing the plots |
| 68 |
SVAR_SRirf(mod, mod.Ynames, defarray("Monetary"),, &IRFPlots) # create the plots |
| 69 |
gridplot IRFPlots --output=display # display in a grid |
| 70 |
|
| 71 |
|