Debian Codegraph @

tests/pac/trend-component-8-mc-iterative-ols/example1.mod

raw
1 // --+ options: json=compute, stochastic +--
2
3 var x1 x2 x1bar x2bar z y;
4
5 varexo ex1 ex2 ex1bar ex2bar ez ey;
6
7 parameters
8 rho_1 rho_2
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 beta g;
12
13 rho_1 = .9;
14 rho_2 = -.2;
15
16 a_x1_0 = -.9;
17 a_x1_1 = .4;
18 a_x1_2 = .3;
19 a_x1_x2_1 = .1;
20 a_x1_x2_2 = .2;
21
22 a_x2_0 = -.9;
23 a_x2_1 = .2;
24 a_x2_2 = -.1;
25 a_x2_x1_1 = -.1;
26 a_x2_x1_2 = .2;
27
28 beta = .2;
29 e_c_m = .5;
30 c_z_1 = .2;
31 c_z_2 = -.1;
32
33 g=.1;
34
35 trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
36
37 pac_model(auxiliary_model_name=toto, discount=beta, growth=g, model_name=pacman);
38
39 model;
40
41 [name='eq:y']
42 y = rho_1*y(-1) + rho_2*y(-2) + ey;
43
44 [name='eq:x1']
45 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;
46
47 [name='eq:x2']
48 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;
49
50 [name='eq:x1bar']
51 x1bar = x1bar(-1) + ex1bar;
52
53 [name='eq:x2bar']
54 x2bar = x2bar(-1) + ex2bar;
55
56 [name='zpac']
57 diff(z) = e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_expectation(pacman) + ez;
58
59 end;
60
61 shocks;
62 var ex1 = 1.0;
63 var ex2 = 1.0;
64 var ex1bar = 1.0;
65 var ex2bar = 1.0;
66 var ez = 1.0;
67 var ey = 0.1;
68 end;
69
70 // Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
71 pac.initialize('pacman');
72
73
74 // Update the parameters of the PAC expectation model (h0 and h1 vectors).
75 pac.update.expectation('pacman');
76
77 // Set initial conditions to zero. Please use more sensible values if any...
78 initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
79
80 B = 1;
81 X = zeros(3,B);
82
83 set_dynare_seed('default');
84 options_.bnlms.set_dynare_seed_to_default = false;
85
86 for i=1:B
87 e_c_m = .5;
88 c_z_1 = .2;
89 c_z_2 = -.1;
90 // Simulate the model for 500 periods
91 TrueData = simul_backward_model(initialconditions, 300);
92 // Define a structure describing the parameters to be estimated (with initial conditions).
93 clear eparams
94 eparams.e_c_m = -.5;
95 eparams.c_z_1 = .2;
96 eparams.c_z_2 =-.1;
97 // Define the dataset used for estimation
98 edata = TrueData;
99 edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
100 pac.estimate.iterative_ols('zpac', eparams, edata, 2005Q1:2000Q1+200);
101 X(1,i) = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
102 X(2,i) = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
103 X(3,i) = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
104 end
105
106 mean(X, 2)