2008-06-21 10:33:31 +02:00
|
|
|
function [nvar,vartan,NumberOfDecompFiles] = ...
|
|
|
|
dsge_posterior_theoretical_variance_decomposition(SampleSize,M_,options_,oo_)
|
2007-10-12 19:02:04 +02:00
|
|
|
% This function estimates the posterior distribution of the variance
|
|
|
|
% decomposition of the observed endogenous variables.
|
|
|
|
%
|
|
|
|
% INPUTS
|
|
|
|
% None.
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% None.
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
2008-05-19 15:22:57 +02:00
|
|
|
% Other matlab routines distributed with Dynare: set_stationary_variables_list.m
|
|
|
|
% CheckPath.m
|
|
|
|
% selec_posterior_draws.m
|
|
|
|
% set_parameters.m
|
|
|
|
% resol.m
|
|
|
|
% th_autocovariances.m
|
|
|
|
% posterior_moments.m
|
2007-10-12 19:02:04 +02:00
|
|
|
%
|
2008-01-17 16:47:36 +01:00
|
|
|
% part of DYNARE, copyright Dynare Team (2007-2008).
|
2007-10-12 19:02:04 +02:00
|
|
|
% Gnu Public License.
|
2008-01-17 16:47:36 +01:00
|
|
|
|
2007-10-12 19:02:04 +02:00
|
|
|
type = 'posterior';% To be defined as a input argument later...
|
|
|
|
|
|
|
|
% Set varlist (vartan)
|
2007-11-09 11:22:08 +01:00
|
|
|
[ivar,vartan] = set_stationary_variables_list;
|
2008-06-21 10:33:31 +02:00
|
|
|
nvar = length(ivar);
|
2007-10-12 19:02:04 +02:00
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
% Set the size of the auto-correlation function to zero.
|
|
|
|
nar = options_.ar;
|
|
|
|
options_.ar = 0;
|
2007-10-12 19:02:04 +02:00
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
% Get informations about the _posterior_draws files.
|
|
|
|
DrawsFiles = dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]);
|
|
|
|
NumberOfDrawsFiles = length(DrawsFiles);
|
2007-10-12 19:02:04 +02:00
|
|
|
|
|
|
|
nexo = M_.exo_nbr;
|
2008-06-21 10:33:31 +02:00
|
|
|
|
2007-10-12 19:02:04 +02:00
|
|
|
|
|
|
|
NumberOfDrawsFiles = rows(DrawsFiles);
|
|
|
|
NumberOfSavedElementsPerSimulation = nvar*(nexo+1);
|
|
|
|
MaXNumberOfDecompLines = ceil(options_.MaxNumberOfBytes/NumberOfSavedElementsPerSimulation/8);
|
|
|
|
|
|
|
|
if NumberOfSimulations<=MaXNumberOfDecompLines
|
|
|
|
Decomposition_array = zeros(NumberOfSimulations,nvar*(nexo+1));
|
|
|
|
NumberOfDecompFiles = 1;
|
|
|
|
else
|
|
|
|
Decomposition_array = zeros(MaXNumberOfDecompLines,nvar*(nexo+1));
|
|
|
|
NumberOfLinesInTheLastDecompFile = mod(NumberOfSimulations,MaXNumberOfDecompLines);
|
|
|
|
NumberOfDecompFiles = ceil(NumberOfSimulations/MaXNumberOfDecompLines);
|
|
|
|
end
|
|
|
|
|
|
|
|
NumberOfDecompLines = rows(Decomposition_array);
|
|
|
|
DecompFileNumber = 1;
|
|
|
|
|
|
|
|
|
|
|
|
% Compute total variances (covariances are not saved) and variances
|
|
|
|
% implied by each structural shock.
|
|
|
|
linea = 0;
|
|
|
|
for file = 1:NumberOfDrawsFiles
|
|
|
|
load([MhDirectoryName '/' DrawsFiles(file).name]);
|
2008-06-17 23:23:02 +02:00
|
|
|
isdrsaved = cols(pdraws)-1;
|
2007-10-12 19:02:04 +02:00
|
|
|
NumberOfDraws = rows(pdraws);
|
|
|
|
for linee = 1:NumberOfDraws
|
|
|
|
linea = linea+1;
|
2008-06-17 23:23:02 +02:00
|
|
|
if isdrsaved
|
|
|
|
dr = pdraws{linee,2};
|
|
|
|
else
|
|
|
|
set_parameters(pdraws{linee,1});
|
|
|
|
[dr,info] = resol(oo_.steady_state,0);
|
|
|
|
end
|
2008-06-21 10:33:31 +02:00
|
|
|
tmp = th_autocovariances(dr,ivar,M_,options_);
|
|
|
|
%for i=1:nvar
|
|
|
|
% Decomposition_array(linea,i) = tmp{1}(i,i);
|
|
|
|
%end
|
|
|
|
Decomposition_array(linea,:) = transpose(tmp{1});
|
2007-10-12 19:02:04 +02:00
|
|
|
for i=1:nvar
|
|
|
|
for j=1:nexo
|
|
|
|
Decomposition_array(linea,nvar+(i-1)*nexo+j) = tmp{2}(i,j);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if linea == NumberOfDecompLines
|
|
|
|
save([fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber)],'Decomposition_array');
|
|
|
|
DecompFileNumber = DecompFileNumber + 1;
|
|
|
|
linea = 0;
|
|
|
|
test = DecompFileNumber-NumberOfDecompFiles;
|
2008-06-17 23:23:02 +02:00
|
|
|
if ~test% Prepare the last round...
|
2007-10-12 19:02:04 +02:00
|
|
|
Decomposition_array = zeros(NumberOfLinesInTheLastDecompFile,nvar*(nexo+1));
|
|
|
|
NumberOfDecompLines = NumberOfLinesInTheLastDecompFile;
|
2008-06-17 23:23:02 +02:00
|
|
|
DecompFileNumber = DecompFileNumber - 1;
|
|
|
|
elseif test<0;
|
2007-10-12 19:02:04 +02:00
|
|
|
Decomposition_array = zeros(MaXNumberOfDecompLines,nvar*(nexo+1));
|
|
|
|
else
|
|
|
|
clear('Decomposition_array');
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-06-17 23:23:02 +02:00
|
|
|
|
2008-06-21 10:33:31 +02:00
|
|
|
options_.ar = nar;% Useless because options_ is not a global anymore...
|
2008-06-17 23:23:02 +02:00
|
|
|
|
|
|
|
function r = rows(M)
|
|
|
|
r = size(M,1);
|
|
|
|
|
|
|
|
function c = cols(M)
|
2008-06-21 10:33:31 +02:00
|
|
|
c = size(M,2);
|