From cc045caa6f0e6155d4b9e8e1cd2b38f558810ea9 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 11 May 2021 14:25:44 +0200 Subject: [PATCH] loglinear: Take care of non-logged lagged/leaded exogenous variables Closes: #1783 --- matlab/dynare.m | 6 +++--- matlab/simult_.m | 3 ++- matlab/store_smoother_results.m | 15 ++++++++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/matlab/dynare.m b/matlab/dynare.m index 6c9ba4fee..65be45884 100644 --- a/matlab/dynare.m +++ b/matlab/dynare.m @@ -281,10 +281,10 @@ try evalin('base',[fname '.driver']) ; catch ME W = evalin('base','whos'); - diary off - if ismember(fname,[W(:).name]) + diary off + if ismember(fname,{W(:).name}) error('Your base workspace already contains a variable with the same name as the mod-file. You need to delete it or rename the mod-file.') - else + else rethrow(ME) end end diff --git a/matlab/simult_.m b/matlab/simult_.m index 508af26e4..1ab1729cf 100644 --- a/matlab/simult_.m +++ b/matlab/simult_.m @@ -42,7 +42,8 @@ y_ = zeros(size(y0,1),iter+M_.maximum_lag); y_(:,1) = y0; if options_.loglinear && ~options_.logged_steady_state - dr.ys=log(dr.ys); + k = get_all_variables_but_lagged_leaded_exogenous(M_); + dr.ys(k)=log(dr.ys(k)); end if ~options_.k_order_solver || (options_.k_order_solver && options_.pruning) %if k_order_pert is not used or if we do not use Dynare++ with k_order_pert diff --git a/matlab/store_smoother_results.m b/matlab/store_smoother_results.m index 645289445..b53283412 100644 --- a/matlab/store_smoother_results.m +++ b/matlab/store_smoother_results.m @@ -79,6 +79,12 @@ end if options_.loglinear oo_.Smoother.loglinear = true; + if ~isempty(M_.aux_vars) % deal with lead/lag of exogenous variables + exo_lead_lag_index = M_.orig_endo_nbr + find(([M_.aux_vars.type] == 2) | ([M_.aux_vars.type] == 3)); + else + exo_lead_lag_index =[]; + end + else oo_.Smoother.loglinear = false; end @@ -137,6 +143,9 @@ if ~isempty(options_.nk) && options_.nk ~= 0 i_endo_declaration_order = oo_.dr.order_var(i_endo_in_dr_matrices); %get indices of smoothed variables in name vector if options_.loglinear %logged steady state must be used constant_all_variables=repmat(log(ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]); + if ~isempty(exo_lead_lag_index) && any(ismember(i_endo_declaration_order,exo_lead_lag_index)) % deal with lead/lag of exogenous variables + constant_all_variables(:,ismember(i_endo_declaration_order,exo_lead_lag_index),:)=repmat(ys(i_endo_declaration_order(ismember(i_endo_declaration_order,exo_lead_lag_index)))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]); + end elseif ~options_.loglinear %unlogged steady state must be used constant_all_variables=repmat((ys(i_endo_declaration_order))',[length(options_.filter_step_ahead),1,gend+max(options_.filter_step_ahead)]); end @@ -157,7 +166,11 @@ for i_endo_in_bayestopt_smoother_varlist=bayestopt_.smoother_saved_var_list' i_endo_declaration_order = oo_.dr.order_var(i_endo_in_dr); %get indices of smoothed variables in name vector %% Compute constant if options_.loglinear == 1 %logged steady state must be used - constant_current_variable=repmat(log(ys(i_endo_declaration_order)),gend,1); + if ~isempty(exo_lead_lag_index) && ismember(i_endo_declaration_order,exo_lead_lag_index)% deal with lead/lag of exogenous variables + constant_current_variable=repmat(ys(i_endo_declaration_order),gend,1); + else + constant_current_variable=repmat(log(ys(i_endo_declaration_order)),gend,1); + end elseif options_.loglinear == 0 %unlogged steady state must be used constant_current_variable=repmat((ys(i_endo_declaration_order)),gend,1); end