Disentangle computation and display of conditional_variance_decomposition

Previously, noprint suppressed the computation of conditional_variance_decomposition although it should only suppress its display. Also adds a dedicated field for the unconditional variance decomposition.
time-shift
Johannes Pfeifer 2014-04-07 11:32:39 +02:00
parent 4a8e737c7a
commit 6eb3a3d3ad
2 changed files with 65 additions and 78 deletions

View File

@ -50,43 +50,54 @@ z = [ m sd s2 ];
oo_.mean = m;
oo_.var = oo_.gamma_y{1};
if ~options_.noprint %options_.nomoments == 0
if options_.order == 2
title='APROXIMATED THEORETICAL MOMENTS';
else
title='THEORETICAL MOMENTS';
end
if options_.hp_filter
title = [title ' (HP filter, lambda = ' num2str(options_.hp_filter) ')'];
end
headers=char('VARIABLE','MEAN','STD. DEV.','VARIANCE');
labels = deblank(M_.endo_names(ivar,:));
lh = size(labels,2)+2;
dyntable(title,headers,labels,z,lh,11,4);
if M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
skipline()
if M_.exo_nbr > 1 && size(stationary_vars, 1) > 0
oo_.variance_decomposition=100*oo_.gamma_y{options_.ar+2};
if ~options_.noprint %options_.nomoments == 0
if options_.order == 2
title='APPROXIMATED VARIANCE DECOMPOSITION (in percent)';
title='APROXIMATED THEORETICAL MOMENTS';
else
title='VARIANCE DECOMPOSITION (in percent)';
title='THEORETICAL MOMENTS';
end
if options_.hp_filter
title = [title ' (HP filter, lambda = ' ...
num2str(options_.hp_filter) ')'];
title = [title ' (HP filter, lambda = ' num2str(options_.hp_filter) ')'];
end
headers = M_.exo_names;
headers(M_.exo_names_orig_ord,:) = headers;
headers = char(' ',headers);
lh = size(deblank(M_.endo_names(ivar(stationary_vars),:)),2)+2;
dyntable(title,headers,deblank(M_.endo_names(ivar(stationary_vars), ...
:)),100*oo_.gamma_y{options_.ar+2}(stationary_vars,:),lh,8,2);
headers=char('VARIABLE','MEAN','STD. DEV.','VARIANCE');
labels = deblank(M_.endo_names(ivar,:));
lh = size(labels,2)+2;
dyntable(title,headers,labels,z,lh,11,4);
skipline()
if options_.order == 2
title='APPROXIMATED VARIANCE DECOMPOSITION (in percent)';
else
title='VARIANCE DECOMPOSITION (in percent)';
end
if options_.hp_filter
title = [title ' (HP filter, lambda = ' ...
num2str(options_.hp_filter) ')'];
end
headers = M_.exo_names;
headers(M_.exo_names_orig_ord,:) = headers;
headers = char(' ',headers);
lh = size(deblank(M_.endo_names(ivar(stationary_vars),:)),2)+2;
dyntable(title,headers,deblank(M_.endo_names(ivar(stationary_vars), ...
:)),100*oo_.gamma_y{options_.ar+2}(stationary_vars,:),lh,8,2);
end
conditional_variance_steps = options_.conditional_variance_decomposition;
if length(conditional_variance_steps)
oo_ = display_conditional_variance_decomposition(conditional_variance_steps,...
ivar,dr,M_, ...
options_,oo_);
StateSpaceModel.number_of_state_equations = M_.endo_nbr;
StateSpaceModel.number_of_state_innovations = M_.exo_nbr;
StateSpaceModel.sigma_e_is_diagonal = M_.sigma_e_is_diagonal;
[StateSpaceModel.transition_matrix,StateSpaceModel.impulse_matrix] = kalman_transition_matrix(dr,(1:M_.endo_nbr)',M_.nstatic+(1:M_.nspred)',M_.exo_nbr);
StateSpaceModel.state_innovations_covariance_matrix = M_.Sigma_e;
StateSpaceModel.order_var = dr.order_var;
oo_.conditional_variance_decomposition = conditional_variance_decomposition(StateSpaceModel,conditional_variance_steps,ivar);
if options_.noprint == 0
display_conditional_variance_decomposition(oo_.conditional_variance_decomposition,conditional_variance_steps,...
ivar,M_,options_);
end
end
end

