Debian Codegraph @

tests/estimation/method_of_moments/AFVRR/AFVRR_MFB.mod

raw
1 % DSGE model based on replication files of
2 % Andreasen, Fernandez-Villaverde, Rubio-Ramirez (2018), The Pruned State-Space System for Non-Linear DSGE Models: Theory and Empirical Applications, Review of Economic Studies, 85, p. 1-49
3 % Adapted for Dynare by Willi Mutschler (@wmutschl, [email protected]), Jan 2021
4 % =========================================================================
5 % Copyright © 2021-2023 Dynare Team
6 %
7 % This file is part of Dynare.
8 %
9 % Dynare is free software: you can redistribute it and/or modify
10 % it under the terms of the GNU General Public License as published by
11 % the Free Software Foundation, either version 3 of the License, or
12 % (at your option) any later version.
13 %
14 % Dynare is distributed in the hope that it will be useful,
15 % but WITHOUT ANY WARRANTY; without even the implied warranty of
16 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 % GNU General Public License for more details.
18 %
19 % You should have received a copy of the GNU General Public License
20 % along with Dynare. If not, see <https://www.gnu.org/licenses/>.
21 % =========================================================================
22
23 % This is the model with Feedback M_FB
24 % Original code RunGMM_Feedback_estim_RRA.m by Martin M. Andreasen, Jan 2016
25
26 @#include "AFVRR_common.inc"
27
28 %--------------------------------------------------------------------------
29 % Parameter calibration taken from RunGMM_Feedback_estim_RRA.m
30 %--------------------------------------------------------------------------
31 % fixed parameters
32 INHABIT = 1;
33 PHI1 = 4;
34 PHI4 = 1;
35 KAPAone = 0;
36 DELTA = 0.025;
37 THETA = 0.36;
38 ETA = 6;
39 CHI = 0;
40 BETTAxhr = 0;
41 BETTAxhr40= 0;
42 RHOD = 0;
43 GAMA = 0.9999;
44 CONSxhr20 = 0;
45
46 % estimated parameters
47 BETTA = 0.997007023687000;
48 B = 0.692501768577000;
49 H = 0.339214495653000;
50 PHI2 = 0.688555040951000;
51 RRA = 24.346514272871001;
52 KAPAtwo = 10.018421876923000;
53 ALFA = 0.792507553312000;
54 RHOR = 0.849194030384000;
55 BETTAPAI = 2.060579322980000;
56 BETTAY = 0.220573712342000;
57 MYYPS = 1.001016690133000;
58 MYZ = 1.005356313981000;
59 RHOA = 0.784141391843000;
60 RHOG = 0.816924540497000;
61 PAI = 1.011924196487000;
62 CONSxhr40 = 0.878774662208000;
63 GoY = 0.207110300602000;
64 STDA = 0.013024450606000;
65 STDG = 0.051049871928000;
66 STDD = 0.008877423780000;
67
68 % endogenous parameters set via steady state, no need to initialize
69 %PHIzero = ;
70 %AA = ;
71 %PHI3 = ;
72 %negVf = ;
73
74 model_diagnostics;
75 % Model diagnostics show that some parameters are endogenously determined
76 % via the steady state, so we run steady to calibrate all parameters
77 steady;
78 model_diagnostics;
79 % Now all parameters are determined
80
81 resid;
82 check;
83
84 %--------------------------------------------------------------------------
85 % Shock distribution
86 %--------------------------------------------------------------------------
87 shocks;
88 var eps_a = STDA^2;
89 var eps_d = STDD^2;
90 var eps_g = STDG^2;
91 end;
92
93 %--------------------------------------------------------------------------
94 % Estimated Params block - these parameters will be estimated, we
95 % initialize at calibrated values
96 %--------------------------------------------------------------------------
97 estimated_params;
98 BETTA;
99 B;
100 H;
101 PHI2;
102 RRA;
103 KAPAtwo;
104 ALFA;
105 RHOR;
106 BETTAPAI;
107 BETTAY;
108 MYYPS;
109 MYZ;
110 RHOA;
111 RHOG;
112 PAI;
113 CONSxhr40;
114 GoY;
115 stderr eps_a;
116 stderr eps_g;
117 stderr eps_d;
118 end;
119
120 estimated_params_init(use_calibration);
121 end;
122
123 %--------------------------------------------------------------------------
124 % Compare whether toolbox yields equivalent moments at second order
125 %--------------------------------------------------------------------------
126 % Note that we compare results for orderApp=1|2 and not for orderApp=3, because
127 % there is a small error in the replication files of the original article in the
128 % computation of the covariance matrix of the extended innovations vector.
129 % The authors have been contacted, fixed it, and report that the results
130 % change only slightly at orderApp=3 to what they report in the paper. At
131 % orderApp=2 all is correct and so the following part tests whether we get
132 % the same model moments at the calibrated parameters (we do not optimize).
133 % We compare it to the replication file RunGMM_Feedback_estim_RRA.m with the
134 % following settings: orderApp=1|2, seOn=0, q_lag=10, weighting=1;
135 % scaled=0; optimizer=0; estimator=1; momentSet=2;
136 %
137 % Output of the replication files for orderApp=1
138 AndreasenEtAl.Q1 = 201778.9697;
139 AndreasenEtAl.moments1 =[ % note that we reshuffeled to be compatible with our matched moments block
140 {[ 1]} {'Ex' } {'Gr_C '} {' ' } {'0.024388' } {'0.023654' }
141 {[ 2]} {'Ex' } {'Gr_I '} {' ' } {'0.031046' } {'0.027719' }
142 {[ 3]} {'Ex' } {'Infl ' } {' ' } {'0.03757' } {'0.047415' }
143 {[ 4]} {'Ex' } {'r1 ' } {' ' } {'0.056048' } {'0.083059' }
144 {[ 5]} {'Ex' } {'r40 ' } {' ' } {'0.069929' } {'0.083059' }
145 {[ 6]} {'Ex' } {'xhr40 '} {' ' } {'0.017237' } {'0' }
146 {[ 7]} {'Ex' } {'GoY '} {' ' } {'-1.5745' } {'-1.5745' }
147 {[ 8]} {'Ex' } {'hours '} {' ' } {'-0.043353' } {'-0.043245' }
148 {[ 9]} {'Exx' } {'Gr_C '} {'Gr_C '} {'0.0013159' } {'0.0012253' }
149 {[10]} {'Exx' } {'Gr_C '} {'Gr_I '} {'0.0021789' } {'0.0015117' }
150 {[11]} {'Exx' } {'Gr_C '} {'Infl ' } {'0.00067495' } {'0.00080078' }
151 {[12]} {'Exx' } {'Gr_C '} {'r1 ' } {'0.0011655' } {'0.00182' }
152 {[13]} {'Exx' } {'Gr_C '} {'r40 ' } {'0.0015906' } {'0.001913' }
153 {[14]} {'Exx' } {'Gr_C '} {'xhr40 '} {'0.0020911' } {'0.0016326' }
154 {[15]} {'Exx' } {'Gr_I '} {'Gr_I '} {'0.0089104' } {'0.0040112' }
155 {[16]} {'Exx' } {'Gr_I '} {'Infl ' } {'0.00063139' } {'0.00060604' }
156 {[17]} {'Exx' } {'Gr_I '} {'r1 ' } {'0.0011031' } {'0.0021426' }
157 {[18]} {'Exx' } {'Gr_I '} {'r40 ' } {'0.0018445' } {'0.0022348' }
158 {[19]} {'Exx' } {'Gr_I '} {'xhr40 '} {'0.00095556' } {'0.0039852' }
159 {[20]} {'Exx' } {'Infl ' } {'Infl ' } {'0.0020268' } {'0.0030058' }
160 {[21]} {'Exx' } {'Infl ' } {'r1 ' } {'0.0025263' } {'0.0044951' }
161 {[22]} {'Exx' } {'Infl ' } {'r40 ' } {'0.0029126' } {'0.0042225' }
162 {[23]} {'Exx' } {'Infl ' } {'xhr40 '} {'-0.00077101'} {'-0.0021222' }
163 {[24]} {'Exx' } {'r1 ' } {'r1 ' } {'0.0038708' } {'0.0074776' }
164 {[25]} {'Exx' } {'r1 ' } {'r40 ' } {'0.0044773' } {'0.0071906' }
165 {[26]} {'Exx' } {'r1 ' } {'xhr40 '} {'-0.00048202'} {'-0.0006736' }
166 {[27]} {'Exx' } {'r40 ' } {'r40 ' } {'0.0054664' } {'0.0070599' }
167 {[28]} {'Exx' } {'r40 ' } {'xhr40 '} {'0.00053864' } {'-0.00036735'}
168 {[29]} {'Exx' } {'xhr40 '} {'xhr40 '} {'0.053097' } {'0.014516' }
169 {[30]} {'Exx' } {'GoY '} {'GoY '} {'2.4863' } {'2.4866' }
170 {[31]} {'Exx' } {'hours '} {'hours '} {'0.0018799' } {'0.0018713' }
171 {[32]} {'Exx1'} {'Gr_C '} {'Gr_C '} {'0.00077917' } {'0.00076856' }
172 {[33]} {'Exx1'} {'Gr_I '} {'Gr_I '} {'0.0050104' } {'0.002163' }
173 {[34]} {'Exx1'} {'Infl ' } {'Infl ' } {'0.0019503' } {'0.0028078' }
174 {[35]} {'Exx1'} {'r1 ' } {'r1 ' } {'0.0038509' } {'0.0074583' }
175 {[36]} {'Exx1'} {'r40 ' } {'r40 ' } {'0.0054699' } {'0.0070551' }
176 {[37]} {'Exx1'} {'xhr40 '} {'xhr40 '} {'-0.00098295'} {'7.2164e-16' }
177 {[38]} {'Exx1'} {'GoY '} {'GoY '} {'2.4868' } {'2.4856' }
178 {[39]} {'Exx1'} {'hours '} {'hours '} {'0.0018799' } {'0.0018708' }
179 ];
180
181 % Output of the replication files for orderApp=2
182 AndreasenEtAl.Q2 = 59.3323;
183 AndreasenEtAl.moments2 =[ % note that we reshuffeled to be compatible with our matched moments block
184 {[ 1]} {'Ex' } {'Gr_C '} {' ' } {'0.024388' } {'0.023654' }
185 {[ 2]} {'Ex' } {'Gr_I '} {' ' } {'0.031046' } {'0.027719' }
186 {[ 3]} {'Ex' } {'Infl ' } {' ' } {'0.03757' } {'0.034565' }
187 {[ 4]} {'Ex' } {'r1 ' } {' ' } {'0.056048' } {'0.056419' }
188 {[ 5]} {'Ex' } {'r40 ' } {' ' } {'0.069929' } {'0.07087' }
189 {[ 6]} {'Ex' } {'xhr40 '} {' ' } {'0.017237' } {'0.01517' }
190 {[ 7]} {'Ex' } {'GoY '} {' ' } {'-1.5745' } {'-1.5743' }
191 {[ 8]} {'Ex' } {'hours '} {' ' } {'-0.043353' } {'-0.043352' }
192 {[ 9]} {'Exx' } {'Gr_C '} {'Gr_C '} {'0.0013159' } {'0.0012464' }
193 {[10]} {'Exx' } {'Gr_C '} {'Gr_I '} {'0.0021789' } {'0.0015247' }
194 {[11]} {'Exx' } {'Gr_C '} {'Infl ' } {'0.00067495' } {'0.0004867' }
195 {[12]} {'Exx' } {'Gr_C '} {'r1 ' } {'0.0011655' } {'0.0011867' }
196 {[13]} {'Exx' } {'Gr_C '} {'r40 ' } {'0.0015906' } {'0.0016146' }
197 {[14]} {'Exx' } {'Gr_C '} {'xhr40 '} {'0.0020911' } {'0.0021395' }
198 {[15]} {'Exx' } {'Gr_I '} {'Gr_I '} {'0.0089104' } {'0.0043272' }
199 {[16]} {'Exx' } {'Gr_I '} {'Infl ' } {'0.00063139' } {'0.00021752'}
200 {[17]} {'Exx' } {'Gr_I '} {'r1 ' } {'0.0011031' } {'0.0013919' }
201 {[18]} {'Exx' } {'Gr_I '} {'r40 ' } {'0.0018445' } {'0.0018899' }
202 {[19]} {'Exx' } {'Gr_I '} {'xhr40 '} {'0.00095556' } {'0.0037854' }
203 {[20]} {'Exx' } {'Infl ' } {'Infl ' } {'0.0020268' } {'0.0021043' }
204 {[21]} {'Exx' } {'Infl ' } {'r1 ' } {'0.0025263' } {'0.0026571' }
205 {[22]} {'Exx' } {'Infl ' } {'r40 ' } {'0.0029126' } {'0.0028566' }
206 {[23]} {'Exx' } {'Infl ' } {'xhr40 '} {'-0.00077101'} {'-0.0016279'}
207 {[24]} {'Exx' } {'r1 ' } {'r1 ' } {'0.0038708' } {'0.0039136' }
208 {[25]} {'Exx' } {'r1 ' } {'r40 ' } {'0.0044773' } {'0.0044118' }
209 {[26]} {'Exx' } {'r1 ' } {'xhr40 '} {'-0.00048202'} {'0.00016791'}
210 {[27]} {'Exx' } {'r40 ' } {'r40 ' } {'0.0054664' } {'0.0052851' }
211 {[28]} {'Exx' } {'r40 ' } {'xhr40 '} {'0.00053864' } {'0.00062143'}
212 {[29]} {'Exx' } {'xhr40 '} {'xhr40 '} {'0.053097' } {'0.018126' }
213 {[30]} {'Exx' } {'GoY '} {'GoY '} {'2.4863' } {'2.4863' }
214 {[31]} {'Exx' } {'hours '} {'hours '} {'0.0018799' } {'0.0018806' }
215 {[32]} {'Exx1'} {'Gr_C '} {'Gr_C '} {'0.00077917' } {'0.00078586'}
216 {[33]} {'Exx1'} {'Gr_I '} {'Gr_I '} {'0.0050104' } {'0.0021519' }
217 {[34]} {'Exx1'} {'Infl ' } {'Infl ' } {'0.0019503' } {'0.0019046' }
218 {[35]} {'Exx1'} {'r1 ' } {'r1 ' } {'0.0038509' } {'0.0038939' }
219 {[36]} {'Exx1'} {'r40 ' } {'r40 ' } {'0.0054699' } {'0.0052792' }
220 {[37]} {'Exx1'} {'xhr40 '} {'xhr40 '} {'-0.00098295'} {'0.00023012'}
221 {[38]} {'Exx1'} {'GoY '} {'GoY '} {'2.4868' } {'2.4852' }
222 {[39]} {'Exx1'} {'hours '} {'hours '} {'0.0018799' } {'0.0018801' }
223 ];
224
225 @#for orderApp in 1:2
226
227 method_of_moments(
228 mom_method = GMM % method of moments method; possible values: GMM|SMM
229 , datafile = 'AFVRR_data.mat' % name of filename with data
230 , bartlett_kernel_lag = 10 % bandwith in optimal weighting matrix
231 , order = @{orderApp} % order of Taylor approximation in perturbation
232 , pruning % use pruned state space system at higher-order
233 % , verbose % display and store intermediate estimation results
234 , weighting_matrix = ['DIAGONAL'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename
235 % , TeX % print TeX tables and graphics
236 % Optimization options that can be set by the user in the mod file, otherwise default values are provided
237 %, huge_number=1D10 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons
238 , mode_compute = 0 % specifies the optimizer for minimization of moments distance, note that by default there is a new optimizer
239 , optim = ('TolFun', 1e-6
240 ,'TolX', 1e-6
241 ,'MaxIter', 3000
242 ,'MaxFunEvals', 1D6
243 ,'UseParallel' , 1
244 %,'Jacobian' , 'on'
245 ) % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute
246 %, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between
247 %, analytic_standard_errors
248 , se_tolx=1e-10
249 );
250
251 % Check results
252
253 fprintf('****************************************************************\n')
254 fprintf('Compare Results for perturbation order @{orderApp}\n')
255 fprintf('****************************************************************\n')
256 dev_Q = AndreasenEtAl.Q@{orderApp} - oo_.mom.Q;
257 dev_datamoments = str2double(AndreasenEtAl.moments@{orderApp}(:,5)) - oo_.mom.data_moments;
258 dev_modelmoments = str2double(AndreasenEtAl.moments@{orderApp}(:,6)) - oo_.mom.model_moments;
259
260 % There is no table command in Octave
261 if ~isoctave
262 table([AndreasenEtAl.Q@{orderApp} ; str2double(AndreasenEtAl.moments@{orderApp}(:,5)) ; str2double(AndreasenEtAl.moments@{orderApp}(:,6))],...
263 [oo_.mom.Q ; oo_.mom.data_moments ; oo_.mom.model_moments ],...
264 [dev_Q ; dev_datamoments ; dev_modelmoments ],...
265 'VariableNames', {'Andreasen_et_al', 'Dynare', 'dev'})
266 end
267
268 if norm(dev_modelmoments)> 1e-4
269 warning('Something wrong in the computation of moments at order @{orderApp}')
270 end
271
272 @#endfor
273
274 %--------------------------------------------------------------------------
275 % Replicate estimation at orderApp=3
276 %--------------------------------------------------------------------------
277 @#ifdef DoEstimation
278 method_of_moments(
279 mom_method = GMM % method of moments method; possible values: GMM|SMM
280 , datafile = 'AFVRR_data.mat' % name of filename with data
281 , bartlett_kernel_lag = 10 % bandwith in optimal weighting matrix
282 , order = 3 % order of Taylor approximation in perturbation
283 , pruning % use pruned state space system at higher-order
284 % , verbose % display and store intermediate estimation results
285 , weighting_matrix = ['DIAGONAL', 'Optimal'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename
286 % , TeX % print TeX tables and graphics
287 % Optimization options that can be set by the user in the mod file, otherwise default values are provided
288 %, huge_number=1D10 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons
289 , mode_compute = 13 % specifies the optimizer for minimization of moments distance, note that by default there is a new optimizer
290 , additional_optimizer_steps = [13]
291 , optim = ('TolFun', 1e-6
292 ,'TolX', 1e-6
293 ,'MaxIter', 3000
294 ,'MaxFunEvals', 1D6
295 ,'UseParallel' , 1
296 %,'Jacobian' , 'on'
297 ) % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute
298 , silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between
299 %, analytic_standard_errors
300 , se_tolx=1e-10
301 );
302 @#endif