| 1 |
// --+ options: stochastic +-- |
| 2 |
|
| 3 |
/* © 2022 Dynare Team |
| 4 |
* |
| 5 |
* This file is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* It is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with the file. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
@#define USE_HISTVAL = 0 |
| 20 |
|
| 21 |
var y1 y2 y3 ; |
| 22 |
|
| 23 |
varexo e1 e2 e3 ; |
| 24 |
|
| 25 |
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 ; |
| 26 |
|
| 27 |
/* |
| 28 |
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that |
| 29 |
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than |
| 30 |
** one in modulus) probably because of the propagation of roundoff errors. |
| 31 |
*/ |
| 32 |
|
| 33 |
D = diag([.9 .7 .8]); |
| 34 |
P = randn(3,3); |
| 35 |
A = P*D*inv(P); |
| 36 |
|
| 37 |
a11 = A(1,1); |
| 38 |
a12 = A(1,2); |
| 39 |
a13 = A(1,3); |
| 40 |
a21 = A(2,1); |
| 41 |
a22 = A(2,2); |
| 42 |
a23 = A(2,3); |
| 43 |
a31 = A(3,1); |
| 44 |
a32 = A(3,2); |
| 45 |
a33 = A(3,3); |
| 46 |
|
| 47 |
model(linear); |
| 48 |
diff(y1) = a11*diff(y1(-1)) + a12*diff(y2(-1)) + a13*diff(y3(-1)) + e1 ; |
| 49 |
diff(y2) = a21*diff(y1(-1)) + a22*diff(y2(-1)) + a23*diff(y3(-1)) + e2 ; |
| 50 |
diff(y3) = a31*diff(y1(-1)) + a32*diff(y2(-1)) + a33*diff(y3(-1)) + e3 ; |
| 51 |
end; |
| 52 |
|
| 53 |
shocks; |
| 54 |
var e1 = 1.0; |
| 55 |
var e2 = 1.0; |
| 56 |
var e3 = 1.0; |
| 57 |
end; |
| 58 |
|
| 59 |
steady; |
| 60 |
|
| 61 |
check; |
| 62 |
|
| 63 |
@#if USE_HISTVAL |
| 64 |
histval; |
| 65 |
y1(0) = 0; |
| 66 |
y2(0) = 0; |
| 67 |
y3(0) = 0; |
| 68 |
y1(-1) = 0; |
| 69 |
y2(-1) = 0; |
| 70 |
y3(-1) = 0; |
| 71 |
end; |
| 72 |
TrueData = simul_backward_model([], 200); |
| 73 |
@#else |
| 74 |
initialconditions = dseries(zeros(2,6), 1Y, vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names)); |
| 75 |
TrueData = simul_backward_model(initialconditions, 200); |
| 76 |
@#endif |
| 77 |
|
| 78 |
// Set the periods where some of the endogenous variables will be constrained. |
| 79 |
subsample = 3Y:100Y; |
| 80 |
|
| 81 |
// Load the generated data |
| 82 |
SimulatedData = copy(TrueData); |
| 83 |
|
| 84 |
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock). |
| 85 |
constrainedpaths = SimulatedData{'y1'}(subsample); |
| 86 |
|
| 87 |
// Set the instruments (innovations used to control the paths for the endogenous variables). |
| 88 |
exogenousvariables = dseries([NaN(98, 1) TrueData{'e2','e3'}.data(3:100,:)], 3Y, M_.exo_names); |
| 89 |
|
| 90 |
// Invert the model by calling the model_inversion routine. |
| 91 |
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_); |
| 92 |
|
| 93 |
// Check that all the constraints are satisfied. |
| 94 |
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12 |
| 95 |
error('Constraint on y1 path is not satisfied!') |
| 96 |
end |
| 97 |
|
| 98 |
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12 |
| 99 |
error('Constraint on e1 path is not satisfied!') |
| 100 |
end |
| 101 |
|
| 102 |
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12 |
| 103 |
error('Constraint on e2 path is not satisfied!') |
| 104 |
end |
| 105 |
|
| 106 |
// Check consistency of the results. |
| 107 |
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12 |
| 108 |
error('Model inversion is not consistent with respect to y2') |
| 109 |
end |
| 110 |
|
| 111 |
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12 |
| 112 |
error('Model inversion is not consistent with respect to y3') |
| 113 |
end |
| 114 |
|
| 115 |
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12 |
| 116 |
error('Model inversion is not consistent with true innovations (e3)') |
| 117 |
end |