From 16d8ee0c7b79a43d5adc8b26f87fe1f6380a21a3 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Fri, 25 Mar 2016 20:20:28 +0100 Subject: [PATCH 1/5] Cosmetic changes to various function headers --- matlab/dynare_estimation_init.m | 4 ++-- matlab/evaluate_static_model.m | 6 +++--- matlab/initial_estimation_checks.m | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index 3166f1f3a..8e4546de5 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -1,6 +1,6 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, bounds] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_) -% function dynare_estimation_init(var_list_, gsa_flag) +% function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, bounds] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_) % performs initialization tasks before estimation or % global sensitivity analysis % @@ -14,7 +14,6 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, % estim_params_: structure storing information about estimated % parameters % bayestopt_: structure storing information about priors -% optim: structure storing optimization bounds % OUTPUTS % dataset_: the dataset after required transformation @@ -28,6 +27,7 @@ function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_, % estim_params_: structure storing information about estimated % parameters % bayestopt_: structure storing information about priors +% bounds: structure containing prior bounds % % SPECIAL REQUIREMENTS % none diff --git a/matlab/evaluate_static_model.m b/matlab/evaluate_static_model.m index a65e093e7..922517964 100644 --- a/matlab/evaluate_static_model.m +++ b/matlab/evaluate_static_model.m @@ -1,7 +1,7 @@ function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,options) -% function [ys,info] = evaluate_steady_state(M,options,oo) -% Computes the steady state +% function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,options) +% Evaluates the static model % % INPUTS % ys vector initial values used to compute the steady @@ -20,7 +20,7 @@ function [residuals,check1,jacob] = evaluate_static_model(ys,exo_ss,params,M,opt % SPECIAL REQUIREMENTS % none -% Copyright (C) 2001-2012 Dynare Team +% Copyright (C) 2001-2016 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 86e17fba1..af22e27bc 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -1,5 +1,5 @@ function DynareResults = initial_estimation_checks(objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,BoundsInfo,DynareResults) -% function initial_estimation_checks(xparam1,gend,data,data_index,number_of_observations,no_more_missing_observations) +% function DynareResults = initial_estimation_checks(objective_function,xparam1,DynareDataset,DatasetInfo,Model,EstimatedParameters,DynareOptions,BayesInfo,BoundsInfo,DynareResults) % Checks data (complex values, ML evaluation, initial values, BK conditions,..) % % INPUTS @@ -11,6 +11,7 @@ function DynareResults = initial_estimation_checks(objective_function,xparam1,Dy % EstimatedParameters [structure] characterizing parameters to be estimated % DynareOptions [structure] describing the options % BayesInfo [structure] describing the priors +% BoundsInfo [structure] containing prior bounds % DynareResults [structure] storing the results % % OUTPUTS From 69e8535a91ae236b22cf20ac4aa9bc658e04f070 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 27 Mar 2016 19:45:10 +0200 Subject: [PATCH 2/5] Add missing author name in NK_baseline.mod --- examples/NK_baseline.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/NK_baseline.mod b/examples/NK_baseline.mod index 1775508a1..d4a2f418a 100644 --- a/examples/NK_baseline.mod +++ b/examples/NK_baseline.mod @@ -1,6 +1,6 @@ /* * This file implements the Baseline New Keynesian DSGE model described in - * much detail in Jesús Fernández-Villaverde (2006): "A Baseline DSGE + * much detail in Jesús Fernández-Villaverde and Juan F. Rubio-Ramírez (2006): "A Baseline DSGE * Model", available at http://economics.sas.upenn.edu/~jesusfv/benchmark_DSGE.pdf * * The parametrization is based on the estimated version of this model in From f37d3afb149f505cc52a8d2d5a95af626a43c762 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 29 Mar 2016 15:25:51 +0200 Subject: [PATCH 3/5] Add headers for param_derivs-files --- preprocessor/DynamicModel.cc | 41 ++++++++++++++++++++++++++++++++++++ preprocessor/StaticModel.cc | 30 +++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 11ff41f0e..bf165209c 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -1536,6 +1536,7 @@ DynamicModel::writeDynamicMFile(const string &dynamic_basename) const << "% in M_.lead_lag_incidence; see the Manual" << endl << "% x [nperiods by M_.exo_nbr] double matrix of exogenous variables (in declaration order)" << endl << "% for all simulation periods" << endl + << "% steady_state [M_.endo_nbr by 1] double vector of steady state values" << endl << "% params [M_.param_nbr by 1] double vector of parameter values in declaration order" << endl << "% it_ scalar double time period for exogenous variables for which to evaluate the model" << endl << "%" << endl @@ -3980,6 +3981,46 @@ DynamicModel::writeParamsDerivativesFile(const string &basename, bool julia) con if (!julia) paramsDerivsFile << "function [rp, gp, rpp, gpp, hp] = " << basename << "_params_derivs(y, x, params, steady_state, it_, ss_param_deriv, ss_param_2nd_deriv)" << endl << "%" << endl + << "% Compute the derivatives of the dynamic model with respect to the parameters" << endl + << "% Inputs :" << endl + << "% y [#dynamic variables by 1] double vector of endogenous variables in the order stored" << endl + << "% in M_.lead_lag_incidence; see the Manual" << endl + << "% x [nperiods by M_.exo_nbr] double matrix of exogenous variables (in declaration order)" << endl + << "% for all simulation periods" << endl + << "% params [M_.param_nbr by 1] double vector of parameter values in declaration order" << endl + << "% steady_state [M_.endo_nbr by 1] double vector of steady state values" << endl + << "% it_ scalar double time period for exogenous variables for which to evaluate the model" << endl + << "% ss_param_deriv [M_.eq_nbr by #params] Jacobian matrix of the steady states values with respect to the parameters" << endl + << "% ss_param_2nd_deriv [M_.eq_nbr by #params by #params] Hessian matrix of the steady states values with respect to the parameters" << endl + << "%" << endl + << "% Outputs:" << endl + << "% rp [M_.eq_nbr by #params] double Jacobian matrix of dynamic model equations with respect to parameters " << endl + << "% Dynare may prepend or append auxiliary equations, see M_.aux_vars" << endl + << "% gp [M_.endo_nbr by #dynamic variables by #params] double Derivative of the Jacobian matrix of the dynamic model equations with respect to the parameters" << endl + << "% rows: equations in order of declaration" << endl + << "% columns: variables in order stored in M_.lead_lag_incidence" << endl + << "% rpp [#second_order_residual_terms by 4] double Hessian matrix of second derivatives of residuals with respect to parameters;" << endl + << "% rows: respective derivative term" << endl + << "% 1st column: equation number of the term appearing" << endl + << "% 2nd column: number of the first parameter in derivative" << endl + << "% 3rd column: number of the second parameter in derivative" << endl + << "% 4th column: value of the Hessian term" << endl + << "% gpp [#second_order_Jacobian_terms by 5] double Hessian matrix of second derivatives of the Jacobian with respect to the parameters;" << endl + << "% rows: respective derivative term" << endl + << "% 1st column: equation number of the term appearing" << endl + << "% 2nd column: column number of variable in Jacobian of the dynamic model" << endl + << "% 3rd column: number of the first parameter in derivative" << endl + << "% 4th column: number of the second parameter in derivative" << endl + << "% 5th column: value of the Hessian term" << endl + << "% hp [#first_order_Hessian_terms by 5] double Jacobian matrix of derivatives of the dynamic Hessian with respect to the parameters;" << endl + << "% rows: respective derivative term" << endl + << "% 1st column: equation number of the term appearing" << endl + << "% 2nd column: column number of first variable in Hessian of the dynamic model" << endl + << "% 3rd column: column number of second variable in Hessian of the dynamic model" << endl + << "% 4th column: number of the parameter in derivative" << endl + << "% 5th column: value of the Hessian term" << endl + << "%" << endl + << "%" << endl << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; else diff --git a/preprocessor/StaticModel.cc b/preprocessor/StaticModel.cc index 92aa43f64..4d41b6dac 100644 --- a/preprocessor/StaticModel.cc +++ b/preprocessor/StaticModel.cc @@ -1160,7 +1160,7 @@ StaticModel::writeStaticMFile(const string &func_name) const << "% Outputs:" << endl << "% residual [M_.endo_nbr by 1] double vector of residuals of the static model equations " << endl << "% in order of declaration of the equations." << endl - << "% Dynare may prepend auxiliary equations, see M_.aux_vars" << endl + << "% Dynare may prepend or append auxiliary equations, see M_.aux_vars" << endl << "% g1 [M_.endo_nbr by M_.endo_nbr] double Jacobian matrix of the static model equations;" << endl << "% columns: variables in declaration order" << endl << "% rows: equations in order of declaration" << endl @@ -2140,6 +2140,34 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons if (!julia) paramsDerivsFile << "function [rp, gp, rpp, gpp, hp] = " << basename << "_static_params_derivs(y, x, params)" << endl << "%" << endl + << "% Status : Computes derivatives of the static model with respect to the parameters" << endl + << "%" << endl + << "% Inputs : " << endl + << "% y [M_.endo_nbr by 1] double vector of endogenous variables in declaration order" << endl + << "% x [M_.exo_nbr by 1] double vector of exogenous variables in declaration order" << endl + << "% params [M_.param_nbr by 1] double vector of parameter values in declaration order" << endl + << "%" << endl + << "% Outputs:" << endl + << "% rp [M_.eq_nbr by #params] double Jacobian matrix of static model equations with respect to parameters " << endl + << "% Dynare may prepend or append auxiliary equations, see M_.aux_vars" << endl + << "% gp [M_.endo_nbr by M_.endo_nbr by #params] double Derivative of the Jacobian matrix of the static model equations with respect to the parameters" << endl + << "% rows: variables in declaration order" << endl + << "% rows: equations in order of declaration" << endl + << "% rpp [#second_order_residual_terms by 4] double Hessian matrix of second derivatives of residuals with respect to parameters;" << endl + << "% rows: respective derivative term" << endl + << "% 1st column: equation number of the term appearing" << endl + << "% 2nd column: number of the first parameter in derivative" << endl + << "% 3rd column: number of the second parameter in derivative" << endl + << "% 4th column: value of the Hessian term" << endl + << "% gpp [#second_order_Jacobian_terms by 5] double Hessian matrix of second derivatives of the Jacobian with respect to the parameters;" << endl + << "% rows: respective derivative term" << endl + << "% 1st column: equation number of the term appearing" << endl + << "% 2nd column: column number of variable in Jacobian of the static model" << endl + << "% 3rd column: number of the first parameter in derivative" << endl + << "% 4th column: number of the second parameter in derivative" << endl + << "% 5th column: value of the Hessian term" << endl + << "%" << endl + << "%" << endl << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; else From bf5a3ab6da8ce13958fa7e6a8f10723a1bd22611 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Tue, 29 Mar 2016 15:58:32 +0200 Subject: [PATCH 4/5] Add headers to identification routines --- matlab/getH.m | 34 ++++++++++++++++++++++++++-- matlab/getJJ.m | 39 +++++++++++++++++++++++++++++++- matlab/identification_analysis.m | 7 +++--- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/matlab/getH.m b/matlab/getH.m index fdf84c4e9..7af13ea10 100644 --- a/matlab/getH.m +++ b/matlab/getH.m @@ -1,8 +1,38 @@ function [H, dA, dOm, Hss, gp, d2A, d2Om, H2ss] = getH(A, B, M_,oo_,options_,kronflag,indx,indexo,iv) - +% function [H, dA, dOm, Hss, gp, d2A, d2Om, H2ss] = getH(A, B, M_,oo_,options_,kronflag,indx,indexo,iv) % computes derivative of reduced form linear model w.r.t. deep params % -% Copyright (C) 2010-2012 Dynare Team +% Inputs: +% A: Transition matrix of lagged states from Kalman filter +% B: Matrix in state transition equation mapping shocks today to +% states today +% M_: structure storing the model information +% oo_: structure storing the results +% options_: structure storing the options +% kronflag: Indicator whether to rely on Kronecker products (1) or +% not (-1 or -2) +% indx: Index of estimated parameters in M_.params +% indexo: Index of estimated standard deviations in M_.exo_names +% iv: Index of considered variables +% +% Outputs: +% H: dTAU/dTHETA: Jacobian of TAU, vectorized form of +% linearized reduced form state space model, given ys [steady state], +% A [transition matrix], B [matrix of shocks], Sigma [covariance of shocks] +% TAU = [ys; vec(A); dyn_vech(B*Sigma*B')]. +% dA: [endo_nbr by endo_nbr by (indx+indexo)] Jacobian of transition matrix A +% dOm: [endo_nbr by endo_nbr by (indx+indexo)] Jacobian of Omega = (B*Sigma*B') +% Hss: [endo_nbr by (indx)] Jacobian of steady state with respect to estimated +% structural parameters only (indx) +% gp: Jacobian of linear rational expectation matrices [i.e. +% Jacobian of dynamic model] with respect to estimated +% structural parameters only (indx) +% d2A: Hessian of transition matrix A +% d2Om: Hessian of Omega +% H2s: Hessian of steady state with respect to estimated +% structural parameters only (indx) + +% Copyright (C) 2010-2016 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/getJJ.m b/matlab/getJJ.m index 4b8130342..71361def6 100644 --- a/matlab/getJJ.m +++ b/matlab/getJJ.m @@ -1,6 +1,43 @@ function [JJ, H, gam, gp, dA, dOm, dYss] = getJJ(A, B, M_,oo_,options_,kronflag,indx,indexo,mf,nlags,useautocorr) +% function [JJ, H, gam, gp, dA, dOm, dYss] = getJJ(A, B, M_,oo_,options_,kronflag,indx,indexo,mf,nlags,useautocorr) +% computes derivatives of 1st and 2nd order moments of observables with +% respect to estimated parameters +% +% Inputs: +% A: Transition matrix of lagged states from Kalman filter +% B: Matrix in state transition equation mapping shocks today to +% states today +% M_: structure storing the model information +% oo_: structure storing the results +% options_: structure storing the options +% kronflag: Indicator whether to rely on Kronecker products (1) or +% not (-1 or -2) +% indx: Index of estimated parameters in M_.params +% indexo: Index of estimated standard deviations in M_.exo_names +% mf: Index of observed variables +% nlags: Number of lags to consider for covariances and +% correlations +% useautocorr: Indicator on whether to use correlations (1) instead of +% covariances (0) +% +% Outputs: +% JJ: Jacobian of 1st and 2nd order moments of observables, i.e. dgam/dTHETA +% (see below for definition of gam) +% H: dTAU/dTHETA: Jacobian of TAU, vectorized form of +% linearized reduced form state space model, given ys [steady state], +% A [transition matrix], B [matrix of shocks], Sigma [covariance of shocks] +% TAU = [ys; vec(A); dyn_vech(B*Sigma*B')]. +% gam: vector of theoretical moments of observed variables mf [JJ is the Jacobian of gam]. +% gam = [ys(mf); dyn_vech(GAM{1}); vec(GAM{j+1})]; for j=1:ar and where +% GAM is the first output of th_autocovariances +% gp: Jacobian of linear rational expectation matrices [i.e. +% Jacobian of dynamic model] with respect to estimated +% structural parameters only (indx) +% dA: [endo_nbr by endo_nbr by (indx+indexo)] Jacobian of transition matrix A +% dOm: Jacobian of Omega = (B*Sigma*B') +% dYss Jacobian of steady state with respect to estimated structural parameters only (indx) -% Copyright (C) 2010-2012 Dynare Team +% Copyright (C) 2010-2016 Dynare Team % % This file is part of Dynare. % diff --git a/matlab/identification_analysis.m b/matlab/identification_analysis.m index b948d91a1..21a3c1209 100644 --- a/matlab/identification_analysis.m +++ b/matlab/identification_analysis.m @@ -7,11 +7,12 @@ function [ide_hess, ide_moments, ide_model, ide_lre, derivatives_info, info] = i % o indx [array] index of estimated parameters % o indexo [array] index of estimated shocks % o options_ident [structure] identification options -% o data_info [structure] data info for Kalman Filter +% o dataset_ [structure] the dataset after required transformation +% o dataset_info [structure] Various informations about the dataset (descriptive statistics and missing observations) info for Kalman Filter % o prior_exist [integer] % =1 when prior exists and indentification is checked only for estimated params and shocks % =0 when prior is not defined and indentification is checked for all params and shocks -% o nem_tex [char] list of tex names +% o name_tex [char] list of tex names % o init [integer] flag for initialization of persistent vars % % OUTPUTS @@ -25,7 +26,7 @@ function [ide_hess, ide_moments, ide_model, ide_lre, derivatives_info, info] = i % SPECIAL REQUIREMENTS % None -% Copyright (C) 2008-2013 Dynare Team +% Copyright (C) 2008-2016 Dynare Team % % This file is part of Dynare. % From 00b605c0847553487e8aeeb9c17ed23b43798795 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sat, 2 Apr 2016 17:36:53 +0200 Subject: [PATCH 5/5] Correct and clarify manual on shock_decomposition command --- doc/dynare.texi | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/dynare.texi b/doc/dynare.texi index c06b434c0..de6c9b2d5 100644 --- a/doc/dynare.texi +++ b/doc/dynare.texi @@ -6308,8 +6308,11 @@ Posterior probability of the respective model @descriptionhead -This command computes and displays shock decomposition according to -the model for a given sample. +This command computes the historical shock decomposition for a given sample based on +the Kalman smoother, i.e. it decomposes the historical deviations of the endogenous +variables from their respective steady state values into the contribution coming +from the various shocks. The @code{variable_names} provided govern for which +variables the decomposition is plotted. Note that this command must come after either @code{estimation} (in case of an estimated model) or @code{stoch_simul} (in case of a calibrated @@ -6335,12 +6338,13 @@ calibrated model. @vindex oo_.shock_decomposition The results are stored in the field @code{oo_.shock_decomposition}, which is a three -dimensional array. The first dimension contains the endogenous variables for -which the shock decomposition has been requested. The second dimension stores +dimensional array. The first dimension contains the @code{M_.endo_nbr} endogenous variables. +The second dimension stores in the first @code{M_.exo_nbr} columns the contribution of the respective shocks. Column @code{M_.exo_nbr+1} stores the contribution of the initial conditions, while column @code{M_.exo_nbr+2} stores the smoothed value of the respective -endogenous variable. The third dimension stores the time periods. Both the variables +endogenous variable in deviations from their steady state, i.e. the mean and trends are +subtracted. The third dimension stores the time periods. Both the variables and shocks are stored in the order of declaration, i.e. @code{M_.endo_names} and @code{M_.exo_names}, respectively.