Debian Codegraph @

tests/model-inversion/nk-1/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{'y','pi','i'}(subsample);
43
44 /* REMARKS
45 **
46 ** In this example we constrain all the endogenous variables from 2Y to 100Y to match the same variables as given by simulated.mod.
47 ** When we invert the model, we search the sequence of innovations that leads to these realizations of the endogenous variables. 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. We expect the difference on e_y and e_pi to be small, and the difference on e_i much larger
52 ** when the economy hits the ZLB (in this situation the solver compensate the absence of the max operator in the Taylor equation with a greater
53 ** value of e_i, compared to the true value, to keep the economy on the ZLB).
54 **
55 */
56
57 // Set the instruments (innovations used to control the paths for the endogenous variables).
58 exogenousvariables = dseries(NaN(99, 3), 2Y, {'e_y';'e_pi';'e_i'});
59
60 /* REMARKS
61 **
62 ** We need as many instruments as contrained endogenous variables. There is no association of these innovations with the constrained
63 ** endogenous variables. The instruments are identified by a NaN value for the exogenous variables. In this example all the exogenous
64 ** variables are used as instruments.
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 /* REMARKS
72 **
73 ** Output arguments endogenousvariables and exogenousvariables are dseries objects.
74 **
75 ** In this example we constrain all the endogenous variables, so the variables in the first output argument matches exactly the
76 ** constraints given in inputs. If we constrained only a subset of the variables we would have more variables in the first output
77 ** argument than in the first input argument (constrainedpaths). Obviously the additional endogenous variables, ie the unconstrained
78 ** endogenous variables, depend on the constraints given in the first input argument. The second output argument contains the
79 ** exogenous variables consistent with the constraints defined in the first input argument. In this example, we have as many shocks for
80 ** controlling the endogenous variables than shocks in the model.
81 **
82 */
83
84
85 // Check that all the constraints are satisfied.
86 if max(abs(endogenousvariables.y(subsample).data-SimulatedData.y(subsample).data))>1e-6 || max(abs(endogenousvariables.pi(subsample).data-SimulatedData.pi(subsample).data))>1e-6 || max(abs(endogenousvariables.i(subsample).data-SimulatedData.i(subsample).data))>1e-6
87 error('Constrained on endogenous variable paths are not all satisfied!')
88 end
89
90 // Plot the differences on e_y (shock in the Euler equation)
91 figure(1)
92 plot(exogenousvariables.e_y-SimulatedData.e_y) % Not zero because of the misspecification related to the ZLB
93 title('e_y')
94
95 // Plot the differences on e_pi (shock in the Phillips curve)
96 figure(2)
97 plot(exogenousvariables.e_pi-SimulatedData.e_pi) % Not zero because of the misspecification related to the ZLB
98 title('e_pi')
99
100 // Plot the differences on e_ik (shock in the Taylor rule)
101 // The red bullets correpond the ZLB episodes.
102 figure(3)
103 plot(exogenousvariables.e_i-SimulatedData.e_i) % Not zero because of the misspecification related to the ZLB
104 title('e_i')
105 hold on
106 id = find(endogenousvariables.i.data==-.05);
107 plot(id, zeros(1,length(id)), 'or')
108 hold off