Debian Codegraph @

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

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