Debian Codegraph @

tests/estimation/univariate/ols/mc-ols.inc

raw
1 verbatim;
2
3 options_.noprint = true;
4
5 number_of_simulations = 1;
6
7 calibrated_values = M_.params;
8 Sigma_e = M_.Sigma_e;
9
10 options_.bnlms.set_dynare_seed_to_default = false;
11
12 Beta = zeros(number_of_simulations, M_.param_nbr);
13
14 for i=1:number_of_simulations
15 % Set initial conditions randomly
16 firstobs = rand(3, length(M_.endo_names));
17 % Set parameters to calibrated values (because after the
18 % estimation parameters in equation 7 are updated with OLS
19 % estimator).
20 M_.params = calibrated_values;
21 M_.Sigma_e = Sigma_e;
22 % Simulate the model.
23 simdata = simul_backward_model(dseries(firstobs, dates('1995Q1'), M_.endo_names), 1100);
24 % Select a subsample.
25 simdata = simdata(simdata.dates(101:1100));
26 % Get vector of indices to exclude exogenous variables from the dataset.
27 names = regexp(simdata.name, 'res\w*');
28 idxs = find(cellfun(@isempty, names));
29 % Perform the estimation of equation 7.
30 if strcmp(M_.fname, 'ols_param_names')
31 dyn_ols(simdata{idxs}, {}, {'eq7'}, '', {{'de_g_yer_ecm_u2_stn_L1', 'de_g_yer_de_g_yer_L1'}});
32 elseif strcmp(M_.fname, 'ols_date_range')
33 dyn_ols(simdata{idxs}, {}, {'eq7'}, '', {}, simdata.dates(2:end-3));
34 else
35 dyn_ols(simdata{idxs}, {}, {'eq7'});
36 end
37 if i ~= number_of_simulations
38 oo_ = rmfield(oo_, 'ols');
39 end
40 % Store the estimation results in Beta
41 Beta(i, :) = M_.params';
42 end
43
44 % Get the indices of the estimated parameters
45 pid = oo_.ols.eq7.param_idxs;
46
47 if number_of_simulations > 1
48 if max(abs(calibrated_values(pid)-mean(Beta(:,pid)', 2)))>1e-2
49 error('There is probably an error in the OLS routine.')
50 end
51 else
52 % NB: estimation results depend on the sequence of generated random
53 % numbers, hence we need to hardcode different results between MATLAB
54 % and Octave
55 if strcmp(M_.fname, 'ols_base')
56 if isoctave
57 good = [2.509401520579608e-02
58 -1.212468793686628e-01
59 2.983003417202038e-02
60 4.645373135672548e-01
61 -6.312448906643650e-02];
62 else
63 good = [0.025487074270635
64 -0.126705792250240
65 0.002639663639062
66 0.486913131141265
67 -0.027702100375691];
68 end
69 elseif strcmp(M_.fname, 'ols_param_names')
70 if isoctave
71 good = [-0.125307512725951
72 0.465364467369817];
73 else
74 good = [-0.125265361034515
75 0.497003481797959];
76 end
77 elseif strcmp(M_.fname, 'ols_date_range')
78 if isoctave
79 good = [4.775810440061960e-01
80 2.096533656963026e-02
81 3.264889547460539e-02
82 -1.167420901882959e-01];
83 else
84 good = [0.468607715487806
85 -0.011224442004140
86 0.033681224841824
87 -0.126743281213504];
88 end
89 elseif strcmp(M_.fname, 'ols_wc_1')
90 if isoctave
91 good = [4.778519485900916e-01
92 2.028231364527827e-02
93 3.186766890724485e-02
94 -1.173897445629599e-01];
95 else
96 good = [0.466534186307255
97 -0.010596174928406
98 0.035098464382347
99 -0.126502172176703];
100 end
101 elseif strcmp(M_.fname, 'ols_wc_2')
102 if isoctave
103 good = [4.679679703340907e-01
104 2.987618894535485e-02
105 2.503849196608867e-02
106 -1.206391201296474e-01
107 3.435379133407408e-02];
108 else
109 good = [0.485802603276717
110 0.002660854661647
111 0.025434782170432
112 -0.126939890810119
113 0.043688440124315];
114 end
115 elseif strcmp(M_.fname, 'ols_wc_3')
116 if isoctave
117 good = [4.766230170524117e-01
118 2.500479091401997e-02
119 2.333265887171398e-02
120 -9.913848386063488e-02];
121 else
122 good = [0.490636551206316
123 0.014209413280418
124 0.028534044956486
125 -0.094387460262917];
126 end
127 end
128 if max(abs(good-Beta(:,pid)'))>1e-2
129 error('There is probably an error in the OLS routine.')
130 end
131 return
132 end
133
134 for i=1:length(pid)
135 figure(i)
136 hold on
137 title(strrep(M_.param_names(pid(i),:), '_', '\_'));
138 bandwidth = mh_optimal_bandwidth(Beta(:,pid(i)), length(Beta(:,pid(i))), -1, 'gaussian');
139 [abscissa, f] = kernel_density_estimate(Beta(:,pid(i)), 256, length(Beta(:,pid(i))), bandwidth, 'gaussian');
140 plot(abscissa, f, '-k', 'linewidth', 2);
141 line([calibrated_values(pid(i)) calibrated_values(pid(i))], [0 max(f)*1.05], 'LineWidth', 2, 'Color', 'r');
142 line([mean(Beta(:,pid(i))) mean(Beta(:,pid(i)))], [0 max(f)*1.05], 'LineWidth', 2, 'Color', 'g');
143 axis tight
144 box on
145 hold off
146 end
147
148 end;
149