From 01907c453039ceb170f52677d4a26cb73849a253 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 29 Apr 2024 18:13:44 +0200 Subject: [PATCH] Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod: compatibility fixes for recent Dynare versions --- Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod | 6 +++--- Born_Pfeifer_2014/smm_diff_function.m | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod b/Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod index f88ca39..6150d3c 100644 --- a/Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod +++ b/Born_Pfeifer_2014/Born_Pfeifer_RM_Comment.mod @@ -274,8 +274,8 @@ burnin=4000; //periods for convergence shocks_mat_with_zeros=zeros(burnin,M_.exo_nbr); //shocks set to 0 to simulate without uncertainty %% Note that simult_FGRU.m uses the original non-standard pruning scheme out_noshock = simult_FGRU(oo_.dr.ys,oo_.dr,shocks_mat_with_zeros,options_.order,zeros(size(oo_.dr.ys)),zeros(M_.exo_nbr,1)); //simulate series -%% To simulate serires with proper pruning scheme as in Andreasen et al. (2013), use the following code -% out_noshock = simult_(oo_.dr.ys,oo_.dr,shocks_mat_with_zeros,options_.order); //simulate series +%% To simulate series with proper pruning scheme as in Andreasen et al. (2013), use the following code +%out_noshock = simult_(M_,options_,oo_.dr.ys,oo_.dr,shocks_mat_with_zeros,options_.order); //simulate series log_deviations_SS_noshock=out_noshock-oo_.dr.ys*ones(1,burnin+M_.maximum_lag); //subtract steady state to get deviations from steady state ergodicmean_no_shocks=out_noshock(:,end); //EMAS is the final point @@ -539,7 +539,7 @@ eval(['print -depsc2 Current_Account',country_string,end_save_string]) //options_.qz_criterium = 1+1e-6; //required because it is empty by default, leading to a crash in k_order_pert [shock_mat]=generate_FGRU_shocks(estimation_replications,winsorizing_dummy); - [fhat,xhat] = csminwel(@smm_diff_function,x_start,H0,[],crit,nit,target,estimation_replications,shock_mat(:,:,1:estimation_replications)); + [fhat,xhat] = csminwel(@smm_diff_function,x_start,H0,[],crit,nit,target,estimation_replications,shock_mat(:,:,1:estimation_replications),M_,oo_,options_); @# endif diff --git a/Born_Pfeifer_2014/smm_diff_function.m b/Born_Pfeifer_2014/smm_diff_function.m index 44b4852..f3e14f8 100644 --- a/Born_Pfeifer_2014/smm_diff_function.m +++ b/Born_Pfeifer_2014/smm_diff_function.m @@ -1,5 +1,5 @@ -function [fval, simulated_moments]=smm_diff_function(xopt,target,replications,shocks) -% function [fval, simulated_moments]=smm_diff_function(xopt,target,replications,shocks) +function [fval, simulated_moments]=smm_diff_function(xopt,target,replications,shocks,M_,oo_,options_) +% function [fval, simulated_moments]=smm_diff_function(xopt,target,replications,shocks,M_,oo_,options_) % Computes the quadratic deviation of the simulated moments from the target % moments in the data % Inputs: @@ -30,7 +30,6 @@ % % For a copy of the GNU General Public License, see . -global oo_ M_ options_ % get Dynare structures; used to pass them on to resol.m tic %% simulate data from monthly model @@ -48,8 +47,14 @@ toc return end - -[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_); %run model solution in Dynare +dyn_ver = dynare_version; +if str2double(dyn_ver(1))< 5 + [oo_.dr, info, M_, options_, oo_] = resol(0, M_, options_, oo_); %get decision rules +elseif str2double(dyn_ver(1))< 6 + [oo_.dr,info,M_,oo_] = resol(0,M_,options_,oo_); %get decision rules +else + [oo_.dr,info] = resol(0,M_,options_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_steady_state); %get decision rules +end if info %solution was not successful fval=10e6+sum([xopt(1),xopt(2),xopt(3),log(xopt(4)) ].^2); %return with penalty