| 1 |
# Example script for sign restrictions in gretl's SVAR addon |
| 2 |
|
| 3 |
set verbose off |
| 4 |
include SVAR.gfn |
| 5 |
|
| 6 |
### supply & demand (artificial example) |
| 7 |
|
| 8 |
nulldata 240 |
| 9 |
setobs 12 1:1 |
| 10 |
b = -0.8 # demand elasticity |
| 11 |
c = 1.1 # supply elasticity |
| 12 |
|
| 13 |
Gamma = {1, -c; -b, 1} |
| 14 |
iG = inv(Gamma) |
| 15 |
U = 3 + filter(mnormal($nobs, 2), 1, 0.8) |
| 16 |
Y = U * iG' |
| 17 |
series p = Y[,1] |
| 18 |
series q = Y[,2] |
| 19 |
list X = p q |
| 20 |
|
| 21 |
var 1 X --quiet |
| 22 |
eval $sigma |
| 23 |
eval iG*iG' |
| 24 |
|
| 25 |
# set up the model |
| 26 |
|
| 27 |
list W = const |
| 28 |
scalar order = 1 |
| 29 |
|
| 30 |
bundle mod = SVAR_setup("SR", X, W, order) |
| 31 |
|
| 32 |
# set up the sign restictions |
| 33 |
|
| 34 |
mod.snames[1] = "Supply" |
| 35 |
mod.snames[2] = "Demand" |
| 36 |
|
| 37 |
# instantaneous restrictions |
| 38 |
|
| 39 |
mod.SRest = {} |
| 40 |
SVAR_SRplain(&mod, "p", "Supply", "-") # supply shock brings price down |
| 41 |
SVAR_SRplain(&mod, "q", "Supply", "+") # and quantity up |
| 42 |
SVAR_SRplain(&mod, "p", "Demand", "+") # demand shock raises price |
| 43 |
SVAR_SRplain(&mod, "q", "Demand", "+") # as well as quantity |
| 44 |
|
| 45 |
rep = 128 |
| 46 |
|
| 47 |
# do the rotations (this is the computationally intensive part) |
| 48 |
SVAR_SRdraw(&mod, rep) |
| 49 |
|
| 50 |
# draw the irfs on a 2x2 grid |
| 51 |
gpbuild Plots |
| 52 |
SVAR_spagplot(mod, "p", "Supply") # 1, 1) |
| 53 |
SVAR_spagplot(mod, "p", "Demand") # 1, 2) |
| 54 |
SVAR_spagplot(mod, "q", "Supply") # 2, 1) |
| 55 |
SVAR_spagplot(mod, "q", "Demand") # 2, 2) |
| 56 |
end gpbuild |
| 57 |
|
| 58 |
gridplot Plots --output=display |