Fixed PAC index for target variable in companion VAR.

time-shift
Stéphane Adjemian(Charybdis) 2018-08-10 15:42:13 +02:00
parent 8a6d23f471
commit 8b3ba814c7
2 changed files with 51 additions and 10 deletions

View File

@ -65,18 +65,33 @@ end
pacvalues = DynareModel.params([pacmodel.ec.params; pacmodel.ar.params(:)]);
% Get the indices for the stationary/nonstationary variables in the VAR system.
if any(varmodel.nonstationary)
idns = find(varmodel.nonstationary);
if length(idns)<length(varmodel.eqn)
ids = find(~varmodel.nonstationary);
id = find(strcmp(DynareModel.endo_names{pacmodel.ec.vars(1)}, varmodel.list_of_variables_in_companion_var));
if isempty(id)
% Find the auxiliary variables if any
ad = find(cell2mat(cellfun(@(x) isauxiliary(x, 8), varmodel.list_of_variables_in_companion_var, 'UniformOutput', false)));
if isempty(ad)
error('Cannot find the trend variable in the Companion VAR/VECM model.')
else
% All the variables in the system are non stationary.
ids = [];
for i=1:length(ad)
auxinfo = DynareModel.aux_vars(get_aux_variable_id(varmodel.list_of_variables_in_companion_var{ad(i)}));
if isequal(auxinfo.orig_index, pacmodel.ec.vars(1))
id = ad(i);
break
end
end
end
if isempty(id)
error('Cannot find the trend variable in the Companion VAR/VECM model.')
end
end
if varmodel.nonstationary(id)
idns = id;
ids = [];
else
% All the variables in the system are stationary.
idns = [];
ids = 1:length(varmodel.eqn);
ids = id;
end
% Get the value of the discount factor.
@ -92,19 +107,27 @@ end
% Get h0 and h1 vectors (plus the parameter for the growth neutrality correction).
if growth_flag
[h0, h1, growthneutrality] = hVectors([pacvalues; beta], varcalib.CompanionMatrix, ids, pacmodel.ec.vars(1), pacmodel.auxmodel);
[h0, h1, growthneutrality] = hVectors([pacvalues; beta], varcalib.CompanionMatrix, ids, idns, pacmodel.auxmodel);
else
[h0, h1] = hVectors([pacvalues; beta], varcalib.CompanionMatrix, ids, pacmodel.ec.vars(1), pacmodel.auxmodel);
[h0, h1] = hVectors([pacvalues; beta], varcalib.CompanionMatrix, ids, idns, pacmodel.auxmodel);
end
% Update the parameters related to the stationary components.
if length(h0)
DynareModel.params(pacmodel.h0_param_indices) = h0;
else
if isfield(pacmodel, 'h0_param_indices') && length(pacmodel.h0_param_indices)
DynareModel.params(pacmodel.h0_param_indices) = .0;
end
end
% Update the parameters related to the nonstationary components.
if length(h1)
DynareModel.params(pacmodel.h1_param_indices) = h1;
else
if isfield(pacmodel, 'h1_param_indices') && length(pacmodel.h1_param_indices)
DynareModel.params(pacmodel.h1_param_indices) = .0;
end
end
% Update the parameter related to the growth neutrality correction.

View File

@ -47,6 +47,7 @@ if nargin<2
oo_.var.(var_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n);
end
end
M_.var.(var_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(var_model_name).lhs);
return
end
@ -64,6 +65,7 @@ if all(~oo_.var.(var_model_name).ec(:))
oo_.var.(var_model_name).CompanionMatrix((i-1)*n+(1:n),(i-2)*n+(1:n)) = eye(n);
end
end
M_.var.(var_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(var_model_name).lhs);
else
error('You should not use undiff option in this model!')
end
@ -189,6 +191,22 @@ else
oo_.var.(var_model_name).CompanionMatrix(i*n+(1:n),(i-1)*n+(1:n)) = eye(n);
end
oo_.var.(var_model_name).CompanionMatrix(1:n, p*n+(1:n)) = B(:,:,p+1);
M_.var.(var_model_name).list_of_variables_in_companion_var = M_.endo_names(M_.var.(var_model_name).lhs);
variables_rewritten_in_levels = M_.var.(var_model_name).list_of_variables_in_companion_var(ecm_eqnums_in_auxiliary_model);
for i=1:m
id = get_aux_variable_id(variables_rewritten_in_levels{i});
if id
auxinfo = M_.aux_vars(id);
if auxinfo.type==8
M_.var.(var_model_name).list_of_variables_in_companion_var(ecm_eqnums_in_auxiliary_model(i)) = ...
{M_.endo_names{auxinfo.orig_index}};
else
error('This is a bug. Please contact the Dynare Team.')
end
else
error('This is a bug. Please contact the Dynare Team.')
end
end
else
error('It is not possible to cast the VECM model in a companion representation! Use undiff option.')
end