View File

@ -1,22 +1,19 @@
function oo_ = display_conditional_variance_decomposition(Steps, SubsetOfVariables, dr,M_,options_,oo_)
% This function computes the conditional variance decomposition of a given state space model
function display_conditional_variance_decomposition(conditional_decomposition_array,Steps,SubsetOfVariables,M_,options_)
% This function displays the conditional variance decomposition of a given state space model
% for a subset of endogenous variables.
%
% INPUTS
% StateSpaceModel [structure] Specification of the state space model.
% conditional_decomposition_array [matrix] Output matrix from compute_conditional_variance_decomposition
% Steps [integer] 1*h vector of dates.
% SubsetOfVariables [integer] 1*q vector of indices.
%
% M_ [structure] Dynare structure containing the
% Model description
% options_ [structure] Dynare structure containing the
% options
% OUTPUTS
% PackedConditionalVarianceDecomposition [double] n(n+1)/2*p matrix, where p is the number of state innovations and
% n is equal to length(SubsetOfVariables).
% none
%
% SPECIAL REQUIREMENTS
%
% [1] The covariance matrix of the state innovations needs to be diagonal.
% [2] In this version, absence of measurement errors is assumed...
% Copyright (C) 2010-2013 Dynare Team
% Copyright (C) 2010-2014 Dynare Team
%
% This file is part of Dynare.
%
@ -33,49 +30,28 @@ function oo_ = display_conditional_variance_decomposition(Steps, SubsetOfVariabl
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
endo_nbr = M_.endo_nbr;
exo_nbr = M_.exo_nbr;
StateSpaceModel.number_of_state_equations = M_.endo_nbr;
StateSpaceModel.number_of_state_innovations = exo_nbr;
StateSpaceModel.sigma_e_is_diagonal = M_.sigma_e_is_diagonal;
iv = (1:endo_nbr)';
ic = M_.nstatic+(1:M_.nspred)';
[StateSpaceModel.transition_matrix,StateSpaceModel.impulse_matrix] = kalman_transition_matrix(dr,iv,ic,exo_nbr);
StateSpaceModel.state_innovations_covariance_matrix = M_.Sigma_e;
StateSpaceModel.order_var = dr.order_var;
conditional_decomposition_array = conditional_variance_decomposition(StateSpaceModel,Steps,SubsetOfVariables );
if options_.noprint == 0
if options_.order == 2
skipline()
disp('APPROXIMATED CONDITIONAL VARIANCE DECOMPOSITION (in percent)')
else
skipline()
disp('CONDITIONAL VARIANCE DECOMPOSITION (in percent)')
end
if options_.order == 2
skipline()
disp('APPROXIMATED CONDITIONAL VARIANCE DECOMPOSITION (in percent)')
else
skipline()
disp('CONDITIONAL VARIANCE DECOMPOSITION (in percent)')
end
vardec_i = zeros(length(SubsetOfVariables),exo_nbr);
vardec_i = zeros(length(SubsetOfVariables),M_.exo_nbr);
for i=1:length(Steps)
disp(['Period ' int2str(Steps(i)) ':'])
for j=1:exo_nbr
for j=1:M_.exo_nbr
vardec_i(:,j) = 100*conditional_decomposition_array(:, ...
i,j);
end
if options_.noprint == 0
headers = M_.exo_names;
headers(M_.exo_names_orig_ord,:) = headers;
headers = char(' ',headers);
lh = size(deblank(M_.endo_names(SubsetOfVariables,:)),2)+2;
dyntable('',headers,...
deblank(M_.endo_names(SubsetOfVariables,:)),...
vardec_i,lh,8,2);
end
end
oo_.conditional_variance_decomposition = conditional_decomposition_array;
headers = M_.exo_names;
headers(M_.exo_names_orig_ord,:) = headers;
headers = char(' ',headers);
lh = size(deblank(M_.endo_names(SubsetOfVariables,:)),2)+2;
dyntable('',headers,...
deblank(M_.endo_names(SubsetOfVariables,:)),...
vardec_i,lh,8,2);
end