Add integration tests for model inversion.
parent
0df38369a7
commit
ac2b3f2bdc
|
@ -463,6 +463,31 @@ MODFILES = \
|
|||
bgp/solow-1/solow.mod \
|
||||
bgp/nk-1/nk.mod \
|
||||
bgp/ramsey-1/ramsey.mod \
|
||||
model-inversion/bk-1/solow_ces.mod \
|
||||
model-inversion/bk-2/solow_ces.mod \
|
||||
model-inversion/bk-3a/varmodel.mod \
|
||||
model-inversion/bk-3a-nlsolve/varmodel.mod \
|
||||
model-inversion/bk-3b/varmodel.mod \
|
||||
model-inversion/bk-3b-nlsolve/varmodel.mod \
|
||||
model-inversion/bk-4/varmodel.mod \
|
||||
model-inversion/bk-4-nlsolve/varmodel.mod \
|
||||
model-inversion/bk-5/varmodel.mod \
|
||||
model-inversion/bk-5-nlsolve/varmodel.mod \
|
||||
model-inversion/bk-6/varmodel.mod \
|
||||
model-inversion/bk-7/varmodel.mod \
|
||||
model-inversion/bk-8/varmodel.mod \
|
||||
model-inversion/bk-9/msm1.mod \
|
||||
model-inversion/bk-9/msm2.mod \
|
||||
model-inversion/bk-diff-1/varmodel.mod \
|
||||
model-inversion/bk-diff-2/varmodel.mod \
|
||||
model-inversion/bk-diff-3/varmodel.mod \
|
||||
model-inversion/bk-diff-4/varmodel.mod \
|
||||
model-inversion/bk-diff-5/varmodel.mod \
|
||||
model-inversion/nk-1/simulate.mod \
|
||||
model-inversion/nk-1/invert.mod \
|
||||
model-inversion/nk-2/simulate.mod \
|
||||
model-inversion/nk-2/invert.mod \
|
||||
model-inversion/nk-2/z_check_inversion.mod \
|
||||
dynare-command-options/ramst.mod \
|
||||
log_transform/example1.mod \
|
||||
log_transform/ramst.mod \
|
||||
|
@ -947,6 +972,14 @@ ramst_model_edit.o.trs: ramst.o.trs
|
|||
log_transform/ramst.m.trs: ramst.m.trs
|
||||
log_transform/ramst.o.trs: ramst.o.trs
|
||||
|
||||
model-inversion/nk-1/invert.m.trs: model-inversion/nk-1/simulate.m.trs
|
||||
model-inversion/nk-1/invert.o.trs: model-inversion/nk-1/simulate.o.trs
|
||||
|
||||
model-inversion/nk-2/invert.m.trs: model-inversion/nk-2/simulate.m.trs
|
||||
model-inversion/nk-2/invert.o.trs: model-inversion/nk-2/simulate.o.trs
|
||||
|
||||
model-inversion/nk-2/z_check_inversion.m.trs: model-inversion/nk-2/invert.m.trs
|
||||
model-inversion/nk-2/z_check_inversion.o.trs: model-inversion/nk-2/invert.o.trs
|
||||
|
||||
observation_trends_and_prefiltering/MCMC: m/observation_trends_and_prefiltering/MCMC o/observation_trends_and_prefiltering/MCMC
|
||||
m/observation_trends_and_prefiltering/MCMC: $(patsubst %.mod, %.m.trs, $(filter observation_trends_and_prefiltering/MCMC/%.mod, $(MODFILES)))
|
||||
|
@ -1160,6 +1193,10 @@ estimation/univariate: m/estimation/univariate o/estimation/univariate
|
|||
m/estimation/univariate: $(patsubst %.mod, %.m.trs, $(filter estimation/univariate/%.mod, $(MODFILES)))
|
||||
o/estimation/univariate: $(patsubst %.mod, %.o.trs, $(filter estimation/univariate/%.mod, $(MODFILES)))
|
||||
|
||||
particle: m/model-inversion o/model-inversion
|
||||
m/model-inversion: $(patsubst %.mod, %.m.trs, $(filter model-inversion/%.mod, $(MODFILES)))
|
||||
o/model-inversion: $(patsubst %.mod, %.o.trs, $(filter model-inversion/%.mod, $(MODFILES)))
|
||||
|
||||
# ECB files
|
||||
M_ECB_TRS_FILES = $(patsubst %.mod, %.m.trs, $(ECB_MODFILES))
|
||||
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Efficiency // $A$
|
||||
EfficiencyGrowth // $X$
|
||||
Population // $L$
|
||||
PopulationGrowth // $N$
|
||||
Output // $Y$
|
||||
PhysicalCapitalStock ; // $K$
|
||||
|
||||
varexo e_x // $\varepsilon_x$
|
||||
e_n ; // $\varepsilon_n$
|
||||
|
||||
parameters alpha // $\alpha$
|
||||
epsilon // $\varepsilon$
|
||||
delta // $\delta$
|
||||
s // $s$
|
||||
rho_x // $\rho_x$
|
||||
rho_n // $\rho_n$
|
||||
EfficiencyGrowth_ss // $X^{\star}$
|
||||
PopulationGrowth_ss ; // $N^{\star}$
|
||||
|
||||
alpha = .33;
|
||||
epsilon = .70;
|
||||
delta = .02;
|
||||
s = .20;
|
||||
rho_x = .90;
|
||||
rho_n = .95;
|
||||
EfficiencyGrowth_ss = 1.02;
|
||||
PopulationGrowth_ss = 1.02;
|
||||
|
||||
if s>delta*alpha^(-epsilon/(epsilon-1))
|
||||
disp('The model admits a unique positive steady state.')
|
||||
end
|
||||
|
||||
|
||||
model;
|
||||
Efficiency = EfficiencyGrowth*Efficiency(-1);
|
||||
EfficiencyGrowth/EfficiencyGrowth_ss = (EfficiencyGrowth(-1)/EfficiencyGrowth_ss)^(rho_x)*exp(e_x);
|
||||
Population = PopulationGrowth*Population(-1);
|
||||
PopulationGrowth/PopulationGrowth_ss = (PopulationGrowth(-1)/PopulationGrowth_ss)^(rho_n)*exp(e_n);
|
||||
Output = (alpha*PhysicalCapitalStock(-1)^((epsilon-1)/epsilon)+(1-alpha)*(Efficiency*Population)^((epsilon-1)/epsilon))^(epsilon/(epsilon-1));
|
||||
PhysicalCapitalStock = (1-delta)*PhysicalCapitalStock(-1) + s*Output;
|
||||
end;
|
||||
|
||||
histval;
|
||||
Efficiency(0) = 1;
|
||||
EfficiencyGrowth(0) = 1.02;
|
||||
Population(0) = 1;
|
||||
PopulationGrowth(0) = 1.02;
|
||||
PhysicalCapitalStock(0) = 1;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e_x = 0.005;
|
||||
var e_n = 0.001;
|
||||
end;
|
||||
|
||||
TrueData = simul_backward_nonlinear_model([], 100, options_, M_, oo_);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'Output','PhysicalCapitalStock'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries(NaN(100, 2), 1Y, {'e_x';'e_n'});
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths.Output(subsample).data-endogenousvariables.Output(subsample).data))>1e-12
|
||||
error('Constraint on Output path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths.PhysicalCapitalStock(subsample).data-endogenousvariables.PhysicalCapitalStock(subsample).data))>1e-12
|
||||
error('Constraint on PhysicalCapitalStock path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check the consistency of the deduced innovations with the true innovations.
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** In this model the two innovatons, on population growth and efficiency growth, cannot be identified simulatneously because
|
||||
** what matters for the dynamic of the physical capital stock and the output is the same non linear function of the two innovations.
|
||||
** This explains why we only check that the product of Efficiency and Population are the same in the simulated (true) data and in the
|
||||
** data returned by the inversion routine.
|
||||
*/
|
||||
|
||||
TrueEfficiency = TrueData.Efficiency;
|
||||
TruePopulation = TrueData.Population;
|
||||
|
||||
TrueEfficiencyTimesPopulation = TrueEfficiency*TruePopulation;
|
||||
EfficiencyTimesPopulation = endogenousvariables.Efficiency*endogenousvariables.Population;
|
||||
|
||||
if max(abs(TrueEfficiencyTimesPopulation(2Y:100Y).data-EfficiencyTimesPopulation(2Y:100Y).data))>1e-5
|
||||
error('Model inversion is not consitent with true innovations.')
|
||||
end
|
|
@ -0,0 +1,117 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var Efficiency // $A$
|
||||
EfficiencyGrowth // $X$
|
||||
Population // $L$
|
||||
PopulationGrowth // $N$
|
||||
Output // $Y$
|
||||
PhysicalCapitalStock ; // $K$
|
||||
|
||||
varexo e_x // $\varepsilon_x$
|
||||
e_n ; // $\varepsilon_n$
|
||||
|
||||
parameters alpha // $\alpha$
|
||||
epsilon // $\varepsilon$
|
||||
delta // $\delta$
|
||||
s // $s$
|
||||
rho_x // $\rho_x$
|
||||
rho_n // $\rho_n$
|
||||
EfficiencyGrowth_ss // $X^{\star}$
|
||||
PopulationGrowth_ss ; // $N^{\star}$
|
||||
|
||||
alpha = .33;
|
||||
epsilon = .70;
|
||||
delta = .02;
|
||||
s = .20;
|
||||
rho_x = .90;
|
||||
rho_n = .95;
|
||||
EfficiencyGrowth_ss = 1.02;
|
||||
PopulationGrowth_ss = 1.02;
|
||||
|
||||
if s>delta*alpha^(-epsilon/(epsilon-1))
|
||||
disp('The model admits a unique positive steady state.')
|
||||
end
|
||||
|
||||
|
||||
model;
|
||||
Efficiency = EfficiencyGrowth*Efficiency(-1);
|
||||
EfficiencyGrowth/EfficiencyGrowth_ss = (EfficiencyGrowth(-1)/EfficiencyGrowth_ss)^(rho_x)*exp(e_x);
|
||||
Population = PopulationGrowth*Population(-1);
|
||||
PopulationGrowth/PopulationGrowth_ss = (PopulationGrowth(-1)/PopulationGrowth_ss)^(rho_n)*exp(e_n);
|
||||
Output = (alpha*PhysicalCapitalStock(-1)^((epsilon-1)/epsilon)+(1-alpha)*(Efficiency*Population)^((epsilon-1)/epsilon))^(epsilon/(epsilon-1));
|
||||
PhysicalCapitalStock = (1-delta)*PhysicalCapitalStock(-1) + s*Output;
|
||||
end;
|
||||
|
||||
histval;
|
||||
Efficiency(0) = 1;
|
||||
EfficiencyGrowth(0) = 1.02;
|
||||
Population(0) = 1;
|
||||
PopulationGrowth(0) = 1.02;
|
||||
PhysicalCapitalStock(0) = 1;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e_x = 0.005;
|
||||
var e_n = 0.001;
|
||||
end;
|
||||
|
||||
TrueData = simul_backward_nonlinear_model([], 200, options_, M_, oo_);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'Output'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 1), TrueData.e_n.data(1:100)], 1Y, M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths.Output(subsample).data-endogenousvariables.Output(subsample).data))>1e-12
|
||||
error('Constraint on Output path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check that the solution for the PhysicalCapitalStock is consistent with the simulated data
|
||||
if max(abs(SimulatedData.PhysicalCapitalStock(2Y:100Y).data-endogenousvariables.PhysicalCapitalStock(2Y:100Y).data))>1e-9
|
||||
error('Results are not consistent with true data (Physical capital stock).')
|
||||
end
|
||||
|
||||
// Check the consistency of the deduced innovations with the true innovations.
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** In this model the two innovatons, on population growth and efficiency growth, cannot be identified simulatneously because
|
||||
** what matters for the dynamic of the physical capital stock and the output is the same non linear function of the two innovations.
|
||||
** This explains why we only check that the product of Efficiency and Population are the same in the simulated (true) data and in the
|
||||
** data returned by the inversion routine.
|
||||
*/
|
||||
|
||||
if max(abs(SimulatedData.e_x(2Y:100Y).data-exogenousvariables.e_x(2Y:100Y).data))>1e-5
|
||||
error('Model inversion is not consitent with true innovations (e_x).')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData.e_n(2Y:100Y).data-exogenousvariables.e_n(2Y:100Y).data))>1e-16
|
||||
error('Model inversion changed a calibrated innovation (e_n).')
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
|
||||
model;
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + e1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + e2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + e3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 1) TrueData{'e2','e3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + e1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + e2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + e3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);//, options_, M_, oo_);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 1) TrueData{'e2','e3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,114 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model;
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 1) TrueData{'e2','e3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,114 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 1) TrueData{'e2','e3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,136 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model;
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3) TrueData{'u1','u2','u3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,136 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3) TrueData{'u1','u2','u3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model;
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 + .1*y3(-2);
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0.1;
|
||||
y2(0) = 0.2;
|
||||
y3(0) = 0.3;
|
||||
y3(-1) = 0.4;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3) TrueData{'u1','u2','u3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 + .1*y3(-2);
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = .1;
|
||||
y2(0) = .2;
|
||||
y3(0) = .3;
|
||||
y3(-1) = .4;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3) TrueData{'u1','u2','u3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
B = [.1 -3 .5; 0 .2 -.5; 0 0 .1];
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = B(1,1);
|
||||
b12 = B(1,2);
|
||||
b13 = B(1,3);
|
||||
b22 = B(2,2);
|
||||
b23 = B(2,3);
|
||||
b33 = B(3,3);
|
||||
|
||||
model;
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = -.1;
|
||||
y2(0) = -.2;
|
||||
y3(0) = -.3;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 10Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3) TrueData{'u1','u2','u3'}.data(1:100,:)], '1Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
B = [.1 -3 .5; 0 .2 -.5; 0 0 .1];
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = B(1,1);
|
||||
b12 = B(1,2);
|
||||
b13 = B(1,3);
|
||||
b22 = B(2,2);
|
||||
b23 = B(2,3);
|
||||
b33 = B(3,3);
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 - .1*u3(-1);
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = .1;
|
||||
y2(0) = .2;
|
||||
y3(0) = .3;
|
||||
u3(0) = -.1;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 0.01;
|
||||
var e2 = 0.01;
|
||||
var e3 = 0.01;
|
||||
var u1 = 0.01;
|
||||
var u2 = 0.01;
|
||||
var u3 = 0.01;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:10Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(200, 3) TrueData{'u1','u2','u3'}.data(2:201,:)], '2Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e2)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,137 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model(linear);
|
||||
y1 = a11*y1(-1) + a12*y2(-1) + a13*y3(-1) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
y2 = a21*y1(-1) + a22*y2(-1) + a23*y3(-1) + b22*e2 + b23*e3 + u2 ;
|
||||
y3 = a31*y1(-1) + a32*y2(-1) + a33*y3(-1) + b33*e3 + u3 - .1*e1(-3);
|
||||
end;
|
||||
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
TrueData = simul_backward_model([], 200);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 10Y:100Y;
|
||||
|
||||
// Copy the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(200, 3) TrueData{'u1','u2','u3'}.data(2:201,:)], '2Y', M_.exo_names);
|
||||
exogenousvariables{'e1','e2','e3'}(2Y:10Y-1) = SimulatedData{'e1','e2','e3'}(2Y:10Y-1);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-8;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,104 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define fake_backward = 1
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
@#if fake_backward
|
||||
var z ;
|
||||
@#endif
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a b c ;
|
||||
|
||||
a = .1;
|
||||
b = .2;
|
||||
c = .3;
|
||||
|
||||
model;
|
||||
@#if fake_backward
|
||||
z = a*z(-1) ;
|
||||
@#endif
|
||||
y1 = y2*y3+exp(e1) ;
|
||||
y2 = 1 + y1*exp(e2) ;
|
||||
y3 = e3 ;
|
||||
end;
|
||||
|
||||
@#if fake_backward
|
||||
histval;
|
||||
z(0) = .0 ;
|
||||
end;
|
||||
@#endif
|
||||
|
||||
shocks;
|
||||
var e1 = .01;
|
||||
var e2 = .01;
|
||||
var e3 = .02;
|
||||
end;
|
||||
|
||||
TrueData = simul_backward_model([], 1000);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:101Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3)], '2Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3.
|
||||
**
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-9;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e2)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,115 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define linearproblem = 0
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a b c ;
|
||||
|
||||
a = .1;
|
||||
b = .2;
|
||||
c = .3;
|
||||
|
||||
model;
|
||||
|
||||
@#if linearproblem
|
||||
|
||||
y1 = .5*y2 + y3 + e1 ;
|
||||
|
||||
y2 = 1 + y1 + e2 ;
|
||||
|
||||
y3 = e3;
|
||||
|
||||
@#else
|
||||
|
||||
y1 = y2*y3+exp(e1) ;
|
||||
|
||||
y2 = 1 + y1*exp(e2) ;
|
||||
|
||||
y3 = e3 ;
|
||||
|
||||
@#endif
|
||||
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = .01;
|
||||
var e2 = .01;
|
||||
var e3 = .02;
|
||||
end;
|
||||
|
||||
TrueData = simul_static_model(1000);
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
initperiod = 501Y;
|
||||
lastperiod = 600Y;
|
||||
subsample = initperiod:lastperiod;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(100, 3)], initperiod, M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3.
|
||||
**
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-9;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, [], M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-8
|
||||
dprintf('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-8
|
||||
dprintf('Model inversion is not consistent with true innovations (e2)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-8
|
||||
dprintf('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
TrueData2 = simul_static_model(100, exogenousvariables(subsample));
|
||||
|
||||
if max(abs(TrueData2(subsample).y1.data-TrueData(subsample).y1.data))>1e-5
|
||||
error('Model inversion is wrong.')
|
||||
end
|
|
@ -0,0 +1,149 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define USE_HISTVAL = 0
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 u1 u2 u3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 b11 b12 b13 b22 b23 b33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
b11 = .10;
|
||||
b12 = -.30;
|
||||
b13 = .05;
|
||||
b22 = .20;
|
||||
b23 = -.05;
|
||||
b33 = .10;
|
||||
|
||||
model(linear);
|
||||
diff(y1) = a11*diff(y1(-1)) + a12*diff(y2(-1)) + a13*diff(y3(-1)) + b11*e1 + b12*e2 + b13*e3 + u1 ;
|
||||
diff(y2) = a21*diff(y1(-1)) + a22*diff(y2(-1)) + a23*diff(y3(-1)) + b22*e2 + b23*e3 + u2 ;
|
||||
diff(y3) = a31*diff(y1(-1)) + a32*diff(y2(-1)) + a33*diff(y3(-1)) + b33*e3 + u3 ;
|
||||
end;
|
||||
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
var u1 = .1;
|
||||
var u2 = .3;
|
||||
var u3 = .2;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
@#if USE_HISTVAL
|
||||
histval;
|
||||
y1(0) = .1;
|
||||
y2(0) = .2;
|
||||
y3(0) = .3;
|
||||
y1(-1) = -.1;
|
||||
y2(-1) = -.2;
|
||||
y3(-1) = -.3;
|
||||
end;
|
||||
TrueData = simul_backward_model([], 200);
|
||||
@#else
|
||||
initdata = zeros(2, 3+3+3);
|
||||
initdata(1,1:3) = [-.1 -.2 -.3];
|
||||
initdata(2,1:3) = [.1 .2 .3];
|
||||
initialconditions = dseries(initdata, '1Y', vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names));
|
||||
TrueData = simul_backward_model(initialconditions, 200);
|
||||
@#endif
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1','y2','y3'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(98, 3) TrueData{'u1','u2','u3'}.data(3:100,:)], '3Y', M_.exo_names);
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** Here we will control y1, y2, and y3 with e1, e2 and e3, u1, u2 and u3 are treated as observed
|
||||
** exogenous variables.
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
options_.dynatol.f = 1e-9;
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Constraint on y2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(constrainedpaths(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Constraint on y3 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u1.data-SimulatedData(subsample).u1.data))>1e-12
|
||||
error('Constraint on u1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u2.data-SimulatedData(subsample).u2.data))>1e-12
|
||||
error('Constraint on u2 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).u3.data-SimulatedData(subsample).u3.data))>1e-12
|
||||
error('Constraint on u3 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e1)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-8
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,72 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define USE_HISTVAL = 0
|
||||
|
||||
var y ;
|
||||
|
||||
varexo e ;
|
||||
|
||||
parameters rho ;
|
||||
|
||||
rho = 1.0;
|
||||
|
||||
model(linear);
|
||||
diff(y) = e ;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
innovations = dseries(ones(200,1), 3Y, 'e');
|
||||
|
||||
@#if USE_HISTVAL
|
||||
histval;
|
||||
y(-1) = 0.0;
|
||||
y(0) = 1.0;
|
||||
end;
|
||||
TrueData = simul_backward_model([], 200, innovations);
|
||||
@#else
|
||||
initdata = zeros(2, 2);
|
||||
initdata(1,1) = 0.0;
|
||||
initdata(2,1) = 1.0;
|
||||
initialconditions = dseries(initdata, 1Y, vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names));
|
||||
TrueData = simul_backward_model(initialconditions, 200, innovations);
|
||||
@#endif
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries(NaN(98, 1), 3Y, M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
assert(all(exogenousvariables.e.data==1), 'Inversion is wrong!');
|
|
@ -0,0 +1,78 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define USE_HISTVAL = 0
|
||||
|
||||
var y ;
|
||||
|
||||
varexo e ;
|
||||
|
||||
parameters rho ;
|
||||
|
||||
rho = 1.0;
|
||||
|
||||
model(linear);
|
||||
diff(y) = rho*diff(y(-1)) + e ;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
innovations = dseries(ones(200,1), 3Y, 'e');
|
||||
|
||||
@#if USE_HISTVAL
|
||||
histval;
|
||||
y(-1) = 0.0;
|
||||
y(0) = 1.0;
|
||||
end;
|
||||
TrueData = simul_backward_model([], 200, innovations);
|
||||
@#else
|
||||
initdata = zeros(2, 2);
|
||||
initdata(1,1) = 0.0;
|
||||
initdata(2,1) = 1.0;
|
||||
initialconditions = dseries(initdata, 1Y, vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names));
|
||||
TrueData = simul_backward_model(initialconditions, 200, innovations);
|
||||
@#endif
|
||||
|
||||
y0 = TrueData(2Y).y.data;
|
||||
yts = TrueData(3Y:10Y).y.data;
|
||||
yex = 1+cumsum(y0+cumsum(ones(8,1)));
|
||||
|
||||
assert(~any(yts-yex), 'Simulation is wrong!')
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries(NaN(98, 1), 3Y, M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
assert(all(exogenousvariables.e.data==1), 'Inversion is wrong!');
|
|
@ -0,0 +1,117 @@
|
|||
// --+ options: stochastic +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define USE_HISTVAL = 0
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
|
||||
model(linear);
|
||||
diff(y1) = a11*diff(y1(-1)) + a12*diff(y2(-1)) + a13*diff(y3(-1)) + e1 ;
|
||||
diff(y2) = a21*diff(y1(-1)) + a22*diff(y2(-1)) + a23*diff(y3(-1)) + e2 ;
|
||||
diff(y3) = a31*diff(y1(-1)) + a32*diff(y2(-1)) + a33*diff(y3(-1)) + e3 ;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
@#if USE_HISTVAL
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
y1(-1) = 0;
|
||||
y2(-1) = 0;
|
||||
y3(-1) = 0;
|
||||
end;
|
||||
TrueData = simul_backward_model([], 200);
|
||||
@#else
|
||||
initialconditions = dseries(zeros(2,6), 1Y, vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names));
|
||||
TrueData = simul_backward_model(initialconditions, 200);
|
||||
@#endif
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 3Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(98, 1) TrueData{'e2','e3'}.data(3:100,:)], 3Y, M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,118 @@
|
|||
// --+ options: stochastic, json=compute +--
|
||||
|
||||
/* © 2022 Dynare Team
|
||||
*
|
||||
* This file is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* It is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the file. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
@#define USE_HISTVAL = 0
|
||||
|
||||
var y1 y2 y3 ;
|
||||
|
||||
varexo e1 e2 e3 ;
|
||||
|
||||
parameters a11 a12 a13 a21 a22 a23 a31 a32 a33 ;
|
||||
|
||||
/*
|
||||
** Simulate the elements of the first order autoregressive matrix (we impose stability of the model, note that
|
||||
** inversion fails if the model is explosive, ie the autoregressive matrix has at least one root greater than
|
||||
** one in modulus) probably because of the propagation of roundoff errors.
|
||||
*/
|
||||
|
||||
D = diag([.9 .7 .8]);
|
||||
P = randn(3,3);
|
||||
A = P*D*inv(P);
|
||||
|
||||
a11 = A(1,1);
|
||||
a12 = A(1,2);
|
||||
a13 = A(1,3);
|
||||
a21 = A(2,1);
|
||||
a22 = A(2,2);
|
||||
a23 = A(2,3);
|
||||
a31 = A(3,1);
|
||||
a32 = A(3,2);
|
||||
a33 = A(3,3);
|
||||
|
||||
model(linear);
|
||||
diff(y1) = a11*diff(y1(-1)) + a12*diff(y2(-1)) + a13*diff(y3(-1)) + .01*diff(y1(-2)) + e1 ;
|
||||
diff(y2) = a21*diff(y1(-1)) + a22*diff(y2(-1)) + a23*diff(y3(-1)) - .01*diff(y1(-2)) + e2 ;
|
||||
diff(y3) = a31*diff(y1(-1)) + a32*diff(y2(-1)) + a33*diff(y3(-1)) + .02*diff(y1(-2)) + e3 ;
|
||||
end;
|
||||
|
||||
shocks;
|
||||
var e1 = 1.0;
|
||||
var e2 = 1.0;
|
||||
var e3 = 1.0;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
@#if USE_HISTVAL
|
||||
histval;
|
||||
y1(0) = 0;
|
||||
y2(0) = 0;
|
||||
y3(0) = 0;
|
||||
y1(-1) = 0;
|
||||
y2(-1) = 0;
|
||||
y3(-1) = 0;
|
||||
y1(-2) = 0
|
||||
end;
|
||||
TrueData = simul_backward_model([], 200);
|
||||
@#else
|
||||
initialconditions = dseries(zeros(3,6), 1Y, vertcat(M_.endo_names(1:M_.orig_endo_nbr), M_.exo_names));
|
||||
TrueData = simul_backward_model(initialconditions, 200);
|
||||
@#endif
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 4Y:100Y;
|
||||
|
||||
// Load the generated data
|
||||
SimulatedData = copy(TrueData);
|
||||
|
||||
// Set the constrained paths for the endogenous variables (Output and PhysicalCapitalStock).
|
||||
constrainedpaths = SimulatedData{'y1'}(subsample);
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries([NaN(97, 1) TrueData{'e2','e3'}.data(4:100,:)], 4Y, M_.exo_names);
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
if max(abs(constrainedpaths(subsample).y1.data-endogenousvariables(subsample).y1.data))>1e-12
|
||||
error('Constraint on y1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e2.data-SimulatedData(subsample).e2.data))>1e-12
|
||||
error('Constraint on e1 path is not satisfied!')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e3.data-SimulatedData(subsample).e3.data))>1e-12
|
||||
error('Constraint on e2 path is not satisfied!')
|
||||
end
|
||||
|
||||
// Check consistency of the results.
|
||||
if max(abs(SimulatedData(subsample).y2.data-endogenousvariables(subsample).y2.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y2')
|
||||
end
|
||||
|
||||
if max(abs(SimulatedData(subsample).y3.data-endogenousvariables(subsample).y3.data))>1e-12
|
||||
error('Model inversion is not consistent with respect to y3')
|
||||
end
|
||||
|
||||
if max(abs(exogenousvariables(subsample).e1.data-SimulatedData(subsample).e1.data))>1e-12
|
||||
error('Model inversion is not consistent with true innovations (e3)')
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
var y pi i;
|
||||
|
||||
varexo e_y e_pi e_i;
|
||||
|
||||
parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
|
||||
|
||||
a1 = .2;
|
||||
a2 = .8;
|
||||
a3 = .05;
|
||||
|
||||
b1 = .3;
|
||||
b2 = .7;
|
||||
b3 = .1;
|
||||
|
||||
c1 = 0.9;
|
||||
c2 = 1.5;
|
||||
c3 = 0.5;
|
||||
|
||||
model(bytecode);
|
||||
y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
|
||||
pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
|
||||
i = c1*i(-1) + c2*pi(1) + c3*y + e_i ;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
shocks;
|
||||
var e_y = 0.002;
|
||||
var e_pi = 0.004;
|
||||
var e_i = 0.001;
|
||||
end;
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Load all the data generated by simulate.mod
|
||||
SimulatedData = dseries('truedata.mat');
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'y','pi','i'}(subsample);
|
||||
|
||||
/* REMARKS
|
||||
**
|
||||
** In this example we constrain all the endogenous variables from 2Y to 100Y to match the same variables as given by simulated.mod.
|
||||
** When we invert the model, we search the sequence of innovations that leads to these realizations of the endogenous variables. If
|
||||
** the model is the same, the sequence of innovations returned by the inversion routine has to match the true sequence of shocks (used
|
||||
** in simulated.mod and available for reference in SimulatedData dseries object). In this example, we invert the model with a slightly
|
||||
** different model by removing the max operator in the Taylor rule. Because of this difference, the innovations returned by the inversion
|
||||
** 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
|
||||
** 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
|
||||
** value of e_i, compared to the true value, to keep the economy on the ZLB).
|
||||
**
|
||||
*/
|
||||
|
||||
// Set the instruments (innovations used to control the paths for the endogenous variables).
|
||||
exogenousvariables = dseries(NaN(99, 3), 2Y, {'e_y';'e_pi';'e_i'});
|
||||
|
||||
/* REMARKS
|
||||
**
|
||||
** We need as many instruments as contrained endogenous variables. There is no association of these innovations with the constrained
|
||||
** endogenous variables. The instruments are identified by a NaN value for the exogenous variables. In this example all the exogenous
|
||||
** variables are used as instruments.
|
||||
**
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
/* REMARKS
|
||||
**
|
||||
** Output arguments endogenousvariables and exogenousvariables are dseries objects.
|
||||
**
|
||||
** In this example we constrain all the endogenous variables, so the variables in the first output argument matches exactly the
|
||||
** constraints given in inputs. If we constrained only a subset of the variables we would have more variables in the first output
|
||||
** argument than in the first input argument (constrainedpaths). Obviously the additional endogenous variables, ie the unconstrained
|
||||
** endogenous variables, depend on the constraints given in the first input argument. The second output argument contains the
|
||||
** exogenous variables consistent with the constraints defined in the first input argument. In this example, we have as many shocks for
|
||||
** controlling the endogenous variables than shocks in the model.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
// Check that all the constraints are satisfied.
|
||||
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
|
||||
error('Constrained on endogenous variable paths are not all satisfied!')
|
||||
end
|
||||
|
||||
// Plot the differences on e_y (shock in the Euler equation)
|
||||
figure(1)
|
||||
plot(exogenousvariables.e_y-SimulatedData.e_y) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_y')
|
||||
|
||||
// Plot the differences on e_pi (shock in the Phillips curve)
|
||||
figure(2)
|
||||
plot(exogenousvariables.e_pi-SimulatedData.e_pi) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_pi')
|
||||
|
||||
// Plot the differences on e_ik (shock in the Taylor rule)
|
||||
// The red bullets correpond the ZLB episodes.
|
||||
figure(3)
|
||||
plot(exogenousvariables.e_i-SimulatedData.e_i) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_i')
|
||||
hold on
|
||||
id = find(endogenousvariables.i.data==-.05);
|
||||
plot(id, zeros(1,length(id)), 'or')
|
||||
hold off
|
|
@ -0,0 +1,41 @@
|
|||
var y pi i;
|
||||
|
||||
varexo e_y e_pi e_i;
|
||||
|
||||
parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
|
||||
|
||||
a1 = .2;
|
||||
a2 = .8;
|
||||
a3 = .05;
|
||||
|
||||
b1 = .3;
|
||||
b2 = .7;
|
||||
b3 = .1;
|
||||
|
||||
c1 = 0.9;
|
||||
c2 = 1.5;
|
||||
c3 = 0.5;
|
||||
|
||||
model;
|
||||
y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
|
||||
pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
|
||||
i = max(c1*i(-1) + c2*pi(1) + c3*y + e_i, -.05) ;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
shocks;
|
||||
var e_y = 0.002;
|
||||
var e_pi = 0.004;
|
||||
var e_i = 0.001;
|
||||
end;
|
||||
|
||||
extended_path(periods=200);
|
||||
|
||||
verbatim;
|
||||
data = [Simulated_time_series dseries(oo_.exo_simul, '2Y', {'e_y', 'e_pi', 'e_i'})];
|
||||
save(data,'truedata', 'mat');
|
||||
end;
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
var y pi i;
|
||||
|
||||
varexo e_y e_pi e_i;
|
||||
|
||||
parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
|
||||
|
||||
a1 = .2;
|
||||
a2 = .8;
|
||||
a3 = .05;
|
||||
|
||||
b1 = .3;
|
||||
b2 = .7;
|
||||
b3 = .1;
|
||||
|
||||
c1 = 0.9;
|
||||
c2 = 1.5;
|
||||
c3 = 0.5;
|
||||
|
||||
model(bytecode);
|
||||
y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
|
||||
pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
|
||||
i = c1*i(-1) + c2*pi(1) + c3*y + e_i ;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
shocks;
|
||||
var e_y = 0.002;
|
||||
var e_pi = 0.004;
|
||||
var e_i = 0.001;
|
||||
end;
|
||||
|
||||
// Set the periods where some of the endogenous variables will be constrained.
|
||||
subsample = 2Y:100Y;
|
||||
|
||||
// Load all the data generated by simulate.mod
|
||||
SimulatedData = dseries('truedata.mat');
|
||||
|
||||
// Set the constrained paths for the endogenous variables.
|
||||
constrainedpaths = SimulatedData{'i'}(subsample);
|
||||
|
||||
/* REMARKS
|
||||
**
|
||||
** In this example we constrain only the nominal interest rate from 2Y to 100Y to match the same variable as given by simulated.mod.
|
||||
** When we invert the model, we search the sequence of innovations e_i that leads to these realizations of the nominal interest rate. If
|
||||
** the model is the same, the sequence of innovations returned by the inversion routine has to match the true sequence of shocks (used
|
||||
** in simulated.mod and available for reference in SimulatedData dseries object). In this example, we invert the model with a slightly
|
||||
** different model by removing the max operator in the Taylor rule. Because of this difference, the innovations returned by the inversion
|
||||
** routine are not equal to the true innovations.
|
||||
**
|
||||
*/
|
||||
|
||||
// Set the instruments (innovations used to control the nominal interest rate).
|
||||
exodata = SimulatedData{'e_y', 'e_pi', 'e_i'}.data;
|
||||
exodata(2:100,3) = NaN;
|
||||
exogenousvariables = dseries(exodata, 1Y, {'e_y';'e_pi';'e_i'});
|
||||
|
||||
/* REMARK
|
||||
**
|
||||
** We need as many instruments as contrained endogenous variables. In this case we control the nominal interest rate path with the shock
|
||||
** 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
|
||||
** exogenous variables.
|
||||
**
|
||||
*/
|
||||
|
||||
// Invert the model by calling the model_inversion routine.
|
||||
[endogenousvariables, exogenousvariables] = model_inversion(constrainedpaths, exogenousvariables, SimulatedData, M_, options_, oo_);
|
||||
|
||||
// Check the path for the nominal interest rate
|
||||
if max(abs(endogenousvariables.i(subsample).data-SimulatedData.i(subsample).data))>1e-6
|
||||
error('Constrained on endogenous variable paths are not all satisfied!')
|
||||
end
|
||||
|
||||
// Save the simulations on disk.
|
||||
endogenousvariables.save('endogenousvariables', 'mat');
|
||||
exogenousvariables.save('exogenousvariables', 'mat');
|
||||
|
||||
// Plot the differences on e_y (shock in the Euler equation)
|
||||
figure(1)
|
||||
plot(exogenousvariables.e_y-SimulatedData.e_y) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_y')
|
||||
|
||||
// Plot the differences on e_pi (shock in the Phillips curve)
|
||||
figure(2)
|
||||
plot(exogenousvariables.e_pi-SimulatedData.e_pi) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_pi')
|
||||
|
||||
// Plot the differences on e_ik (shock in the Taylor rule)
|
||||
figure(3)
|
||||
plot(exogenousvariables.e_i-SimulatedData.e_i) % Not zero because of the misspecification related to the ZLB
|
||||
title('e_i')
|
||||
hold on
|
||||
id = find(endogenousvariables.i.data==-.05);
|
||||
plot(id, zeros(1,length(id)), 'or')
|
||||
hold off
|
||||
|
||||
figure(4)
|
||||
plot(endogenousvariables.i,'-k','linewidth',2)
|
||||
hold on
|
||||
plot(SimulatedData.i(1Y:100Y),'--r','linewidth',2)
|
||||
hold off
|
||||
title('Nominal interest rate')
|
||||
|
||||
figure(5)
|
||||
plot(endogenousvariables.y,'-k','linewidth',2)
|
||||
hold on
|
||||
plot(SimulatedData.y(1Y:100Y),'--r','linewidth',2)
|
||||
hold off
|
||||
title('Output gap')
|
||||
|
||||
figure(6)
|
||||
plot(endogenousvariables.pi,'-k','linewidth',2)
|
||||
hold on
|
||||
plot(SimulatedData.pi(1Y:100Y),'--r','linewidth',2)
|
||||
hold off
|
||||
title('Inflation gap')
|
|
@ -0,0 +1,41 @@
|
|||
var y pi i;
|
||||
|
||||
varexo e_y e_pi e_i;
|
||||
|
||||
parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
|
||||
|
||||
a1 = .2;
|
||||
a2 = .8;
|
||||
a3 = .05;
|
||||
|
||||
b1 = .3;
|
||||
b2 = .7;
|
||||
b3 = .1;
|
||||
|
||||
c1 = 0.9;
|
||||
c2 = 1.5;
|
||||
c3 = 0.5;
|
||||
|
||||
model;
|
||||
y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
|
||||
pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
|
||||
i = max(c1*i(-1) + c2*pi(1) + c3*y + e_i, -.05) ;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
shocks;
|
||||
var e_y = 0.002;
|
||||
var e_pi = 0.004;
|
||||
var e_i = 0.001;
|
||||
end;
|
||||
|
||||
extended_path(periods=200);
|
||||
|
||||
verbatim;
|
||||
data = [Simulated_time_series dseries(oo_.exo_simul, '2Y', {'e_y', 'e_pi', 'e_i'})];
|
||||
save(data,'truedata', 'mat');
|
||||
end;
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
var y pi i;
|
||||
|
||||
varexo e_y e_pi e_i;
|
||||
|
||||
parameters a1 a2 a3 b1 b2 b3 c1 c2 c3;
|
||||
|
||||
a1 = .2;
|
||||
a2 = .8;
|
||||
a3 = .05;
|
||||
|
||||
b1 = .3;
|
||||
b2 = .7;
|
||||
b3 = .1;
|
||||
|
||||
c1 = 0.9;
|
||||
c2 = 1.5;
|
||||
c3 = 0.5;
|
||||
|
||||
model;
|
||||
y = a1*y(-1) + a2*y(1) - a3*(i-pi(1)) + e_y ;
|
||||
pi = b1*pi(-1) + b2*pi(1) + b3*y + e_pi ;
|
||||
i = c1*i(-1) + c2*pi(1) + c3*y + e_i ;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
check;
|
||||
|
||||
shocks;
|
||||
var e_y = 0.002;
|
||||
var e_pi = 0.004;
|
||||
var e_i = 0.001;
|
||||
end;
|
||||
|
||||
dse = dseries('endogenousvariables.mat');
|
||||
dsx = dseries('exogenousvariables.mat');
|
||||
dsx = [dsx.e_y, dsx.e_pi, dsx.e_i];
|
||||
|
||||
// Check that the returned paths for the endogenous variables are correct.
|
||||
[ts, oo_] = extended_path(zeros(3, 1), 99, dsx.data(2:100,:), options_, M_, oo_);
|
||||
|
||||
assert(max(abs(dse(1Y:10Y).y.data-ts(1Y:10Y).y.data))<1e-5,'nk-2 inversion is wrong (y).')
|
||||
assert(max(abs(dse(1Y:10Y).pi.data-ts(1Y:10Y).pi.data))<1e-5,'nk-2 inversion is wrong (pi).')
|
||||
assert(max(abs(dse(1Y:10Y).i.data-ts(1Y:10Y).i.data))<1e-5,'nk-2 inversion is wrong (i).')
|
Loading…
Reference in New Issue