Debian Codegraph @

tests/pac/trend-component-7/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 gamma beta ;
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
23 a_x2_0 = -.9;
24 a_x2_1 = .2;
25 a_x2_2 = -.1;
26 a_x2_x1_1 = -.1;
27 a_x2_x1_2 = .2;
28
29 beta = .2;
30 e_c_m = .5;
31 c_z_1 = .2;
32 c_z_2 = -.1;
33
34 trend_component_model(model_name=toto, eqtags=['eq:x1', 'eq:x2', 'eq:x1bar', 'eq:x2bar'], targets=['eq:x1bar', 'eq:x2bar']);
35
36 pac_model(auxiliary_model_name=toto, discount=beta, model_name=pacman);
37
38 model;
39
40 [name='eq:y']
41 y = rho_1*y(-1) + rho_2*y(-2) + ey;
42
43 [name='eq:x1']
44 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;
45
46 [name='eq:x2']
47 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;
48
49 [name='eq:x1bar']
50 x1bar = x1bar(-1) + ex1bar;
51
52 [name='eq:x2bar']
53 x2bar = x2bar(-1) + ex2bar;
54
55 [name='zpac']
56 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;
57
58 end;
59
60 shocks;
61 var ex1 = 1.0;
62 var ex2 = 1.0;
63 var ex1bar = 1.0;
64 var ex2bar = 1.0;
65 var ez = 1.0;
66 var ey = 0.1;
67 end;
68
69 // Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
70 pac.initialize('pacman');
71
72 // Update the parameters of the PAC expectation model (h0 and h1 vectors).
73 pac.update.expectation('pacman');
74
75 // Set initial conditions to zero. Please use more sensible values if any...
76 initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
77
78 // Simulate the model for 500 periods
79 TrueData = simul_backward_model(initialconditions, 500);
80
81 //[pnames, enames, xnames, pid, eid, xid] = get_variables_and_parameters_in_equation('zpac', M_)
82
83 // Define a structure describing the parameters to be estimated (with initial conditions).
84 clear eparams
85 eparams.e_c_m = .9;
86 eparams.c_z_1 = .5;
87 eparams.c_z_2 = .2;
88
89 // Define the dataset used for estimation
90 edata = TrueData;
91 edata.ez = dseries(NaN(TrueData.nobs, 1), 200Q1, 'ez');
92
93 pac.estimate.nls('zpac', eparams, edata, 2005Q1:2120Q1);
94
95 disp(sprintf('Estimate of e_c_m: %f', M_.params(strmatch('e_c_m', M_.param_names, 'exact'))))
96 disp(sprintf('Estimate of c_z_1: %f', M_.params(strmatch('c_z_1', M_.param_names, 'exact'))))
97 disp(sprintf('Estimate of c_z_2: %f', M_.params(strmatch('c_z_2', M_.param_names, 'exact'))))