Adjust result output for NLS and Iterative OLS.

time-shift
Dóra Kocsis 2019-10-09 15:11:08 +02:00
parent 3434ec2f9b
commit 3648ccb8ff
3 changed files with 56 additions and 36 deletions

View File

@ -401,6 +401,12 @@ while noconvergence
end
end
% Save results
oo_.pac.(pacmodl).equations.(eqtag).ssr = ssr;
oo_.pac.(pacmodl).equations.(eqtag).residual = r;
oo_.pac.(pacmodl).equations.(eqtag).estimator = params0_;
oo_.pac.(pacmodl).equations.(eqtag).covariance = NaN(length(params0_));
oo_.pac.(pacmodl).equations.(eqtag).student = NaN(size(params0_));
function [PacExpectations, Model] = UpdatePacExpectationsData(dataPAC0, dataPAC1, data, range, pacmodl, eqtag, Model, Output)

View File

@ -323,6 +323,7 @@ C = C/T;
% Save results
oo_.pac.(pacmodl).equations.(eqtag).ssr = SSR;
oo_.pac.(pacmodl).equations.(eqtag).residual = r;
oo_.pac.(pacmodl).equations.(eqtag).estimator = params1;
oo_.pac.(pacmodl).equations.(eqtag).covariance = C;
oo_.pac.(pacmodl).equations.(eqtag).student = params1./(sqrt(diag(C)));

View File

@ -59,51 +59,64 @@ diff(z) = e_c_m*(x1(-1)-z(-1)) + c_z_1*diff(z(-1)) + c_z_2*diff(z(-2)) + pac_ex
end;
shocks;
var ex1 = 1.0;
var ex2 = 1.0;
var ex1bar = 1.0;
var ex2bar = 1.0;
var ez = 1.0;
var ey = 0.1;
var g = 0.1;
end;
// Initialize the PAC model (build the Companion VAR representation for the auxiliary model).
pac.initialize('pacman');
// Update the parameters of the PAC expectation model (h0 and h1 vectors).
pac.update.expectation('pacman');
// Set initial conditions to zero. Please use more sensible values if any...
initialconditions = dseries(zeros(10, M_.endo_nbr+M_.exo_nbr), 2000Q1, vertcat(M_.endo_names,M_.exo_names));
B = 1;
X = zeros(3,B);
// Simulate the model for 5000 periods
TrueData = simul_backward_model(initialconditions, 5000);
set_dynare_seed('default');
options_.bnlms.set_dynare_seed_to_default = false;
// NLS estimation
// Define a structure describing the parameters to be estimated (with initial conditions).
clear eparams
eparams.e_c_m = .5;
eparams.c_z_1 = .2;
eparams.c_z_2 =-.1;
for i=1:B
e_c_m = .5;
c_z_1 = .2;
c_z_2 = -.1;
// Simulate the model for 500 periods
TrueData = simul_backward_model(initialconditions, 300);
// Define a structure describing the parameters to be estimated (with initial conditions).
clear eparams
eparams.e_c_m = .5;
eparams.c_z_1 = .2;
eparams.c_z_2 =-.1;
// Define the dataset used for estimation
edata = TrueData;
edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
pac.estimate.iterative_ols('zpac', eparams, edata, 2005Q1:2000Q1+200);
pac.print('pacman','zpac');
X(1,i) = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
X(2,i) = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
X(3,i) = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
end
edata = TrueData;
edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
pac.estimate.nls('zpac', eparams, edata, 2005Q1:2000Q1+200, 'lsqnonlin');
mean(X, 2)
e_c_m_nls = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
c_z_1_nls = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
c_z_2_nls = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
resid_nls = oo_.pac.pacman.equations.eq0.residual;
fprintf('Estimate of e_c_m: %f \n', e_c_m_nls)
fprintf('Estimate of c_z_1: %f \n', c_z_1_nls)
fprintf('Estimate of c_z_2: %f \n', c_z_2_nls)
skipline(2)
// Iterative OLS estimation using estimates from NLS
// Define a structure describing the parameters to be estimated (with initial conditions).
clear eparams
eparams.e_c_m = e_c_m_nls;
eparams.c_z_1 = c_z_1_nls;
eparams.c_z_2 = c_z_2_nls;
// Define the dataset used for estimation
edata = TrueData;
edata.ez = dseries(NaN(TrueData.nobs, 1), 2000Q1, 'ez');
pac.estimate.iterative_ols('zpac', eparams, edata, 2005Q1:2000Q1+200);
// Test printing of PAC expectations
pac.print('pacman','zpac');
e_c_m_iterative_ols = M_.params(strmatch('e_c_m', M_.param_names, 'exact'));
c_z_1_iterative_ols = M_.params(strmatch('c_z_1', M_.param_names, 'exact'));
c_z_2_iterative_ols = M_.params(strmatch('c_z_2', M_.param_names, 'exact'));
resid_iterative_ols = oo_.pac.pacman.equations.eq0.residual;
fprintf('Estimate of e_c_m: %f \n', e_c_m_iterative_ols)
fprintf('Estimate of c_z_1: %f \n', c_z_1_iterative_ols)
fprintf('Estimate of c_z_2: %f \n', c_z_2_iterative_ols)
if any(abs(resid_nls-resid_iterative_ols)>1e-4)
error('Iterative OLS and NLS do not provide consistent results.')
end