Debian Codegraph @

addons/SVAR/examples/SetRestrictions/KilianMurphy_relaxed.inp

raw
1 /*
2 Example script for sign restrictions in gretl's SVAR addon.
3 This here is to demonstrate the use of "exotic" restrictions,
4 inspired from Kilian & Murphy.
5
6 However, it is not a replication, since imposing all their
7 restrictions leads to very few accepted draws. Hence the
8 restrictions here are somewhat relaxed.
9 */
10
11 set verbose off
12 set seed 909090
13
14 include SVAR.gfn
15
16 open KMdata.gdt --quiet --frompkg=SVAR
17
18 # variables
19 list X = prod KI rpo inventories
20
21 # set up the model
22 list Z = const seasonals(1)
23 order = 24
24 bundle mod = SVAR_setup("SR", X, Z, order)
25 SVAR_cumulate(&mod, 1)
26 SVAR_cumulate(&mod, 4)
27 mod.horizon = 16
28
29 numofaccept = 256 # takes long
30 coverage = 0.95
31
32 ## set up the sign restictions
33 mod.snames = defarray("Supply", "Demand", "Speculative Demand")
34
35 # these are the "dynamic" and impact sign restrictions.
36 SVAR_SRplain(&mod, "prod", "Supply", "-", 12)
37 SVAR_SRplain(&mod, "KI", "Supply", "-", 12)
38 SVAR_SRplain(&mod, "rpo", "Supply", "+", 12)
39
40 SVAR_SRplain(&mod, "prod", "Demand", "+")
41 SVAR_SRplain(&mod, "KI", "Demand", "+")
42 SVAR_SRplain(&mod, "rpo", "Demand", "+")
43 # SignRest(&mod, "Demand", "inventories")
44
45 SVAR_SRplain(&mod, "prod", "Speculative Demand", "+")
46 SVAR_SRplain(&mod, "KI", "Speculative Demand", "-")
47 SVAR_SRplain(&mod, "rpo", "Speculative Demand", "+")
48 SVAR_SRplain(&mod, "inventories", "Speculative Demand","+")
49
50
51 ## exotic restrictions:
52 /* Attention:
53 The symbol "M" for the IRF matrix is hardcoded!
54 And if elements from the model bundle are needed, the name of
55 that bundle must in this context also be "mod".
56 (By coincidence in this script it also happens to be "mod" in
57 other contexts.)
58 The horizon range for which these exotic restrictions should
59 hold is specified explicitly or implicitly in the function
60 call below.
61 */
62 string exot2 = "M[1,2] / M[3,2] >= 0" # shock 2: Demand
63 string exot3 = "M[1,3] / M[3,3] >= 0" # shock 3: Specul. Demand
64
65
66 # TODO: These super-exotic restrictions work with hardcoded "mod"
67 # and thus curently do _not_ need need_model = 1.
68 # The whole need_model documentation needs fixing.
69
70 ## Supply elasticity bounds
71 # prepare
72 string part1 = "mean( (exp((log(54389) + cum(mod.Y[,1]))) * M[1,1] ./ 100 - M[4,1]) "
73 part1 ~= " ./ (exp((log(54389) + cum(mod.Y[,1]))) - mean(mod.Y[,4]))"
74 part1 ~= " ./ (M[3,1]./100) ) "
75 string exot1 = part1 ~ " >= -0.8" # shock 1: Supply
76
77 # memo: mean(mod.Y[,4]) = 4.4982 - from the summary statistics
78
79 string exot11 = part1 ~ " <= 0 " # shock 1: Supply
80
81 # apply exotic and super-exotic restrictions
82 SVAR_SRexotic(&mod, exot11, defarray("Supply"))
83 SVAR_SRexotic(&mod, exot1, defarray("Supply"))
84 SVAR_SRexotic(&mod, exot2, defarray("Demand"))
85 SVAR_SRexotic(&mod, exot3, defarray("Speculative Demand"))
86
87 # do the rotations (this is the computationally intensive part)
88 Bayesian = 1
89 SVAR_SRdraw(&mod, numofaccept, Bayesian, coverage, 25000)
90
91 # draw the irfs
92 gpbuild IRFPlots
93 SVAR_SRirf(mod, mod.Ynames, mod.snames)
94 end gpbuild
95
96 gridplot IRFPlots --output=display --cols=4 --width=1200 --height=800