From 8e1528c1cbcc45ca9fa9c16b8cd2508b085224a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Tue, 24 Sep 2019 18:09:42 +0200 Subject: [PATCH] Temporary fix for growth parameter in PAC models The preprocessor has been modified to allow linear combinations in the growth parameter (see Dynare/preprocessor@a0f74f5c16b9a1826069797a5fa9ebce2ae7777f and Dynare/preprocessor@d873414728cb19b610f5159a072cc013bc537c69). This commit restores the previous functionality (i.e. it fixes the simple case where only one parameter/variable is provided for the growth parameter). The code still needs to be adapted to really handle linear combinations. --- matlab/+pac/+estimate/iterative_ols.m | 15 ++++++++++----- matlab/print_expectations.m | 13 +++++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/matlab/+pac/+estimate/iterative_ols.m b/matlab/+pac/+estimate/iterative_ols.m index d4bce328b..b233277b8 100644 --- a/matlab/+pac/+estimate/iterative_ols.m +++ b/matlab/+pac/+estimate/iterative_ols.m @@ -418,19 +418,24 @@ function [PacExpectations, Model] = UpdatePacExpectationsData(dataPAC0, dataPAC1 % Add correction for growth neutrality if required. correction = 0; if isfield(Model.pac.(pacmodl), 'growth_type') - switch Model.pac.(pacmodl).growth_type + if numel(Model.pac.(pacmodl).growth_type) > 1 || ... + Model.pac.(pacmodl).growth_constant(1) ~= 1 || ... + Model.pac.(pacmodl).growth_param_id(1) ~= 0 + error('Linear combinations in growth parameter are not yet supported') + end + switch Model.pac.(pacmodl).growth_type{1} case 'parameter' - correction = Model.params(Model.pac.(pacmodl).growth_index)*Model.params(Model.pac.(pacmodl).growth_neutrality_param_index); + correction = Model.params(Model.pac.(pacmodl).growth_index(1))*Model.params(Model.pac.(pacmodl).growth_neutrality_param_index); case 'exogenous' - GrowthVariable = data{Model.exo_names{Model.pac.(pacmodl).growth_index}}; + GrowthVariable = data{Model.exo_names{Model.pac.(pacmodl).growth_index(1)}}; GrowthVariable = GrowthVariable(range).data; correction = GrowthVariable*Model.params(Model.pac.(pacmodl).growth_neutrality_param_index); case 'endogenous' - GrowthVariable = data{Model.endo_names{Model.pac.(pacmodl).growth_index}}.lag(abs(Model.pac.(pacmodl).growth_lag)); + GrowthVariable = data{Model.endo_names{Model.pac.(pacmodl).growth_index(1)}}.lag(abs(Model.pac.(pacmodl).growth_lag(1))); GrowthVariable = GrowthVariable(range).data; correction = GrowthVariable*Model.params(Model.pac.(pacmodl).growth_neutrality_param_index); otherwise error('Not yet implemented.') end end - PacExpectations = PacExpectations+correction; \ No newline at end of file + PacExpectations = PacExpectations+correction; diff --git a/matlab/print_expectations.m b/matlab/print_expectations.m index 3fec43fb7..8d310eefa 100644 --- a/matlab/print_expectations.m +++ b/matlab/print_expectations.m @@ -307,23 +307,28 @@ for i=1:maxlag end if isequal(id, 1) if isequal(expectationmodelkind, 'pac') && growth_correction + if numel(expectationmodel.growth_type) > 1 || ... + expectationmodel.growth_constant(1) ~= 1 || ... + expectationmodel.growth_param_id(1) ~= 0 + error('Linear combinations in growth parameter are not yet supported') + end pgrowth = M_.params(expectationmodel.growth_neutrality_param_index); vgrowth = expectationmodel.growth_str; - switch expectationmodel.growth_type + switch expectationmodel.growth_type{1} case 'parameter' vgrowth = M_.params(strcmp(vgrowth, M_.param_names)); otherwise vgrowth = regexprep(vgrowth, '\<(?!diff\>)\<(?!log\>)\<(?!\d\>)\w+', 'dbase.$0'); end if parameter>=0 - switch expectationmodel.growth_type + switch expectationmodel.growth_type{1} case 'parameter' expression = sprintf('%s*%s+%s*%s', num2str(pgrowth, '%1.16f'), num2str(vgrowth, '%1.16f'), num2str(parameter, '%1.16f'), variable); otherwise expression = sprintf('%s*%s+%s*%s', num2str(pgrowth, '%1.16f'), vgrowth, num2str(parameter, '%1.16f'), variable); end else - switch expectationmodel.growth_type + switch expectationmodel.growth_type{1} case 'parameter' expression = sprintf('%s*%s-%s*%s', num2str(pgrowth, '%1.16f'), num2str(vgrowth, '%1.16f'), num2str(-parameter, '%1.16f'), variable); otherwise @@ -348,4 +353,4 @@ fclose(fid); fprintf('Expectation dseries expression is saved in %s.\n', filename); -skipline(); \ No newline at end of file +skipline();