Debian Codegraph @

tests/pac/trend-component-25/example1.mod

raw
1 // --+ options: json=compute, stochastic +--
2
3 var x1 x2 x1bar x2bar z y x u v s;
4
5 varexo ex1 ex2 ex1bar ex2bar ez ey ex eu ev es;
6
7 parameters
8 rho_1 rho_2 rho_3 rho_4
9 a_x1_0 a_x1_1 a_x1_2 a_x1_x2_1 a_x1_x2_2
10 a_x2_0 a_x2_1 a_x2_2 a_x2_x1_1 a_x2_x1_2
11 e_c_m c_z_1 c_z_2 c_z_dx2 c_z_u c_z_dv c_z_s beta
12 lambda;
13
14 rho_1 = .9;
15 rho_2 = -.2;
16 rho_3 = .4;
17 rho_4 = -.3;
18
19
20 a_x1_0 = -.9;
21 a_x1_1 = .4;
22 a_x1_2 = .3;
23 a_x1_x2_1 = .1;
24 a_x1_x2_2 = .2;
25
26 a_x2_0 = -.9;
27 a_x2_1 = .2;
28 a_x2_2 = -.1;
29 a_x2_x1_1 = -.1;
30 a_x2_x1_2 = .2;
31
32 beta = .2;
33 e_c_m = .5;
34 c_z_1 = .2;
35 c_z_2 = -.1;
36 c_z_dx2 = .3;
37 c_z_u = .3;
38 c_z_dv = .4;
39 c_z_s = -.2;
40
41 lambda = 0.5; // Share of optimizing agents.
42
43 trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
44
45 pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
46
47 model;
48
49 [name='eq:s']
50 s = .3*s(-1) - .1*s(-2) + es;
51
52 [name='eq:diff(v)']
53 diff(v) = .5*diff(v(-1)) + ev;
54
55 [name='eq:u']
56 u = .5*u(-1) - .2*u(-2) + eu;
57
58 [name='eq:y']
59 y = rho_1*y(-1) + rho_2*y(-2) + ey;
60
61 [name='eq:x']
62 x = rho_3*x(-1) + rho_4*x(-2) + ex;
63
64 [name='eq:x1']
65 diff(x1) = a_x1_0*(x1(-1)-x1bar(-1)) + a_x1_1*diff(x1(-1)) + a_x1_2*diff(x1(-2)) + a_x1_x2_1*diff(x2(-1)) + a_x1_x2_2*diff(x2(-2)) + ex1;
66
67 [name='eq:x2']
68 diff(x2) = a_x2_0*(x2(-1)-x2bar(-1)) + a_x2_1*diff(x1(-1)) + a_x2_2*diff(x1(-2)) + a_x2_x1_1*diff(x2(-1)) + a_x2_x1_2*diff(x2(-2)) + ex2;
69
70 [name='eq:x1bar']
71 x1bar = x1bar(-1) + ex1bar;
72
73 [name='eq:x2bar']
74 x2bar = x2bar(-1) + ex2bar;
75
76 [name='zpac']
77 diff(z) = lambda*(e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + c_z_s*s + c_z_dv*diff(v) ) + (1-lambda)*( y + x) + c_z_u*u + c_z_dx2*diff(x2) + ez;
78
79 end;
80
81 shocks;
82 var ex1 = 1.0;
83 var ex2 = 1.0;
84 var ex1bar = 1.0;
85 var ex2bar = 1.0;
86 var ez = 1.0;
87 var ey = 0.1;
88 var ex = 0.1;
89 var eu = 0.05;
90 var ev = 0.05;
91 var es = 0.07;
92 end;
93
94 // Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
95 pac.initialize('pacman');
96
97 // Update the parameters of the PAC expectation model (h0 and h1 vectors).
98 pac.update.expectation('pacman');
99
100 // Set initial conditions to zero. Please use more sensible values if any...
101 initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
102
103 // Simulate the model for 500 periods
104 if isoctave
105 // Use a different seed under Octave, the OLS estimation fails with the default one
106 options_.bnlms.set_dynare_seed_to_default = false;
107 set_dynare_seed(4);
108 end
109 TrueData = simul_backward_model(initialconditions, 5000);
110
111 // Define a structure describing the parameters to be estimated (with initial conditions).
112 clear eparams
113 eparams.e_c_m = .9;
114 eparams.c_z_1 = .5;
115 eparams.c_z_2 = .2;
116 eparams.c_z_s = .9;
117 eparams.c_z_dx2 = .1;
118 eparams.lambda = .7;
119
120 // Define the dataset used for estimation
121 edata = TrueData;
122 edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
123 pac.estimate.iterative_ols('zpac', eparams, edata, 2005Q1:2005Q1+4000);
124
125 e_c_m_iterative_ols = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
126 c_z_1_iterative_ols = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
127 c_z_2_iterative_ols = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
128 c_z_s_iterative_ols = M_.params(strmatch('c_z_s', M_.param_names, 'exact'));
129 c_z_dx2_iterative_ols = M_.params(strmatch('c_z_dx2', M_.param_names, 'exact'));
130 lambda_iterative_ols = M_.params(strmatch('lambda', M_.param_names, 'exact'));
131
132 disp(sprintf('Estimate of e_c_m: %f', e_c_m_iterative_ols))
133 disp(sprintf('Estimate of c_z_1: %f', c_z_1_iterative_ols))
134 disp(sprintf('Estimate of c_z_2: %f', c_z_2_iterative_ols))
135 disp(sprintf('Estimate of c_z_s: %f', c_z_s_iterative_ols))
136 disp(sprintf('Estimate of c_z_dx2: %f', c_z_dx2_iterative_ols))
137 disp(sprintf('Estimate of lambda: %f', lambda_iterative_ols))
138
139 skipline(2)
140
141 // Define a structure describing the parameters to be estimated (with initial conditions).
142 clear eparams
143 eparams.e_c_m = .9;
144 eparams.c_z_1 = .5;
145 eparams.c_z_2 = .2;
146 eparams.c_z_s = .9;
147 eparams.c_z_dx2 = .1;
148 eparams.lambda = .7;
149
150 edata = TrueData;
151 edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
152 pac.estimate.nls('zpac', eparams, edata, 2005Q1:2005Q1+4000, 'fmincon');
153
154 e_c_m_nls = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
155 c_z_1_nls = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
156 c_z_2_nls = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
157 c_z_s_nls = M_.params(strmatch('c_z_s', M_.param_names, 'exact'));
158 c_z_dx2_nls = M_.params(strmatch('c_z_dx2', M_.param_names, 'exact'));
159 lambda_nls = M_.params(strmatch('lambda', M_.param_names, 'exact'));
160
161 disp(sprintf('Estimate of e_c_m: %f', e_c_m_nls))
162 disp(sprintf('Estimate of c_z_1: %f', c_z_1_nls))
163 disp(sprintf('Estimate of c_z_2: %f', c_z_2_nls))
164 disp(sprintf('Estimate of c_z_s: %f', c_z_s_nls))
165 disp(sprintf('Estimate of c_z_dx2: %f', c_z_dx2_nls))
166 disp(sprintf('Estimate of lambda: %f', lambda_nls))
167
168 if abs(e_c_m_nls-e_c_m_iterative_ols)>.01
169 error('Iterative OLS and NLS do not provide consistent estimates (e_c_m)')
170 end
171
172 if abs(c_z_1_nls-c_z_1_iterative_ols)>.01
173 error('Iterative OLS and NLS do not provide consistent estimates (c_z_1)')
174 end
175
176 if abs(c_z_2_nls-c_z_2_iterative_ols)>.01
177 error('Iterative OLS and NLS do not provide consistent estimates (c_z_2)')
178 end
179
180 if abs(c_z_s_nls-c_z_s_iterative_ols)>.01
181 error('Iterative OLS and NLS do not provide consistent estimates (c_z_s)')
182 end
183
184 if abs(c_z_dx2_nls-c_z_dx2_iterative_ols)>.01
185 error('Iterative OLS and NLS do not provide consistent estimates (c_z_dx2)')
186 end
187
188 if abs(lambda_nls-lambda_iterative_ols)>.01
189 error('Iterative OLS and NLS do not provide consistent estimates (lambda)')
190 end