Contemporaneous correlations using different draws from the postierior

Hi,

I am wondering if it is possible in Dynare to draw from the posterior and compute contemporaneous correlations. I am interested in the sensitivity of my correlations to the parameters chosen and how much these correlations would vary if parameters would drawn from the posteriors.

Thanks,
J.

Yes, that is possible using a posterior_function. Search the forum on this.

1 Like

Thanks, Johannes. I will look into the function.

Hi Johannes,

Sorry to bother you again. I’ve gone through some of the other posts using posterior_function and got a working version of what I’d like to do. I am slightly confused by the outputs. I’ve downloaded the posterior_function_demo.m and changed the codes inside of the file to the following:

%% store the mean of the parameter draw
output_cell{1,1}=xparam1;

%% compute the steady state for the parameter draw and store it
% set the parameters draws to the model structure
M_ = set_all_parameters(xparam1,estim_params_,M_);
options_.noprint=1;
options_.drop=200;
options_.periods=1000;
var_list=char(‘Y’,‘R’);
[ys, oo_] = simult(oo_.dr.ys,oo_.dr,M_,options_,oo_);

oo_=disp_moments(ys,var_list,M_,options_,oo_);
% compute the steady state for the parameter draw written to M_
[ys,params,info] = evaluate_steady_state(oo_.steady_state,M_,options_,oo_,0);$

Two questions on the outputs:

  1. in my oo_. file, the simulation shows up as an exogenous simulation in exo_simul. What I was hoping to get are the endogenous responses to shocks for Y and R since the standard deviations of my shocks are in the estimated parameter vector. Are these the same things here? Or do I need to provide simult.m with the shocks.
  2. Can I use the contemporaneous_correlation here, as I would in the stoch_simul setting. I tried saving the oo_.contemporaneous_correlation as an output but received an error.

Thanks,
J.

Can you please provide me with the full files and tell me which output you want to retrieve?

Hi Johannes,

Thanks for the reply. Ideally, getting stochastic simulations for the endogenous variables based on different draws from the posterior would be acceptable (my shock variances are also estimated). I can compute the contemporaneous correlations from there. If I can use the contemporaneous_correlation command in this setting that would be even better.

Thanks,
J.

dsge.mod (2.4 KB) posterior_function_demo.m (3.1 KB) us_data.mat (4.2 KB)

Use

function output_cell =posterior_function_demo(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info)
% output_cell =posterior_function_demo(xparam1,M_,options_,oo_,estim_params_,bayestopt_,dataset_,dataset_info);
% This is an example file computing statistics on the prior/posterior draws. The
% function allows read-only access to all Dynare structures. However, those
% structures are local to this function.  Changing them will not affect
% other Dynare functions and you cannot use them to pass results to other
% Dynare functions.
% The function takes one and only one output argument: an 1 by n cell.
% Using functions like cell2mat, the contents of the cell can be easily
% transformed back to matrices. See the fs2000_posterior_function.mod for
% an example

% INPUTS
%   xparam1                      Current parameter draw
%   M_           [structure]     Matlab's structure describing the Model (initialized by dynare, see @ref{M_}).
%   options_     [structure]     Matlab's structure describing the options (initialized by dynare, see @ref{options_}).
%   oo_          [structure]     Matlab's structure gathering the results (initialized by dynare, see @ref{oo_}).
%   estim_params_[structure]     Matlab's structure describing the estimated_parameters (initialized by dynare, see @ref{estim_params_}).
%   bayestopt_   [structure]     Matlab's structure describing the parameter options (initialized by dynare, see @ref{bayestopt_}).
%   dataset_     [structure]     Matlab's structure storing the dataset
%   dataset_info [structure]     Matlab's structure storing the information about the dataset

% Output
%   output_cell  [1 by n cell]   1 by n Matlab cell allowing to store any
%                                desired computation or result (strings, matrices, structures, etc.)

% Copyright (C) 2015 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <http://www.gnu.org/licenses/>.


%% store the mean of the parameter draw
output_cell{1,1}=xparam1;

%% compute the steady state for the parameter draw and store it
% set the parameters draws to the model structure
M_ = set_all_parameters(xparam1,estim_params_,M_);
options_.noprint=1;
if isempty(options_.qz_criterium)
    options_.qz_criterium = 1+1e-6;
end

%get model solution at parameters
[dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
oo_.dr=dr;

var_list=char('yobs','iobs');
options_.contemporaneous_correlation=1;
oo_=disp_th_moments(oo_.dr,var_list,M_,options_,oo_);

%set second part of output cell
output_cell{1,2}=oo_.contemporaneous_correlation;
end
1 Like

Thanks, this works perfectly.

Much appreciated.