| 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 fake_backward = 1 |
| 20 |
|
| 21 |
var y1 y2 y3 ; |
| 22 |
|
| 23 |
@#if fake_backward |
| 24 |
var z ; |
| 25 |
@#endif |
| 26 |
|
| 27 |
varexo e1 e2 e3 ; |
| 28 |
|
| 29 |
parameters a b c ; |
| 30 |
|
| 31 |
a = .1; |
| 32 |
b = .2; |
| 33 |
c = .3; |
| 34 |
|
| 35 |
model; |
| 36 |
@#if fake_backward |
| 37 |
z = a*z(-1) ; |
| 38 |
@#endif |
| 39 |
y1 = y2*y3+exp(e1) ; |
| 40 |
y2 = 1 + y1*exp(e2) ; |
| 41 |
y3 = e3 ; |
| 42 |
end; |
| 43 |
|
| 44 |
@#if fake_backward |
| 45 |
histval; |
| 46 |
z(0) = .0 ; |
| 47 |
end; |
| 48 |
@#endif |
| 49 |
|
| 50 |
shocks; |
| 51 |
var e1 = .01; |
| 52 |
var e2 = .01; |
| 53 |
var e3 = .02; |
| 54 |
end; |
| 55 |
|
| 56 |
TrueData = simul_backward_model([], 1000); |
| 57 |
|
| 58 |
// Set the periods where some of the endogenous variables will be constrained. |
| 59 |
subsample = 2Y:101Y; |
| 60 |
|
| 61 |
// Load the generated data |
| 62 |
SimulatedData = copy(TrueData); |
| 63 |
|
| 64 |
// Set the constrained paths for the endogenous variables. |
| 65 |
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample); |
| 66 |
|
| 67 |
// Set the instruments (innovations used to control the paths for the endogenous variables). |
| 68 |
exogenousvariables = dseries([NaN(100, 3)], '2Y', M_.exo_names); |
| 69 |
|
| 70 |
/* REMARK |
| 71 |
** |
| 72 |
** Here we will control y1, y2, and y3 with e1, e2 and e3. |
| 73 |
** |
| 74 |
*/ |
| 75 |
|
| 76 |
// Invert the model by calling the model_inversion routine. |
| 77 |
options_.dynatol.f = 1e-9; |
| 78 |
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_); |
| 79 |
|
| 80 |
// Check that all the constraints are satisfied. |
| 81 |
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12 |
| 82 |
error('Constraint on y1 path is not satisfied!') |
| 83 |
end |
| 84 |
|
| 85 |
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12 |
| 86 |
error('Constraint on y2 path is not satisfied!') |
| 87 |
end |
| 88 |
|
| 89 |
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12 |
| 90 |
error('Constraint on y3 path is not satisfied!') |
| 91 |
end |
| 92 |
|
| 93 |
// Check consistency of the results. |
| 94 |
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-8 |
| 95 |
error('Model inversion is not consistent with true innovations (e1)') |
| 96 |
end |
| 97 |
|
| 98 |
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-8 |
| 99 |
error('Model inversion is not consistent with true innovations (e2)') |
| 100 |
end |
| 101 |
|
| 102 |
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-8 |
| 103 |
error('Model inversion is not consistent with true innovations (e3)') |
| 104 |
end |