Debian Codegraph @

tests/estimation/method_of_moments/AnScho/AnScho_MoM_common.inc

raw
1 % DSGE model used in replication files of
2 % An, Sungbae and Schorfheide, Frank, (2007), Bayesian Analysis of DSGE Models, Econometric Reviews, 26, issue 2-4, p. 113-172.
3 % Adapted by Willi Mutschler (@wmutschl, [email protected])
4 % =========================================================================
5 % Copyright © 2020-2021 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 var c p R g y z INFL INT YGR;
24 varexo e_r e_g e_z;
25 parameters tau nu kap cyst psi1 psi2 rhor rhog rhoz rrst pist gamst;
26
27 varobs INT YGR INFL;
28
29 tau = 2;
30 nu = 0.1;
31 kap = 0.33;
32 cyst = 0.85;
33 psi1 = 1.5;
34 psi2 = 0.125;
35 rhor = 0.75;
36 rhog = 0.95;
37 rhoz = 0.9;
38 rrst = 1;
39 pist = 3.2;
40 gamst = 0.55;
41
42 model;
43 #pist2 = exp(pist/400);
44 #rrst2 = exp(rrst/400);
45 #bet = 1/rrst2;
46 #phi = tau*(1-nu)/nu/kap/pist2^2;
47 #gst = 1/cyst;
48 #cst = (1-nu)^(1/tau);
49 #yst = cst*gst;
50 #dy = y-y(-1);
51 1 = exp(-tau*c(+1)+tau*c+R-z(+1)-p(+1));
52 (1-nu)/nu/phi/(pist2^2)*(exp(tau*c)-1) = (exp(p)-1)*((1-1/2/nu)*exp(p)+1/2/nu) - bet*(exp(p(+1))-1)*exp(-tau*c(+1)+tau*c+y(+1)-y+p(+1));
53 exp(c-y) = exp(-g) - phi*pist2^2*gst/2*(exp(p)-1)^2;
54 R = rhor*R(-1) + (1-rhor)*psi1*p + (1-rhor)*psi2*(dy+z) + e_r/100;
55 g = rhog*g(-1) + e_g/100;
56 z = rhoz*z(-1) + e_z/100;
57 YGR = gamst+100*(dy+z);
58 INFL = pist+400*p;
59 INT = pist+rrst+4*gamst+400*R;
60 end;
61
62 steady_state_model;
63 z = 0; p = 0; g = 0; R = 0; c = 0; y = 0;
64 YGR = gamst; INFL = pist; INT = pist + rrst + 4*gamst;
65 end;
66
67 shocks;
68 var e_r = 0.20^2;
69 var e_g = 0.80^2;
70 var e_z = 0.45^2;
71 corr e_r,e_g = 0.2;
72 end;
73
74 @#if estimParams == 0
75 % Define only initial values without bounds
76 estimated_params;
77 %tau, 1.50;
78 %kap, 0.15;
79 psi1, 1.20;
80 psi2, 0.50;
81 rhor, 0.50;
82 %rhog, 0.50;
83 %rhoz, 0.50;
84 %rrst, 1.20;
85 %pist, 3.00;
86 gamst, 0.75;
87 stderr e_r, 0.30;
88 stderr e_g, 0.30;
89 stderr e_z, 0.30;
90 corr e_r,e_g, 0.10;
91 end;
92 @#endif
93
94 @#if estimParams == 1
95 % Define initial values and bounds
96 estimated_params;
97 %tau, 1.50, 1e-5, 10;
98 %kap, 0.15, 1e-5, 10;
99 psi1, 1.20, 1e-5, 10;
100 psi2, 0.50, 1e-5, 10;
101 rhor, 0.50, 1e-5, 0.99999;
102 %rhog, 0.50, 1e-5, 0.99999;
103 %rhoz, 0.50, 1e-5, 0.99999;
104 %rrst, 1.20, 1e-5, 10;
105 %pist, 3.00, 1e-5, 20;
106 gamst, 0.75, -5, 5;
107 stderr e_r, 0.30, 1e-8, 5;
108 stderr e_g, 0.30, 1e-8, 5;
109 stderr e_z, 0.30, 1e-8, 5;
110 corr e_r,e_g, 0.10, -1, 1;
111 end;
112 @#endif
113
114 @#if estimParams == 2
115 % Define prior distribution
116 estimated_params;
117 %tau, 1.50, 1e-5, 10, gamma_pdf, 2.00, 0.50;
118 %kap, 0.15, 1e-5, 10, gamma_pdf, 0.33, 0.10;
119 psi1, 1.20, 1e-5, 10, gamma_pdf, 1.50, 0.25;
120 psi2, 0.50, 1e-5, 10, gamma_pdf, 0.125, 0.25;
121 rhor, 0.50, 1e-5, 0.99999, beta_pdf, 0.50, 0.20;
122 %rhog, 0.50, 1e-5, 0.99999, beta_pdf, 0.80, 0.10;
123 %rhoz, 0.50, 1e-5, 0.99999, beta_pdf, 0.66, 0.15;
124 %rrst, 1.20, 1e-5, 10, gamma_pdf, 0.50, 0.50;
125 %pist, 3.00, 1e-5, 20, gamma_pdf, 7.00, 2.00;
126 gamst, 0.75, -5, 5, normal_pdf, 0.40, 0.20;
127 stderr e_r, 0.30, 1e-8, 5, inv_gamma_pdf, 0.50, 0.26;
128 stderr e_g, 0.30, 1e-8, 5, inv_gamma_pdf, 1.25, 0.65;
129 stderr e_z, 0.30, 1e-8, 5, inv_gamma_pdf, 0.63, 0.33;
130 corr e_r,e_g, 0.10, -1, 1, uniform_pdf, , , -1, 1;
131 end;
132 @#endif
133
134
135 % % Simulate data
136 % stoch_simul(order=2,pruning,nodisplay,nomoments,periods=750,drop=500);
137 % save('AnScho_MoM_data_2.mat', options_.varobs{:} );
138 % pause(1);
139
140 %--------------------------------------------------------------------------
141 % Method of Moments Estimation
142 %--------------------------------------------------------------------------
143 matched_moments;
144
145 %first-order product moments
146 YGR;
147 YGR(-1); %redundant
148 YGR(0)^1; %redundant
149 YGR^1; %redundant
150 YGR^1*INFL^0*INT^0; %redundant
151 INFL(+2)^1;
152 INT(-2);
153 INT(2); %redundant
154
155 %second-order contemporenous product moments
156 YGR^2;
157 YGR(-1)^2; %redundant
158 YGR*YGR; %redundant
159 YGR(1)*YGR(1); %redundant
160 INFL*YGR;
161 YGR*INFL; %redundant
162 YGR(2)*INT(2);
163 INT(2)*YGR(2); %redundant
164 INT(2)^1*YGR(2)^1; %redundant
165 YGR(2)^1*INT(2)^1; %redundant
166 INFL(-2)^1*INFL(-2)^1;
167 INFL(-1)*INT(-1);
168 INT(0)^1*INT^1;
169 INT(0)^1*INT^1*YGR(2)^0*INT(-2)^0*INFL^0; %redundant
170
171 %second-order temporal product moments
172 YGR*YGR(-1);
173 YGR(3)*YGR(2); %redundant
174 YGR(2)*YGR(3); %redundant
175 YGR(-2)*YGR(-1); %redundant
176 INT(3)^1*INT(-2)^1;
177 YGR(5)^0*INFL*INFL(2)^1;
178 YGR(5)^1*INFL(-3)^1;
179 INFL(-3)^1*YGR(5)^1; %redundant
180 INFL(3)*INT(2);
181
182 @#ifdef Extended_Matched_Moments_Checks
183 YGR^3;
184 YGR(-3)^2*YGR(-3); %redundant
185 YGR(-3)*YGR(-3)^2; %redundant
186 YGR(0)^1*YGR(0)*YGR; %redundant
187 INT(-2)^2*INFL(-1)^4;
188 INFL(1)^4*INT(0)^2; %redundant
189 INT(0)^2*INFL(1)^4; %redundant
190 %YGR^2*INFL(-3)^4*INT(5)^6;
191 %YGR^2*INT(5)^6*INFL(-3)^4;%redundant
192 %INT(5)^6*YGR^2*INFL(-3)^4;%redundant
193 @#endif
194 end;
195
196 M_.matched_moments_orig = M_.matched_moments;
197
198 method_of_moments(
199 % Necessary options
200 mom_method = @{MoM_Method} % method of moments method; possible values: GMM|SMM
201 , datafile = 'AnScho_MoM_data_2.mat' % name of filename with data
202
203 % Options for both GMM and SMM
204 % , bartlett_kernel_lag = 20 % bandwith in optimal weighting matrix
205 , order = 2 % order of Taylor approximation in perturbation
206 % , penalized_estimator % include deviation from prior mean as additional moment restriction and use prior precision as weight
207 , pruning % use pruned state space system at higher-order
208 , verbose % display and store intermediate estimation results
209 , weighting_matrix = ['optimal'] % weighting matrix in moments distance objective function; possible values: OPTIMAL|IDENTITY_MATRIX|DIAGONAL|filename. Size of cell determines stages in iterated estimation, e.g. two state with ['DIAGONAL','OPTIMAL']
210 %, weighting_matrix_scaling_factor=1 % scaling of weighting matrix in objective function
211 , se_tolx=1e-6 % step size for numerical computation of standard errors
212
213 % Options for SMM
214 , burnin=50 % number of periods dropped at beginning of simulation
215 , bounded_shock_support % trim shocks in simulation to +- 2 stdev
216 % , seed = 24051986 % seed used in simulations
217 , simulation_multiple = 5 % multiple of the data length used for simulation
218
219 % Options for GMM
220 @#if MoM_Method == "GMM"
221 , analytic_standard_errors % compute standard errors using analytical derivatives
222 @#endif
223 % General options
224 % , dirname = 'MM' % directory in which to store estimation output
225 % , graph_format = EPS % specify the file format(s) for graphs saved to disk
226 % , nodisplay % do not display the graphs, but still save them to disk
227 % , nograph % do not create graphs (which implies that they are not saved to the disk nor displayed)
228 % , noprint % do not print stuff to console
229 % , plot_priors = 1 % control plotting of priors
230 % , prior_trunc = 1e-10 % probability of extreme values of the prior density that is ignored when computing bounds for the parameters
231 % , TeX % print TeX tables and graphics
232
233 % Data and model options
234 % , first_obs = 501 % number of first observation
235 % , logdata % if data is already in logs
236 , nobs = 250 % number of observations
237 % , prefilter=0 % demean each data series by its empirical mean and use centered moments
238
239 % , xls_sheet = data % name/number of sheet with data in Excel
240 % , xls_range = B2:D200 % range of data in Excel sheet
241
242 % Optimization options that can be set by the user in the mod file, otherwise default values are provided
243 % , huge_number=1e7 % value for replacing the infinite bounds on parameters by finite numbers. Used by some optimizers for numerical reasons
244 @#ifdef NoEstim
245 , mode_compute = 0
246 @#else
247 , mode_compute = 13 % specifies the optimizer for minimization of moments distance
248 , additional_optimizer_steps = [4] % vector of additional mode-finders run after mode_compute
249 , mode_check % plot the target function for values around the computed minimum for each estimated parameter in turn
250 @#endif
251 % optim: a list of NAME and VALUE pairs to set options for the optimization routines. Available options depend on mode_compute, some exemplary common options:
252 , optim = ('TolFun' , 1e-6 % termination tolerance on the function value, a positive scalar
253 ,'TolX' , 1e-6 % termination tolerance on x, a positive scalar
254 ,'MaxIter' , 3000 % maximum number of iterations allowed, a positive integer
255 ,'MaxFunEvals' , 1D6 % maximum number of function evaluations allowed, a positive integer
256 % ,'UseParallel' , 1 % when true (and supported by optimizer) solver estimates gradients in parallel (using Matlab/Octave's parallel toolbox)
257 % ,'Jacobian' , 'off' % when 'off' gradient-based solvers approximate Jacobian using finite differences; for GMM we can also pass the analytical Jacobian to gradient-based solvers by setting this 'on'
258 )
259 , silent_optimizer % run minimization of moments distance silently without displaying results or saving files in between
260
261 % Numerical algorithms options
262 % , aim_solver % Use AIM algorithm to compute perturbation approximation
263 % , k_order_solver % use k_order_solver in higher order perturbation approximations
264 % , dr=default % method used to compute the decision rule; possible values are DEFAULT, CYCLE_REDUCTION, LOGARITHMIC_REDUCTION
265 % , dr_cycle_reduction_tol = 1e-7 % convergence criterion used in the cycle reduction algorithm
266 % , dr_logarithmic_reduction_tol = 1e-12 % convergence criterion used in the logarithmic reduction algorithm
267 % , dr_logarithmic_reduction_maxiter = 100 % maximum number of iterations used in the logarithmic reduction algorithm
268 % , lyapunov = DEFAULT % algorithm used to solve lyapunov equations; possible values are DEFAULT, FIXED_POINT, DOUBLING, SQUARE_ROOT_SOLVER
269 % , lyapunov_complex_threshold = 1e-15 % complex block threshold for the upper triangular matrix in symmetric Lyapunov equation solver
270 % , lyapunov_fixed_point_tol = 1e-10 % convergence criterion used in the fixed point Lyapunov solver
271 % , lyapunov_doubling_tol = 1e-16 % convergence criterion used in the doubling algorithm
272 % , qz_criterium = 0.999999 % value used to split stable from unstable eigenvalues in reordering the Generalized Schur decomposition used for solving first order problems
273 % , qz_zero_threshold = 1e-6 % value used to test if a generalized eigenvalue is 0/0 in the generalized Schur decomposition
274 % , schur_vec_tol=1e-11 % tolerance level used to find nonstationary variables in Schur decomposition of the transition matrix
275 % , mode_check_neighbourhood_size = 5 % width of the window (expressed in percentage deviation) around the computed minimum to be displayed on the diagnostic plots
276 % , mode_check_symmetric_plots=1 % ensure that the check plots are symmetric around the minimum
277 % , mode_check_number_of_points = 20 % number of points around the minimum where the target function is evaluated (for each parameter)
278 );