Debian Codegraph @

tests/model-inversion/nk-2/invert.mod

raw
1 var y pi i;
2
3 varexo e_y e_pi e_i;
4
5 parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
6
7 a1 = .2;
8 a2 = .8;
9 a3 = .05;
10
11 b1 = .3;
12 b2 = .7;
13 b3 = .1;
14
15 c1 = 0.9;
16 c2 = 1.5;
17 c3 = 0.5;
18
19 model;
20 y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
21 pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
22 i = c1*i(-1) + c2*pi(1) + c3*y + e_i ;
23 end;
24
25 steady;
26
27 check;
28
29 shocks;
30 var e_y = 0.002;
31 var e_pi = 0.004;
32 var e_i = 0.001;
33 end;
34
35 // Set the periods where some of the endogenous variables will be constrained.
36 subsample = 2Y:100Y;
37
38 // Load all the data generated by simulate.mod
39 SimulatedData = dseries('truedata.mat');
40
41 // Set the constrained paths for the endogenous variables.
42 constrainedpaths = SimulatedData{'i'}(subsample);
43
44 /* REMARKS
45 **
46 ** In this example we constrain only the nominal interest rate from 2Y to 100Y to match the same variable as given by simulated.mod.
47 ** When we invert the model, we search the sequence of innovations e_i that leads to these realizations of the nominal interest rate. If
48 ** the model is the same, the sequence of innovations returned by the inversion routine has to match the true sequence of shocks (used
49 ** in simulated.mod and available for reference in SimulatedData dseries object). In this example, we invert the model with a slightly
50 ** different model by removing the max operator in the Taylor rule. Because of this difference, the innovations returned by the inversion
51 ** routine are not equal to the true innovations.
52 **
53 */
54
55 // Set the instruments (innovations used to control the nominal interest rate).
56 exodata = SimulatedData{'e_y', 'e_pi', 'e_i'}.data;
57 exodata(2:100,3) = NaN;
58 exogenousvariables = dseries(exodata, 1Y, {'e_y';'e_pi';'e_i'});
59
60 /* REMARK
61 **
62 ** We need as many instruments as contrained endogenous variables. In this case we control the nominal interest rate path with the shock
63 ** in the Taylor rule. The other shocks have non NaN values (we use the values generated by simulation.mod). These shocks are considered as observed
64 ** exogenous variables.
65 **
66 */
67
68 // Invert the model by calling the model_inversion routine.
69 [endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
70
71 // Check the path for the nominal interest rate
72 if max(abs(endogenousvariables.i(subsample).data-SimulatedData.i(subsample).data))>1e-6
73 error('Constrained on endogenous variable paths are not all satisfied!')
74 end
75
76 // Save the simulations on disk.
77 endogenousvariables.save('endogenousvariables', 'mat');
78 exogenousvariables.save('exogenousvariables', 'mat');
79
80 // Plot the differences on e_y (shock in the Euler equation)
81 figure(1)
82 plot(exogenousvariables.e_y-SimulatedData.e_y) % Not zero because of the misspecification related to the ZLB
83 title('e_y')
84
85 // Plot the differences on e_pi (shock in the Phillips curve)
86 figure(2)
87 plot(exogenousvariables.e_pi-SimulatedData.e_pi) % Not zero because of the misspecification related to the ZLB
88 title('e_pi')
89
90 // Plot the differences on e_ik (shock in the Taylor rule)
91 figure(3)
92 plot(exogenousvariables.e_i-SimulatedData.e_i) % Not zero because of the misspecification related to the ZLB
93 title('e_i')
94 hold on
95 id = find(endogenousvariables.i.data==-.05);
96 plot(id, zeros(1,length(id)), 'or')
97 hold off
98
99 figure(4)
100 plot(endogenousvariables(1Y:100Y).i,'-k','linewidth',2)
101 hold on
102 plot(SimulatedData(1Y:100Y).i,'--r','linewidth',2)
103 hold off
104 title('Nominal interest rate')
105
106 figure(5)
107 plot(endogenousvariables(1Y:100Y).y,'-k','linewidth',2)
108 hold on
109 plot(SimulatedData(1Y:100Y).y,'--r','linewidth',2)
110 hold off
111 title('Output gap')
112
113 figure(6)
114 plot(endogenousvariables(1Y:100Y).pi,'-k','linewidth',2)
115 hold on
116 plot(SimulatedData(1Y:100Y).pi,'--r','linewidth',2)
117 hold off
118 title('Inflation gap')