Debian Codegraph @

addons/SVAR/examples/SetRestrictions/mixed_example.inp

raw
1 # Example script for mixed restrictions in gretl's SVAR addon
2
3 set verbose off
4 set plot_collection on
5 set seed 240523
6
7 include SVAR.gfn
8
9 ### artificial example
10
11 nulldata 360
12 setobs 12 1:1
13
14 ###
15 # set up the DGP (a trivariate VAR(1))
16 ###
17
18 # the autoregresive matrix
19 A = {0.8, -0.1, 0.1; 0.4, 0.8, -0.1; -0.4, 0.1, 0.8}
20 # the true C matrix
21 C = {1, 1, 0; -0.2, 1, 0.6; -0.8, 0.0, 1}
22 scalar n = rows(C)
23 E = mnormal($nobs, n) * C'
24 # stationarity check
25 eval eigen(A)
26
27 M = C
28 i = 0
29
30 if 1
31 printf "True IRFS:\n"
32 loop 6
33 printf "%d:\n%8.3f\n", i, M
34 M = A*M
35 i++
36 endloop
37 printf "%d:\n%8.3f\n", i, M
38 endif
39 # generate artificial data
40
41 mY = varsimul(A, E, zeros(1, n))
42 list Y = mat2list(mY[2:,], "y")
43
44 # var 1 Y --silent
45 # eval $sigma
46 # eval C*C'
47
48 # set up the model
49
50 list W = const
51 scalar order = 1
52 scalar store_draws = 1
53 bundle mod = SVAR_setup("SR", Y, W, order, store_draws)
54
55 # set up the sign restictions
56
57 mod.snames = defarray("foo", "bar", "baz")
58
59 # instantaneous restrictions
60
61 mod.SRest = {}
62 SVAR_SRplain(&mod, "y1", "foo", "+")
63 SVAR_SRplain(&mod, "y2", "bar", "+")
64 SVAR_SRplain(&mod, "y3", "baz", "+")
65
66 SVAR_SRplain(&mod, "y2", "baz", "+", 4, 0)
67 SVAR_SRplain(&mod, "y2", "foo", "-")
68 SVAR_SRplain(&mod, "y1", "bar", "+", 4)
69 SVAR_SRplain(&mod, "y3", "foo", "-", 4)
70
71 # now add zero restrictions
72
73 SVAR_restrict(&mod, "C", 1, 3) # instantaneous response of y1 to baz is 0
74 SVAR_restrict(&mod, "C", 3, 2) # instantaneous response of y3 to bar is 0
75
76 # add a cross-variable restriction, that is C_{1,2} = C_{2,2}
77 # Rd = mod.Rd1
78 # tmp = {0,1,0; 0,-1,0; 0,0,0}
79 # Rd = Rd | (vec(tmp)' ~ 0)
80 # mod.Rd1 = Rd
81
82 # estimate
83 DO_BAYES = 1
84 SVAR_SRdraw(&mod, 192, DO_BAYES)
85
86 # draw the IRFs
87
88 strings IRFPlots
89 SVAR_SRirf(mod, mod.Ynames, defarray("foo", "bar", "baz"), 0, &IRFPlots)
90 gridplot IRFPlots --output=display
91
92 # draw the spaghetti plots for the point restrictions
93 SVAR_spagplot(mod, "y1", "baz")
94 SVAR_spagplot(mod, "y3", "bar")