Debian Codegraph @

tests/conditional_variance_decomposition/example3.mod

raw
1 /*
2 * Example 1 from F. Collard (2001): "Stochastic simulations with DYNARE:
3 * A practical guide" (see "guide.pdf" in the documentation directory).
4 *
5 * This file uses the steady_state_model-block to provide analytical steady state values.
6 * To do so, the equations of the model have been transformed into a non-linear equation in
7 * labor h. Within the steady_state_model-block, a helper function is called that uses fsolve
8 * to solve this non-linear equation. The use of the helper function is necessary to avoid
9 * interference of the MATLAB syntax with Dynare's preprocessor. A more complicated alternative
10 * that provides more flexibility in the type of commands executed and functions called is the use
11 * of an explicit steady state file. See the NK_baseline.mod in the Examples Folder.
12 *
13 * This mod-file also shows how to use Dynare's capacities to generate TeX-files of the model equations.
14 * If you want to see the model equations belonging to this mod-file, run it using Dynare
15 * and then use a TeX-editor to compile the TeX-files generated.
16 */
17
18 /*
19 * Copyright © 2013 Dynare Team
20 *
21 * This file is part of Dynare.
22 *
23 * Dynare is free software: you can redistribute it and/or modify
24 * it under the terms of the GNU General Public License as published by
25 * the Free Software Foundation, either version 3 of the License, or
26 * (at your option) any later version.
27 *
28 * Dynare is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
32 *
33 * You should have received a copy of the GNU General Public License
34 * along with Dynare. If not, see <https://www.gnu.org/licenses/>.
35 */
36
37 @#define unit_root_var=0
38
39 var y, c, k, a, h, b
40 @#if unit_root_var==1
41 , unit_root
42 @#endif
43 ;
44 varexo e, u;
45
46 parameters beta $\beta$
47 rho $\rho$
48 alpha $\alpha$
49 delta $\delta$
50 theta $\theta$
51 psi $\psi$
52 tau $\tau$;
53
54 alpha = 0.36;
55 rho = 0.95;
56 tau = 0.025;
57 beta = 0.99;
58 delta = 0.025;
59 psi = 0;
60 theta = 2.95;
61
62 phi = 0.1;
63
64 model;
65 c*theta*h^(1+psi)=(1-alpha)*y;
66 k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
67 *(exp(b(+1))*alpha*y(+1)+(1-delta)*k));
68 y = exp(a)*(k(-1)^alpha)*(h^(1-alpha));
69 k = exp(b)*(y-c)+(1-delta)*k(-1);
70 a = rho*a(-1)+tau*b(-1) + e;
71 b = tau*a(-1)+rho*b(-1) + u;
72 @#if unit_root_var==1
73 unit_root=unit_root(-1)+e;
74 @#endif
75 end;
76
77 steady_state_model;
78 h=example3_steady_state_helper(alpha,beta,delta,psi,theta);
79 k=((1/beta-(1-delta))/alpha)^(1/(alpha-1))*h;
80 y = k^alpha*h^(1-alpha);
81 c=(1-alpha)*y/(theta*h^(1+psi));
82 a=0;
83 b=0;
84 end;
85
86 shocks;
87 var e; stderr 0.009;
88 var u; stderr 0.009;
89 var e, u = phi*0.009*0.009;
90 end;
91
92 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=1);
93 oo1_=oo_;
94 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=1) y k;
95 oo2_=oo_;
96 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=2) y k ;
97 oo3_=oo_;
98 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=2);
99 oo4_=oo_;
100
101 if max(max(abs(oo1_.variance_decomposition-oo4_.variance_decomposition)))>1e-8 || max(max(abs(oo2_.variance_decomposition-oo3_.variance_decomposition)))>1e-8
102 error('Unconditional variance decomposition does not match.')
103 end
104
105 if max(max(max(abs(oo1_.conditional_variance_decomposition-oo4_.conditional_variance_decomposition))))>1e-8 || max(max(max(abs(oo2_.conditional_variance_decomposition-oo3_.conditional_variance_decomposition)))) >1e-8
106 error('Conditional variance decomposition does not match.')
107 end
108
109 varobs y;
110 shocks;
111 var y; stderr 0.01;
112 end;
113
114 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=1);
115 oo1_=oo_;
116 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=1) y k;
117 oo2_=oo_;
118 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=2) y k ;
119 oo3_=oo_;
120 stoch_simul(irf=0,conditional_variance_decomposition=[1,4,40],pruning,order=2);
121 oo4_=oo_;
122
123
124 if max(max(abs(oo1_.variance_decomposition-oo4_.variance_decomposition)))>1e-8 || max(max(abs(oo2_.variance_decomposition-oo3_.variance_decomposition)))>1e-8
125 error('Unconditional variance decomposition does not match.')
126 end
127
128 if max(max(max(abs(oo1_.conditional_variance_decomposition-oo4_.conditional_variance_decomposition))))>1e-8 || max(max(max(abs(oo2_.conditional_variance_decomposition-oo3_.conditional_variance_decomposition)))) >1e-8
129 error('Conditional variance decomposition does not match.')
130 end
131
132 if max(max(abs(oo1_.variance_decomposition_ME-oo4_.variance_decomposition_ME)))>1e-2 || max(max(abs(oo2_.variance_decomposition_ME-oo3_.variance_decomposition_ME)))>1e-2
133 error('Unconditional variance decomposition with ME does not match.')
134 end
135
136 if max(max(max(abs(oo1_.conditional_variance_decomposition_ME-oo4_.conditional_variance_decomposition_ME))))>1e-8 || max(max(max(abs(oo2_.conditional_variance_decomposition_ME-oo3_.conditional_variance_decomposition_ME))))>1e-8
137 error('Conditional variance decomposition with ME does not match.')
138 end