Debian Codegraph @

tests/occbin/filter/NKM_calib_smoother.mod

raw
1 //Tests Occbin estimation with IVF and PKF with 1 constraints
2
3 // this file implements the model in:
4 // Atkinson, T., A. W. Richter, and N. A. Throckmorton (2019).
5 // The zero lower bound andestimation accuracy.Journal of Monetary Economics
6 // original codes provided by Alexander Richter
7 // adapted for dynare implementation
8 // adapted to avoid stochastic singularity at the ZLB
9 // ------------------------- Settings -----------------------------------------//
10
11 @#ifndef small_model
12 @#define small_model = 0
13 @#endif
14
15
16 // ----------------- Defintions -----------------------------------------//
17 var
18 c //1 Consumption
19 n //2 Labor
20 y //5 Output
21 yf //6 Final goods
22 yg //11 Output growth gap
23 w //12 Real wage rate
24 wf //13 Flexible real wage
25 pigap //15 Inflation rate -> pi(t)/pibar = pigap
26 inom //16 Nominal interest rate
27 inomnot //17 Notional interest rate
28 mc //19 Real marginal cost
29 lam //20 Inverse marginal utility of wealth
30 g //21 Growth shock
31 s //22 Risk premium shock
32 mp //23 Monetary policy shock
33 pi //24 Observed inflation
34 @#if !(small_model)
35 x //3 Investment
36 k //4 Capital
37 u //7 Utilization cost
38 ups //8 Utilization choice
39 wg //9 Real wage growth gap
40 xg //10 Investment growth
41 rk //14 Real rental rate
42 q //18 Tobins q
43 @#endif
44 ;
45
46 varexo
47 epsg // Productivity growth shock
48 epsi // Notional interest rate shock
49 epss // Risk premium shock
50 ;
51 parameters
52 // Calibrated Parameters
53 beta // Discount factor
54 chi // Labor disutility scale
55 thetap // Elasticity of subs. between intermediate goods
56 thetaw // Elasticity of subs. between labor types
57 nbar // Steady state labor
58 eta // Inverse frish elasticity of labor supply
59 delta // Depreciation
60 alpha // Capital share
61 gbar // Mean growth rate
62 pibar // Inflation target
63 inombar // Steady gross nom interest rate
64 inomlb // Effective lower bound on gross nominal interest rate
65 sbar // Average risk premium
66 // Parameters for DGP and Estimated parameters
67 varphip // Rotemberg price adjustment cost
68 varphiw // Rotemberg wage adjustment cost
69 h // Habit persistence
70 rhos // Persistence
71 rhoi // Persistence
72 sigz // Standard deviation technology
73 sigs // Standard deviation risk premia
74 sigi // Standard deviation mon pol
75 phipi // Inflation responsiveness
76 phiy // Output responsiveness
77 nu // Investment adjustment cost
78 sigups // Utilization
79 ;
80
81
82 // ---------------- Calibration -----------------------------------------//
83
84 beta = 0.9949; // Discount factor
85 thetap = 6; // Elasticity of subs. between intermediate goods
86 thetaw = 6; // Elasticity of subs. between labor types
87 nbar = 1/3; // Steady state labor
88 eta = 1/3; // Inverse frish elasticity of labor supply
89 delta = 0.025; // Depreciation
90 alpha = 0.35; // Capital share
91 gbar = 1.0034; // Mean growth rate
92 pibar = 1.0053; // Inflation target
93 sbar = 1.0058; // Average risk premium
94 rkbar = 1/beta;
95 varphiw = 100; // Rotemberg wage adjustment cost
96 nu = 4; // Investment adjustment cost
97 sigups = 5; // Utilization
98 varphip = 100; // Rotemberg price adjustment cost
99 h = 0.80; // Habit persistence
100 rhos = 0.80; // Persistence
101 rhoi = 0.80; // Persistence
102 sigz = 0.005; // Standard deviation
103 sigs = 0.005; // Standard deviation
104 sigi = 0.002; // Standard deviation
105 phipi = 2.0; // Inflation responsiveness
106 phiy = 0.5; // Output responsiveness
107 inomlb = 1 ; // Inom LB
108
109 // ---------------- Model -----------------------------------------------//
110 model;
111
112 @#if !(small_model)
113 [name = 'HH FOC utilization (1)']
114 rk = steady_state(rk)*exp(sigups*(ups-1));
115
116 [name = 'Utilization definition (3)']
117 u = steady_state(rk)*(exp(sigups*(ups-1))-1)/sigups;
118
119 [name = 'Firm FOC capital (4)']
120 rk = mc*alpha*g*yf/(ups*k(-1));
121
122 [name = 'HH FOC capital (17)']
123 q = beta*(lam/lam(+1))*(rk(+1)*ups(+1)-u(+1)+(1-delta)*q(+1))/g(+1);
124
125 [name = 'HH FOC investment (18)']
126 1 = q*(1-nu*(xg-1)^2/2-nu*(xg-1)*xg)+beta*nu*gbar*q(+1)*(lam/lam(+1))*xg(+1)^2*(xg(+1)-1)/g(+1);
127
128 [name = 'Wage Phillips Curve (20)']
129 varphiw*(wg-1)*wg = ((1-thetaw)*w+thetaw*wf)*n/yf + beta*varphiw*(lam/lam(+1))*(wg(+1)-1)*wg(+1)*(yf(+1)/yf) ;
130
131 [name = 'Real wage growth gap (6)']
132 wg = pigap*g*w/(gbar*w(-1));
133
134 [name = 'Law of motion for capital (15)']
135 k = (1-delta)*(k(-1)/g)+x*(1-nu*(xg-1)^2/2);
136
137 [name = 'Investment growth gap (14)']
138 xg = g*x/(gbar*x(-1));
139 @#endif
140
141
142 @#if small_model
143 [name = 'Production function (2)']
144 yf = n;
145
146 [name = 'Firm FOC labor (5)']
147 w = mc*yf/n;
148
149 [name = 'Output definition (7)']
150 y = (1-varphip*(pigap-1)^2/2)*yf;
151
152 [name = 'ARC (13)']
153 c = y;
154
155 [name = 'Household labpur supply equals flex wage']
156 w = wf;
157 @#else
158 [name = 'Production function (2)']
159 yf = (ups*k(-1)/g)^alpha*n^(1-alpha);
160
161 [name = 'Firm FOC labor (5)']
162 w = (1-alpha)*mc*yf/n;
163
164 [name = 'Output definition (7)']
165 y = (1-varphip*(pigap-1)^2/2-varphiw*(wg-1)^2/2)*yf - u*k(-1)/g;
166
167 [name = 'ARC (13)']
168 x = y-c;
169 @#endif
170
171 [name = 'Output growth gap (8)']
172 yg = g*y/(gbar*y(-1));
173
174 [name = 'Notional Interest Rate (9)']
175 inomnot = inomnot(-1)^rhoi*(inombar*pigap^phipi*yg^phiy)^(1-rhoi);
176
177 [name = 'Nominal Interest Rate (10)', bind='zlb']
178 inom = inomlb*exp(mp);
179 [name = 'Nominal Interest Rate (10)', relax='zlb']
180 inom = inomnot*exp(mp);
181
182 [name = 'Inverse MUC (11)']
183 lam = c-h*c(-1)/g;
184
185 [name = 'Flexible real wage definition (12)']
186 wf = chi*n^eta*lam;
187
188 [name = 'HH FOC bond (16)']
189 1 = beta*(lam/lam(+1))*s*inom/(g(+1)*pibar*pigap(+1));
190
191 [name = 'Price Phillips Curve (19)']
192 varphip*(pigap-1)*pigap = 1-thetap+thetap*mc+beta*varphip*(lam/lam(+1))*(pigap(+1)-1)*pigap(+1)*(yf(+1)/yf);
193
194 [name = 'Stochastic productivity growth (21)']
195 g = gbar+ sigz*epsg;
196
197 [name = 'Risk premium shock (22)']
198 s = (1-rhos)*sbar + rhos*s(-1)+sigs*epss ;
199
200 [name = 'Notional interest rate shock (23)']
201 mp = sigi*epsi;
202
203 [name = 'Observed inflation (24)']
204 pi = pigap*pibar;
205
206 end;
207
208 occbin_constraints;
209 name 'zlb'; bind inomnot <= inomlb; relax inomnot > inomlb;
210 end;
211
212 // ---------------- Steady state -----------------------------------------//
213 steady_state_model;
214 mp = 0;
215 xg = 1;
216 s = sbar;
217 n = nbar;
218 ups =1;
219 u =0;
220 q =1;
221 g = gbar;
222 yg = 1;
223 pigap = 1;
224 wg =1;
225 pi = pigap*pibar;
226 // FOC bond
227 inom = gbar*pibar/(beta*s);
228 inomnot = inom;
229 inombar = inom;
230 // Firm pricing
231 mc = (thetap-1)/thetap;
232 // FOC capital
233 rk = gbar/beta+delta-1;
234 // Marginal cost definition
235 @#if small_model
236 alpha = 0;
237 thetaw=1;
238 @#endif
239 w = (mc*(1-alpha)^(1-alpha)*alpha^alpha/rk^alpha)^(1/(1-alpha));
240 @#if small_model
241 wf = w;
242 @#else
243 wf = (thetaw-1)*w/thetaw;
244 @#endif
245 // Consolidated FOC firm
246 k = w*n*gbar*alpha/(rk*(1-alpha));
247 // Law of motion for capital
248 x = (1-(1-delta)/gbar)*k;
249 // Production function
250 yf = (k/gbar)^alpha*n^(1-alpha);
251 // Real GDP
252 y = yf;
253 // Aggregate resouce constraint
254 c = y-x;
255 // FOC labor
256 lam = (1-h/gbar)*c;
257 chi = wf/(n^eta*lam);
258
259 end;
260
261 // ---------------- Checks -----------------------------------------//
262 steady;
263 check;
264
265 // ---------------- Simulation -----------------------------------------//
266 shocks;
267 var epsi = 1;
268 var epss = 1;
269 var epsg = 1;
270 end;
271
272 steady;
273 check;
274
275 // ---------------- Estimation -----------------------------------------//
276
277 varobs yg inom pi;
278
279 // -----------------Occbin ----------------------------------------------//
280 options_.occbin.smoother.debug=1;
281 occbin_setup(likelihood_piecewise_kalman_filter);
282 options_.nobs=110;
283 calib_smoother(datafile=dataobsfile,first_obs=1,smoothed_state_uncertainty,smoother_redux);
284 oo_PKF=oo_;
285
286 occbin_setup(likelihood_inversion_filter,smoother_inversion_filter);
287 calib_smoother(datafile=dataobsfile,first_obs=1,smoothed_state_uncertainty,smoother_redux);
288
289 figure
290 subplot(3,1,1)
291 plot(1:options_.nobs,oo_.SmoothedShocks.epsg,'b-',1:options_.nobs,oo_PKF.SmoothedShocks.epsg)
292 subplot(3,1,2)
293 plot(1:options_.nobs,oo_.SmoothedShocks.epsi,'b-',1:options_.nobs,oo_PKF.SmoothedShocks.epsi)
294 subplot(3,1,3)
295 plot(1:options_.nobs,oo_.SmoothedShocks.epss,'b-',1:options_.nobs,oo_PKF.SmoothedShocks.epss)
296 figure
297 plot(1:options_.nobs,oo_.SmoothedVariables.inom,'b-',1:options_.nobs,oo_PKF.SmoothedVariables.inom)
298
299 burnin=40;
300 if max(abs(oo_.SmoothedShocks.epsg(burnin+1:end)-oo_PKF.SmoothedShocks.epsg(burnin+1:end)))>0.1 || ...
301 max(abs(oo_.SmoothedShocks.epsi(burnin+1:end)-oo_PKF.SmoothedShocks.epsi(burnin+1:end)))>0.1 || ...
302 max(abs(oo_.SmoothedShocks.epss(burnin+1:end)-oo_PKF.SmoothedShocks.epss(burnin+1:end)))>0.1
303 error('Smoothed shocks differ too much')
304 end
305
306 if max(abs(oo_.SmoothedVariables.inom(burnin+1:end)-oo_PKF.SmoothedVariables.inom(burnin+1:end)))>0.001 || ...
307 max(abs(oo_.SmoothedVariables.yg(burnin+1:end)-oo_PKF.SmoothedVariables.yg(burnin+1:end)))>0.001 || ...
308 max(abs(oo_.SmoothedVariables.pi(burnin+1:end)-oo_PKF.SmoothedVariables.pi(burnin+1:end)))>0.001
309 error('Smoothed observables differ too much')
310 end
311
312 temp_data=load('dataobsfile.mat');
313 if max(abs(temp_data.inom(options_.first_obs+burnin:options_.first_obs+options_.nobs-1)-oo_PKF.SmoothedVariables.inom(burnin+1:end)))>0.0001 || ...
314 max(abs(temp_data.yg(options_.first_obs+burnin:options_.first_obs+options_.nobs-1)-oo_PKF.SmoothedVariables.yg(burnin+1:end)))>0.0001 || ...
315 max(abs(temp_data.pi(options_.first_obs+burnin:options_.first_obs+options_.nobs-1)-oo_PKF.SmoothedVariables.pi(burnin+1:end)))>0.0001
316 error('Smoothed observables differ too much')
317 end
318