Debian Codegraph @

tests/forecast/fs2000_forecast_varexo_det.mod

raw
1 /*
2 * Copyright © 2004-2025 Dynare Team
3 *
4 * This file is part of Dynare.
5 *
6 * Dynare is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Dynare is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 //checks correctness of forecasts of AR1 within larger model such that variable ordering can be tested
21
22 var m ${m}$ (long_name='money growth')
23 P ${P}$ (long_name='Price level')
24 c ${c}$ (long_name='consumption')
25 e ${e}$ (long_name='capital stock')
26 W ${W}$ (long_name='Wage rate')
27 R ${R}$ (long_name='interest rate')
28 k ${k}$ (long_name='capital stock')
29 d ${d}$ (long_name='dividends')
30 n ${n}$ (long_name='labor')
31 l ${l}$ (long_name='loans')
32 A
33 gy_obs ${\Delta \ln GDP}$ (long_name='detrended capital stock')
34 gp_obs ${\Delta \ln P}$ (long_name='detrended capital stock')
35 y ${y}$ (long_name='detrended output')
36 dA ${\Delta A}$ (long_name='TFP growth')
37 ;
38 varexo e_a ${\epsilon_A}$ (long_name='TFP shock')
39 e_m ${\epsilon_M}$ (long_name='Money growth shock')
40 ;
41 varexo_det eps_det;
42
43 parameters alp ${\alpha}$ (long_name='capital share')
44 bet ${\beta}$ (long_name='discount factor')
45 gam ${\gamma}$ (long_name='long-run TFP growth')
46 logmst ${\log(m^*)}$ (long_name='long-run money growth')
47 rho ${\rho}$ (long_name='autocorrelation money growth')
48 phi ${\phi}$ (long_name='labor weight in consumption')
49 del ${\delta}$ (long_name='depreciation rate')
50 ;
51
52 % roughly picked values to allow simulating the model before estimation
53 alp = 0.33;
54 bet = 0.99;
55 gam = 0.003;
56 logmst = log(1.011);
57 rho = 0.7;
58 phi = 0.787;
59 del = 0.02;
60
61 model;
62 [name='NC before eq. (1), TFP growth equation']
63 dA = exp(gam+e_a);
64 [name='NC eq. (2), money growth rate']
65 log(m) = (1-rho)*logmst + rho*log(m(-1))+e_m;
66 [name='NC eq. (A1), Euler equation']
67 -P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(-alp*(gam+log(e(+1))))*k^(alp-1)*n(+1)^(1-alp)+(1-del)*exp(-(gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
68 [name='NC below eq. (A1), firm borrowing constraint']
69 W = l/n;
70 [name='NC eq. (A2), intratemporal labour market condition']
71 -(phi/(1-phi))*(c*P/(1-n))+l/n = 0;
72 [name='NC below eq. (A2), credit market clearing']
73 R = P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(-alp)/W;
74 [name='NC eq. (A3), credit market optimality']
75 1/(c*P)-bet*P*(1-alp)*exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
76 [name='NC eq. (18), aggregate resource constraint']
77 c+k = exp(-alp*(gam+e_a))*k(-1)^alp*n^(1-alp)+(1-del)*exp(-(gam+e_a))*k(-1);
78 [name='NC eq. (19), money market condition']
79 P*c = m;
80 [name='NC eq. (20), credit market equilibrium condition']
81 m-1+d = l;
82 [name='Definition TFP shock']
83 e = exp(e_a);
84 [name='Implied by NC eq. (18), production function']
85 y = k(-1)^alp*n^(1-alp)*exp(-alp*(gam+e_a));
86 [name='Observation equation GDP growth']
87 gy_obs = dA*y/y(-1);
88 [name='Observation equation price level']
89 gp_obs = (P/P(-1))*m(-1)/dA;
90 A= rho*A(-1)+e_a + eps_det;
91 end;
92
93 shocks;
94 var e_a; stderr 0.01;
95 var e_m; stderr 0.005;
96 end;
97
98 steady_state_model;
99 dA = exp(gam);
100 gst = 1/dA;
101 m = exp(logmst);
102 khst = ( (1-gst*bet*(1-del)) / (alp*gst^alp*bet) )^(1/(alp-1));
103 xist = ( ((khst*gst)^alp - (1-gst*(1-del))*khst)/m )^(-1);
104 nust = phi*m^2/( (1-alp)*(1-phi)*bet*gst^alp*khst^alp );
105 n = xist/(nust+xist);
106 P = xist + nust;
107 k = khst*n;
108
109 l = phi*m*n/( (1-phi)*(1-n) );
110 c = m/P;
111 d = l - m + 1;
112 y = k^alp*n^(1-alp)*gst^alp;
113 R = m/bet;
114 W = l/n;
115 ist = y-c;
116 q = 1 - d;
117
118 e = 1;
119
120 gp_obs = m/dA;
121 gy_obs = dA;
122 end;
123
124
125 stoch_simul(order=1,irf=0);
126
127 forecast(periods=500,conf_sig=0.95) A;
128 %% get theoretical forecast error variance for AR(1) process:
129 var_analytical=NaN(1+500,1);
130 var_analytical(1)=0; %zero variance in initial period
131 for ii=1:500
132 var_analytical(ii+1)=var_analytical(ii)+(rho^(ii-1))^2*0.01^2;
133 end
134 std_analytical=sqrt(var_analytical);
135
136 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
137 error('Mean forecast does not match theoretical moments')
138 end
139 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_analytical(2:end),Inf)>1e-9
140 error('Forecast variance does not match theoretical moments')
141 end
142
143 varobs A;
144
145 shocks;
146 var e_a=0.01^2;
147 var A=0.01^2;
148 end;
149
150 forecast(periods=500,conf_sig=0.95) A;
151 std_analytical_ME=sqrt(var_analytical+0.01^2);
152 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
153 error('Mean forecast with ME does not match theoretical moments')
154 end
155 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_analytical(2:end),Inf)>1e-9
156 error('Forecast variance with ME does not match theoretical moments')
157 end
158 if norm(oo_.forecast.HPDsup_ME.A-norminv(0.975)*std_analytical_ME(2:end),Inf)>1e-9
159 error('Forecast variance with ME does not match theoretical moments')
160 end
161
162
163 forecast(periods=500,conf_sig=0.95);
164 std_analytical_ME=sqrt(var_analytical+0.01^2);
165 if norm(oo_.forecast.Mean.A-0,Inf)>1e-9
166 error('Mean forecast with ME does not match theoretical moments')
167 end
168 if norm(oo_.forecast.HPDsup.A-norminv(0.975)*std_analytical(2:end),Inf)>1e-9
169 error('Forecast variance with ME does not match theoretical moments')
170 end
171 if norm(oo_.forecast.HPDsup_ME.A-norminv(0.975)*std_analytical_ME(2:end),Inf)>1e-9
172 error('Forecast variance with ME does not match theoretical moments')
173 end