Commit dfbd10a5 authored by Michel Juillard's avatar Michel Juillard

added choice of parameter set to shock_decomposition. This corrects a bug when...

added choice of parameter set to shock_decomposition. This corrects a bug when shock_decomposition is requested after Metropolis iterations.
parent ea86e8ce
......@@ -307,8 +307,12 @@ options_.ms.draws_nbr_modified_harmonic_mean = 1000000;
options_.ms.thinning_factor = 1;
options_.ms.dirichlet_scale = [1.0 1.5 2.0];
% Shock decomposition
options_.parameter_set = [];
% initialize persistent variables in priordens()
priordens([],[],[],[],[],[],1);
% Set dynare random generator and seed.
set_dynare_seed('default');
\ No newline at end of file
set_dynare_seed('default');
function oo_ = shock_decomposition(M_,oo_,options_,varlist)
% function z = shock_decomposition(R,epsilon,varlist)
% function z = shock_decomposition(M_,oo_,options_,varlist)
% Computes shocks contribution to a simulated trajectory
%
% INPUTS
% R: mm*rr matrix of shock impact
% epsilon: rr*nobs matrix of shocks
% varlist: list of variables
% M_: [structure] Definition of the model
% oo_: [structure] Storage of results
% options_: [structure] Options
% varlist: [char] List of variables
%
% OUTPUTS
% z: nvar*rr*nobs shock decomposition
% oo_: [structure] Storage of results
%
% SPECIAL REQUIREMENTS
% none
......@@ -30,21 +31,36 @@ function oo_ = shock_decomposition(M_,oo_,options_,varlist)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
% indices of endogenous variables
if size(varlist,1) == 0
varlist = M_.endo_names(1:M_.orig_endo_nbr,:);
end
[i_var,nvar] = varlist_indices(varlist,M_.endo_names);
% number of variables
endo_nbr = M_.endo_nbr;
% number of shocks
nshocks = M_.exo_nbr;
% indices of endogenous variables
if size(varlist,1) == 0
varlist = M_.endo_names(1:M_.orig_endo_nbr,:);
% parameter set
parameter_set = options_.parameter_set;
if isempty(parameter_set)
if isfield(oo_,'posterior_mean')
parameter_set = 'posterior_mean';
elseif isfield(oo_,'posterior_mode')
parameter_set = 'posterior_mode';
else
error(['shock_decomposition: option parameter_set is not specified ' ...
'and posterior mode is not available'])
end
end
[i_var,nvar] = varlist_indices(varlist,M_.endo_names);
oo = evaluate_smoother(parameter_set);
% reduced form
dr = oo_.dr;
dr = oo.dr;
% data reordering
order_var = dr.order_var;
......@@ -57,13 +73,13 @@ B = dr.ghu;
% initialization
for i=1:nshocks
epsilon(i,:) = eval(['oo_.SmoothedShocks.' M_.exo_names(i,:)]);
epsilon(i,:) = eval(['oo.SmoothedShocks.' M_.exo_names(i,:)]);
end
gend = size(epsilon,2);
z = zeros(endo_nbr,nshocks+2,gend);
for i=1:endo_nbr
z(i,end,:) = eval(['oo_.SmoothedVariables.' M_.endo_names(i,:)]);
z(i,end,:) = eval(['oo.SmoothedVariables.' M_.endo_names(i,:)]);
end
maximum_lag = M_.maximum_lag;
......
......@@ -1601,7 +1601,7 @@ shock_decomposition_options_list : shock_decomposition_option COMMA shock_decomp
| shock_decomposition_option
;
shock_decomposition_option : o_parameters
shock_decomposition_option : o_parameter_set
| o_shocks
| o_labels
;
......@@ -1848,7 +1848,6 @@ o_parameter_set : PARAMETER_SET EQUAL PRIOR_MODE
{ driver.option_str("parameter_set", "posterior_median"); }
;
o_parameters : PARAMETERS EQUAL symbol {driver.option_str("parameters",$3);};
o_shocks : SHOCKS EQUAL '(' list_of_symbol_lists ')' { driver.option_symbol_list("shocks"); };
o_labels : LABELS EQUAL '(' symbol_list ')' { driver.option_symbol_list("labels"); };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment