| 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 benchmark model with no feedback M_0 |
| 24 |
% Original code RunGMM_standardModel_RRA.m by Martin M. Andreasen, Jan 2016 |
| 25 |
|
| 26 |
@#include "AFVRR_common.inc" |
| 27 |
|
| 28 |
%-------------------------------------------------------------------------- |
| 29 |
% Parameter calibration taken from RunGMM_standardModel_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 |
CONSxhr40 = 0; |
| 41 |
BETTAxhr = 0; |
| 42 |
BETTAxhr40= 0; |
| 43 |
RHOD = 0; |
| 44 |
GAMA = 0.9999; |
| 45 |
CONSxhr20 = 0; |
| 46 |
|
| 47 |
% estimated parameters |
| 48 |
BETTA = 0.999544966118000; |
| 49 |
B = 0.668859504661000; |
| 50 |
H = 0.342483445196000; |
| 51 |
PHI2 = 0.997924964981000; |
| 52 |
RRA = 662.7953149595370; |
| 53 |
KAPAtwo = 5.516226495551000; |
| 54 |
ALFA = 0.809462321180000; |
| 55 |
RHOR = 0.643873352513000; |
| 56 |
BETTAPAI = 1.270087844103000; |
| 57 |
BETTAY = 0.031812764291000; |
| 58 |
MYYPS = 1.001189151180000; |
| 59 |
MYZ = 1.005286347928000; |
| 60 |
RHOA = 0.743239127127000; |
| 61 |
RHOG = 0.793929380230000; |
| 62 |
PAI = 1.012163659169000; |
| 63 |
GoY = 0.206594858866000; |
| 64 |
STDA = 0.016586292524000; |
| 65 |
STDG = 0.041220613851000; |
| 66 |
STDD = 0.013534473123000; |
| 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 |
GoY; |
| 114 |
stderr eps_a; |
| 115 |
stderr eps_g; |
| 116 |
stderr eps_d; |
| 117 |
end; |
| 118 |
|
| 119 |
estimated_params_init(use_calibration); |
| 120 |
end; |
| 121 |
|
| 122 |
%-------------------------------------------------------------------------- |
| 123 |
% Compare whether toolbox yields equivalent moments at second order |
| 124 |
%-------------------------------------------------------------------------- |
| 125 |
% Note that we compare results for orderApp=1|2 and not for orderApp=3, because |
| 126 |
% there is a small error in the replication files of the original article in the |
| 127 |
% computation of the covariance matrix of the extended innovations vector. |
| 128 |
% The authors have been contacted, fixed it, and report that the results |
| 129 |
% change only slightly at orderApp=3 to what they report in the paper. At |
| 130 |
% orderApp=2 all is correct and so the following part tests whether we get |
| 131 |
% the same model moments at the calibrated parameters (we do not optimize). |
| 132 |
% We compare it to the replication file RunGMM_standardModel_RRA.m with the |
| 133 |
% following settings: orderApp=1|2, seOn=0, q_lag=10, weighting=1; |
| 134 |
% scaled=0; optimizer=0; estimator=1; momentSet=2; |
| 135 |
% |
| 136 |
% Output of the replication files for orderApp=1 |
| 137 |
AndreasenEtAl.Q1 = 23893.072; |
| 138 |
AndreasenEtAl.moments1 =[ % note that we reshuffeled to be compatible with our matched moments block |
| 139 |
{[ 1]} {'Ex' } {'Gr_C '} {' ' } {'0.024388' } {'0.023764' } |
| 140 |
{[ 2]} {'Ex' } {'Gr_I '} {' ' } {'0.031046' } {'0.028517' } |
| 141 |
{[ 3]} {'Ex' } {'Infl ' } {' ' } {'0.03757' } {'0.048361' } |
| 142 |
{[ 4]} {'Ex' } {'r1 ' } {' ' } {'0.056048' } {'0.073945' } |
| 143 |
{[ 5]} {'Ex' } {'r40 ' } {' ' } {'0.069929' } {'0.073945' } |
| 144 |
{[ 6]} {'Ex' } {'xhr40 '} {' ' } {'0.017237' } {'0' } |
| 145 |
{[ 7]} {'Ex' } {'GoY '} {' ' } {'-1.5745' } {'-1.577' } |
| 146 |
{[ 8]} {'Ex' } {'hours '} {' ' } {'-0.043353' } {'-0.042861' } |
| 147 |
{[ 9]} {'Exx' } {'Gr_C '} {'Gr_C '} {'0.0013159' } {'0.0011816' } |
| 148 |
{[10]} {'Exx' } {'Gr_C '} {'Gr_I '} {'0.0021789' } {'0.0016052' } |
| 149 |
{[11]} {'Exx' } {'Gr_C '} {'Infl ' } {'0.00067495' } {'0.00090947' } |
| 150 |
{[12]} {'Exx' } {'Gr_C '} {'r1 ' } {'0.0011655' } {'0.0016016' } |
| 151 |
{[13]} {'Exx' } {'Gr_C '} {'r40 ' } {'0.0015906' } {'0.0017076' } |
| 152 |
{[14]} {'Exx' } {'Gr_C '} {'xhr40 '} {'0.0020911' } {'0.0013997' } |
| 153 |
{[15]} {'Exx' } {'Gr_I '} {'Gr_I '} {'0.0089104' } {'0.0055317' } |
| 154 |
{[16]} {'Exx' } {'Gr_I '} {'Infl ' } {'0.00063139' } {'0.00050106' } |
| 155 |
{[17]} {'Exx' } {'Gr_I '} {'r1 ' } {'0.0011031' } {'0.0018178' } |
| 156 |
{[18]} {'Exx' } {'Gr_I '} {'r40 ' } {'0.0018445' } {'0.0020186' } |
| 157 |
{[19]} {'Exx' } {'Gr_I '} {'xhr40 '} {'0.00095556' } {'0.0064471' } |
| 158 |
{[20]} {'Exx' } {'Infl ' } {'Infl ' } {'0.0020268' } {'0.0030519' } |
| 159 |
{[21]} {'Exx' } {'Infl ' } {'r1 ' } {'0.0025263' } {'0.0042181' } |
| 160 |
{[22]} {'Exx' } {'Infl ' } {'r40 ' } {'0.0029126' } {'0.0039217' } |
| 161 |
{[23]} {'Exx' } {'Infl ' } {'xhr40 '} {'-0.00077101'} {'-0.0019975' } |
| 162 |
{[24]} {'Exx' } {'r1 ' } {'r1 ' } {'0.0038708' } {'0.0061403' } |
| 163 |
{[25]} {'Exx' } {'r1 ' } {'r40 ' } {'0.0044773' } {'0.0058343' } |
| 164 |
{[26]} {'Exx' } {'r1 ' } {'xhr40 '} {'-0.00048202'} {'-0.00089501'} |
| 165 |
{[27]} {'Exx' } {'r40 ' } {'r40 ' } {'0.0054664' } {'0.0056883' } |
| 166 |
{[28]} {'Exx' } {'r40 ' } {'xhr40 '} {'0.00053864' } {'-0.00041184'} |
| 167 |
{[29]} {'Exx' } {'xhr40 '} {'xhr40 '} {'0.053097' } {'0.016255' } |
| 168 |
{[30]} {'Exx' } {'GoY '} {'GoY '} {'2.4863' } {'2.4919' } |
| 169 |
{[31]} {'Exx' } {'hours '} {'hours '} {'0.0018799' } {'0.0018384' } |
| 170 |
{[32]} {'Exx1'} {'Gr_C '} {'Gr_C '} {'0.00077917' } {'0.00065543' } |
| 171 |
{[33]} {'Exx1'} {'Gr_I '} {'Gr_I '} {'0.0050104' } {'0.0033626' } |
| 172 |
{[34]} {'Exx1'} {'Infl ' } {'Infl ' } {'0.0019503' } {'0.0029033' } |
| 173 |
{[35]} {'Exx1'} {'r1 ' } {'r1 ' } {'0.0038509' } {'0.006112' } |
| 174 |
{[36]} {'Exx1'} {'r40 ' } {'r40 ' } {'0.0054699' } {'0.005683' } |
| 175 |
{[37]} {'Exx1'} {'xhr40 '} {'xhr40 '} {'-0.00098295'} {'3.3307e-16' } |
| 176 |
{[38]} {'Exx1'} {'GoY '} {'GoY '} {'2.4868' } {'2.4912' } |
| 177 |
{[39]} {'Exx1'} {'hours '} {'hours '} {'0.0018799' } {'0.0018378' } |
| 178 |
]; |
| 179 |
|
| 180 |
% Output of the replication files for orderApp=2 |
| 181 |
AndreasenEtAl.Q2 = 65.8269; |
| 182 |
AndreasenEtAl.moments2 =[ % note that we reshuffeled to be compatible with our matched moments block |
| 183 |
{[ 1]} {'Ex' } {'Gr_C '} {' ' } {'0.024388' } {'0.023764' } |
| 184 |
{[ 2]} {'Ex' } {'Gr_I '} {' ' } {'0.031046' } {'0.028517' } |
| 185 |
{[ 3]} {'Ex' } {'Infl ' } {' ' } {'0.03757' } {'0.034882' } |
| 186 |
{[ 4]} {'Ex' } {'r1 ' } {' ' } {'0.056048' } {'0.056542' } |
| 187 |
{[ 5]} {'Ex' } {'r40 ' } {' ' } {'0.069929' } {'0.070145' } |
| 188 |
{[ 6]} {'Ex' } {'xhr40 '} {' ' } {'0.017237' } {'0.020825' } |
| 189 |
{[ 7]} {'Ex' } {'GoY '} {' ' } {'-1.5745' } {'-1.5748' } |
| 190 |
{[ 8]} {'Ex' } {'hours '} {' ' } {'-0.043353' } {'-0.04335' } |
| 191 |
{[ 9]} {'Exx' } {'Gr_C '} {'Gr_C '} {'0.0013159' } {'0.001205' } |
| 192 |
{[10]} {'Exx' } {'Gr_C '} {'Gr_I '} {'0.0021789' } {'0.0016067' } |
| 193 |
{[11]} {'Exx' } {'Gr_C '} {'Infl ' } {'0.00067495' } {'0.00059406'} |
| 194 |
{[12]} {'Exx' } {'Gr_C '} {'r1 ' } {'0.0011655' } {'0.0011949' } |
| 195 |
{[13]} {'Exx' } {'Gr_C '} {'r40 ' } {'0.0015906' } {'0.0016104' } |
| 196 |
{[14]} {'Exx' } {'Gr_C '} {'xhr40 '} {'0.0020911' } {'0.0020245' } |
| 197 |
{[15]} {'Exx' } {'Gr_I '} {'Gr_I '} {'0.0089104' } {'0.0060254' } |
| 198 |
{[16]} {'Exx' } {'Gr_I '} {'Infl ' } {'0.00063139' } {'8.3563e-05'} |
| 199 |
{[17]} {'Exx' } {'Gr_I '} {'r1 ' } {'0.0011031' } {'0.0013176' } |
| 200 |
{[18]} {'Exx' } {'Gr_I '} {'r40 ' } {'0.0018445' } {'0.0019042' } |
| 201 |
{[19]} {'Exx' } {'Gr_I '} {'xhr40 '} {'0.00095556' } {'0.0064261' } |
| 202 |
{[20]} {'Exx' } {'Infl ' } {'Infl ' } {'0.0020268' } {'0.0020735' } |
| 203 |
{[21]} {'Exx' } {'Infl ' } {'r1 ' } {'0.0025263' } {'0.0027621' } |
| 204 |
{[22]} {'Exx' } {'Infl ' } {'r40 ' } {'0.0029126' } {'0.0029257' } |
| 205 |
{[23]} {'Exx' } {'Infl ' } {'xhr40 '} {'-0.00077101'} {'-0.0012165'} |
| 206 |
{[24]} {'Exx' } {'r1 ' } {'r1 ' } {'0.0038708' } {'0.0040235' } |
| 207 |
{[25]} {'Exx' } {'r1 ' } {'r40 ' } {'0.0044773' } {'0.0044702' } |
| 208 |
{[26]} {'Exx' } {'r1 ' } {'xhr40 '} {'-0.00048202'} {'0.00030542'} |
| 209 |
{[27]} {'Exx' } {'r40 ' } {'r40 ' } {'0.0054664' } {'0.0052718' } |
| 210 |
{[28]} {'Exx' } {'r40 ' } {'xhr40 '} {'0.00053864' } {'0.0010045' } |
| 211 |
{[29]} {'Exx' } {'xhr40 '} {'xhr40 '} {'0.053097' } {'0.018416' } |
| 212 |
{[30]} {'Exx' } {'GoY '} {'GoY '} {'2.4863' } {'2.4853' } |
| 213 |
{[31]} {'Exx' } {'hours '} {'hours '} {'0.0018799' } {'0.0018806' } |
| 214 |
{[32]} {'Exx1'} {'Gr_C '} {'Gr_C '} {'0.00077917' } {'0.00067309'} |
| 215 |
{[33]} {'Exx1'} {'Gr_I '} {'Gr_I '} {'0.0050104' } {'0.0033293' } |
| 216 |
{[34]} {'Exx1'} {'Infl ' } {'Infl ' } {'0.0019503' } {'0.0019223' } |
| 217 |
{[35]} {'Exx1'} {'r1 ' } {'r1 ' } {'0.0038509' } {'0.0039949' } |
| 218 |
{[36]} {'Exx1'} {'r40 ' } {'r40 ' } {'0.0054699' } {'0.0052659' } |
| 219 |
{[37]} {'Exx1'} {'xhr40 '} {'xhr40 '} {'-0.00098295'} {'0.0004337' } |
| 220 |
{[38]} {'Exx1'} {'GoY '} {'GoY '} {'2.4868' } {'2.4846' } |
| 221 |
{[39]} {'Exx1'} {'hours '} {'hours '} {'0.0018799' } {'0.00188' } |
| 222 |
]; |
| 223 |
|
| 224 |
@#for orderApp in 1:2 |
| 225 |
|
| 226 |
method_of_moments( |
| 227 |
mom_method = GMM % method of moments method; possible values: GMM|SMM |
| 228 |
, datafile = 'AFVRR_data.mat' % name of filename with data |
| 229 |
, bartlett_kernel_lag = 10 % bandwith in optimal weighting matrix |
| 230 |
, order = @{orderApp} % order of Taylor approximation in perturbation |
| 231 |
, pruning % use pruned state space system at higher-order |
| 232 |
% , verbose % display and store intermediate estimation results |
| 233 |
, weighting_matrix = ['DIAGONAL'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename |
| 234 |
% , TeX % print TeX tables and graphics |
| 235 |
% Optimization options that can be set by the user in the mod file, otherwise default values are provided |
| 236 |
%, huge_number=1D10 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons |
| 237 |
, mode_compute = 0 % specifies the optimizer for minimization of moments distance, note that by default there is a new optimizer |
| 238 |
, optim = ('TolFun', 1e-6 |
| 239 |
,'TolX', 1e-6 |
| 240 |
,'MaxIter', 3000 |
| 241 |
,'MaxFunEvals', 1D6 |
| 242 |
,'UseParallel' , 1 |
| 243 |
%,'Jacobian' , 'on' |
| 244 |
) % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute |
| 245 |
%, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between |
| 246 |
%, analytic_standard_errors |
| 247 |
, se_tolx=1e-10 |
| 248 |
); |
| 249 |
|
| 250 |
% Check results |
| 251 |
|
| 252 |
fprintf('****************************************************************\n') |
| 253 |
fprintf('Compare Results for perturbation order @{orderApp}\n') |
| 254 |
fprintf('****************************************************************\n') |
| 255 |
dev_Q = AndreasenEtAl.Q@{orderApp} - oo_.mom.Q; |
| 256 |
dev_datamoments = str2double(AndreasenEtAl.moments@{orderApp}(:,5)) - oo_.mom.data_moments; |
| 257 |
dev_modelmoments = str2double(AndreasenEtAl.moments@{orderApp}(:,6)) - oo_.mom.model_moments; |
| 258 |
|
| 259 |
% There is no table command in Octave |
| 260 |
if ~isoctave |
| 261 |
table([AndreasenEtAl.Q@{orderApp} ; str2double(AndreasenEtAl.moments@{orderApp}(:,5)) ; str2double(AndreasenEtAl.moments@{orderApp}(:,6))],... |
| 262 |
[oo_.mom.Q ; oo_.mom.data_moments ; oo_.mom.model_moments ],... |
| 263 |
[dev_Q ; dev_datamoments ; dev_modelmoments ],... |
| 264 |
'VariableNames', {'Andreasen_et_al', 'Dynare', 'dev'}) |
| 265 |
end |
| 266 |
|
| 267 |
if norm(dev_modelmoments)> 1e-4 |
| 268 |
error('Something wrong in the computation of moments at order @{orderApp}') |
| 269 |
end |
| 270 |
|
| 271 |
@#endfor |
| 272 |
|
| 273 |
%-------------------------------------------------------------------------- |
| 274 |
% Replicate estimation at orderApp=3 |
| 275 |
%-------------------------------------------------------------------------- |
| 276 |
@#ifdef DoEstimation |
| 277 |
method_of_moments( |
| 278 |
mom_method = GMM % method of moments method; possible values: GMM|SMM |
| 279 |
, datafile = 'AFVRR_data.mat' % name of filename with data |
| 280 |
, bartlett_kernel_lag = 10 % bandwith in optimal weighting matrix |
| 281 |
, order = 3 % order of Taylor approximation in perturbation |
| 282 |
, pruning % use pruned state space system at higher-order |
| 283 |
% , verbose % display and store intermediate estimation results |
| 284 |
, weighting_matrix = ['DIAGONAL', 'OPTIMAL'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename |
| 285 |
% , TeX % print TeX tables and graphics |
| 286 |
% Optimization options that can be set by the user in the mod file, otherwise default values are provided |
| 287 |
%, huge_number=1D10 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons |
| 288 |
, mode_compute = 13 % specifies the optimizer for minimization of moments distance, note that by default there is a new optimizer |
| 289 |
, additional_optimizer_steps = [13] |
| 290 |
, optim = ('TolFun', 1e-6 |
| 291 |
,'TolX', 1e-6 |
| 292 |
,'MaxIter', 3000 |
| 293 |
,'MaxFunEvals', 1D6 |
| 294 |
,'UseParallel' , 1 |
| 295 |
%,'Jacobian' , 'on' |
| 296 |
) % a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute |
| 297 |
, silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between |
| 298 |
%, analytic_standard_errors |
| 299 |
, se_tolx=1e-10 |
| 300 |
); |
| 301 |
@#endif |