Commit 47ae5950 authored by adjemian's avatar adjemian
Browse files

Bug corrections : TeX output, oo_ structure (posterior density), posterior IRF.

Added : Posterior IRFs for BVAR-DSGE, conditional forecasts

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1119 ac1d8469-bf42-47a9-8791-bf33cf982152
parent be18e12a
......@@ -192,4 +192,4 @@ function [fval,cost_flag,ys,trend_coeff,info] = DsgeLikelihood(xparam1,gend,data
% Adds prior if necessary
% ------------------------------------------------------------------------------
lnprior = priordens(xparam1,bayestopt_.pshape,bayestopt_.p1,bayestopt_.p2,bayestopt_.p3,bayestopt_.p4);
fval = (likelihood-lnprior);
fval = (likelihood-lnprior);
\ No newline at end of file
function GetPosteriorParametersStatistics()
% stephane.adjemian@ens.fr [09-09-2005]
function get_posterior_parameters_statistics()
% This function prints and saves posterior estimates after the mcmc
% (+updates of oo_ & TeX output).
%
% INPUTS
% None.
%
% OUTPUTS
% None.
%
% ALGORITHM
% None.
%
% SPECIAL REQUIREMENTS
% None.
%
%
% part of DYNARE, copyright S. Adjemian, M. Juillard (2006)
% Gnu Public License.
global estim_params_ M_ options_ bayestopt_ oo_
TeX = options_.TeX;
......@@ -12,6 +29,8 @@ np = estim_params_.np ;
nx = nvx+nvn+ncx+ncn+np;
DirectoryName = CheckPath('metropolis');
OutputDirectoryName = CheckPath('Output');
load([ DirectoryName '/' M_.fname '_mh_history'])
FirstMhFile = record.KeepedDraws.FirstMhFile;
FirstLine = record.KeepedDraws.FirstLine; ifil = FirstLine;
......@@ -21,138 +40,199 @@ FirstMhFile = record.KeepedDraws.FirstMhFile;
NumberOfDraws = TotalNumberOfMhDraws-floor(options_.mh_drop*TotalNumberOfMhDraws);
clear record;
disp(' ')
disp(' ')
disp('ESTIMATION RESULTS')
disp(' ')
disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
pnames=[' ';'beta ';'gamm ';'norm ';'invg ';'unif ';'invg2'];
tit2 = sprintf('%10s %7s %10s %14s %4s %6s\n',' ','prior mean','post. mean','conf. interval','prior','pstdev');
pformat = '%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f';
disp(' ');disp(' ');disp('ESTIMATION RESULTS');disp(' ');
disp(sprintf('Log data density is %f.',oo_.MarginalDensity.ModifiedHarmonicMean))
if np
disp(' ')
disp('parameters')
disp(tit2)
ip = nvx+nvn+ncx+ncn+1;
for i=1:np
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
name = bayestopt_.name{ip};
disp(sprintf('%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f', ...
name, ...
bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pstdev(ip)));
eval(['oo_.posterior_mean.parameters.' name ' = post_mean;']);
eval(['oo_.posterior_hpdinf.parameters.' name ' = hpd_interval(1);']);
eval(['oo_.posterior_hpdsup.parameters.' name ' = hpd_interval(2);']);
eval(['oo_.posterior_median.' name ' = post_median;']);
eval(['oo_.posterior_variance.' name ' = post_var;']);
eval(['oo_.posterior_deciles.' name ' = post_deciles;']);
eval(['oo_.posterior_density.' name ' = density;']);
ip = ip+1;
end
if TeX
fid = TeXBegin(OutputDirectoryName,M_.fname,1,'parameters');
end
disp(' ')
disp('parameters')
disp(tit2)
ip = nvx+nvn+ncx+ncn+1;
for i=1:np
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
name = bayestopt_.name{ip};
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
oo_ = Filloo(oo_,name,'parameters',post_mean,hpd_interval,post_median,post_var,post_deciles,density);
if TeX
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
end
ip = ip+1;
end
if TeX
TeXEnd(fid,1,'parameters');
end
end
if nvx
ip = 1;
disp(' ')
disp('standard deviation of shocks')
disp(tit2)
for i=1:nvx
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k = estim_params_.var_exo(i,1);
name = deblank(M_.exo_names(k,:));
disp(sprintf('%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f', ...
name,bayestopt_.pmean(ip),post_mean, ...
hpd_interval,pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pstdev(ip)));
M_.Sigma_e(k,k) = post_mean*post_mean;
eval(['oo_.posterior_mean.shocks_std.' name ' = post_mean;']);
eval(['oo_.posterior_hpdinf.shocks_std.' name ' = hpd_interval(1);']);
eval(['oo_.posterior_hpdsup.shocks_std.' name ' = hpd_interval(2);']);
eval(['oo_.posterior_median.shocks_std.' name ' = post_median;']);
eval(['oo_.posterior_variance.shocks_std.' name ' = post_var;']);
eval(['oo_.posterior_deciles.shocks_std.' name ' = post_deciles;']);
eval(['oo_.posterior_density.shocks_std.' name ' = density;']);
ip = ip+1;
end
if TeX
fid = TeXBegin(OutputDirectoryName,M_.fname,2,'standard deviation of structural shocks');
end
ip = 1;
disp(' ')
disp('standard deviation of shocks')
disp(tit2)
for i=1:nvx
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k = estim_params_.var_exo(i,1);
name = deblank(M_.exo_names(k,:));
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval,...
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
M_.Sigma_e(k,k) = post_mean*post_mean;
oo_ = Filloo(oo_,name,'shocks_std',post_mean,hpd_interval,post_median,post_var,post_deciles,density);
if TeX
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
end
ip = ip+1;
end
if TeX
TeXEnd(fid,2,'standard deviation of structural shocks');
end
end
if nvn
disp(' ')
disp('standard deviation of measurement errors')
disp(tit2)
ip = nvx+1;
for i=1:nvn
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
disp(sprintf('%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f', ...
name,...
bayestopt_.pmean(ip), ...
post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pstdev(ip)));
eval(['oo_.posterior_mean.measurement_errors_std.' name ' = post_mean;']);
eval(['oo_.posterior_hpdinf.measurement_errors_std.' name ' = hpd_interval(1);']);
eval(['oo_.posterior_hpdsup.measurement_errors_std.' name ' = hpd_interval(2);']);
eval(['oo_.posterior_median.measurement_errors_std.' name ' = post_median;']);
eval(['oo_.posterior_variance.measurement_errors_std.' name ' = post_var;']);
eval(['oo_.posterior_deciles.measurement_errors_std.' name ' = post_deciles;']);
eval(['oo_.posterior_density.measurement_errors_std.' name ' = density;']);
ip = ip+1;
end
if TeX
fid = TeXBegin(OutputDirectoryName,M_.fname,3,'standard deviation of measurement errors')
end
disp(' ')
disp('standard deviation of measurement errors')
disp(tit2)
ip = nvx+1;
for i=1:nvn
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
name = deblank(options_.varobs(estim_params_.var_endo(i,1),:));
disp(sprintf(pformat,name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
oo_ = Filloo(oo_,name,'measurement_errors_std',post_mean,hpd_interval,post_median,...
post_var,post_deciles,density);
if TeX
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
end
ip = ip+1;
end
if TeX
TeXEnd(fid,3,'standard deviation of measurement errors');
end
end
if ncx
disp(' ')
disp('correlation of shocks')
disp(tit2)
ip = nvx+nvn+1;
for i=1:ncx
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k1 = estim_params_.corrx(i,1);
k2 = estim_params_.corrx(i,2);
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
disp(sprintf('%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f', name, ...
bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pstdev(ip)));
eval(['oo_.posterior_mean.shocks_corr.' NAME ' = post_mean;']);
eval(['oo_.posterior_hpdinf.shocks_corr.' NAME ' = hpd_interval(1);']);
eval(['oo_.posterior_hpdsup.shocks_corr.' NAME ' = hpd_interval(2);']);
eval(['oo_.posterior_median.shocks_corr.' NAME ' = post_median;']);
eval(['oo_.posterior_variance.shocks_corr.' NAME ' = post_var;']);
eval(['oo_.posterior_deciles.shocks_corr.' NAME ' = post_deciles;']);
eval(['oo_.posterior_density.shocks_corr.' NAME ' = density;']);
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
ip = ip+1;
end
if TeX
fid = TeXBegin(OutputDirectoryName,M_.fname,4,'correlation of structural shocks');
end
disp(' ')
disp('correlation of shocks')
disp(tit2)
ip = nvx+nvn+1;
for i=1:ncx
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k1 = estim_params_.corrx(i,1);
k2 = estim_params_.corrx(i,2);
name = [deblank(M_.exo_names(k1,:)) ',' deblank(M_.exo_names(k2,:))];
NAME = [deblank(M_.exo_names(k1,:)) '_' deblank(M_.exo_names(k2,:))];
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
oo_ = Filloo(oo_,NAME,'shocks_corr',post_mean,hpd_interval,post_median,post_var,post_deciles,density);
M_.Sigma_e(k1,k2) = post_mean*sqrt(M_.Sigma_e(k1,k1)*M_.Sigma_e(k2,k2));
M_.Sigma_e(k2,k1) = M_.Sigma_e(k1,k2);
if TeX
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
end
ip = ip+1;
end
if TeX
TeXEnd(fid,4,'correlation of structural shocks');
end
end
if ncn
disp(' ')
disp('correlation of measurement errors')
disp(tit2)
ip = nvx+nvn+ncx+1;
for i=1:ncn
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k1 = estim_params_.corrn(i,1);
k2 = estim_params_.corrn(i,2);
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
disp(sprintf('%12s %7.3f %8.4f %7.4f %7.4f %4s %6.4f', name, ...
bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pstdev(ip)));
eval(['oo_.posterior_mean.measurement_errors_corr.' NAME ' = post_mean;']);
eval(['oo_.posterior_hpdinf.measurement_errors_corr.' NAME ' = hpd_interval(1);']);
eval(['oo_.posterior_hpdsup.measurement_errors_corr.' NAME ' = hpd_interval(2);']);
eval(['oo_.posterior_median.measurement_errors_corr.' NAME ' = post_median;']);
eval(['oo_.posterior_variance.measurement_errors_corr.' NAME ' = post_var;']);
eval(['oo_.posterior_deciles.measurement_errors_corr.' NAME ' = post_decile;']);
eval(['oo_.posterior_density.measurement_errors_corr.' NAME ' = density;']);
ip = ip+1;
end
end
\ No newline at end of file
if TeX
fid = TeXBegin(OutputDirectoryName,M_.fname,5,'correlation of measurement errors');
end
disp(' ')
disp('correlation of measurement errors')
disp(tit2)
ip = nvx+nvn+ncx+1;
for i=1:ncn
Draws = GetAllPosteriorDraws(ip,FirstMhFile,FirstLine,TotalNumberOfMhFiles,NumberOfDraws);
[post_mean, post_median, post_var, hpd_interval, post_deciles, density] = posterior_moments(Draws,1);
k1 = estim_params_.corrn(i,1);
k2 = estim_params_.corrn(i,2);
name = [deblank(M_.endo_names(k1,:)) ',' deblank(M_.endo_names(k2,:))];
NAME = [deblank(M_.endo_names(k1,:)) '_' deblank(M_.endo_names(k2,:))];
disp(sprintf(pformat, name,bayestopt_.pmean(ip),post_mean,hpd_interval, ...
pnames(bayestopt_.pshape(ip)+1,:),bayestopt_.pstdev(ip)));
oo_ = Filloo(oo_,NAME,'measurement_errors_corr',post_mean,hpd_interval,...
post_median,post_var,post_deciles,density);
if TeX
TeXCore(fid,name,deblank(pnames(bayestopt_.pshape(ip)+1,:)),bayestopt_.pmean(ip),...
bayestopt_.pstdev(ip),post_mean,sqrt(post_var),hpd_interval);
end
ip = ip+1;
end
if TeX
TeXEnd(fid,5,'correlation of measurement errors');
end
end
%
%% subfunctions:
%
function fid = TeXBegin(directory,fname,fnum,title)
TeXfile = [directory '/' fname '_Posterior_Mean_' int2str(fnum) '.TeX'];
fidTeX = fopen(TeXfile,'w');
fprintf(fidTeX,'%% TeX-table generated by Dynare.\n');
fprintf(fidTeX,['%% RESULTS FROM METROPOLIS HASTINGS (' title ')\n']);
fprintf(fidTeX,['%% ' datestr(now,0)]);
fprintf(fidTeX,' \n');
fprintf(fidTeX,' \n');
fprintf(fidTeX,'\\begin{table}\n');
fprintf(fidTeX,'\\centering\n');
fprintf(fidTeX,'\\begin{tabular}{l|lcccccc} \n');
fprintf(fidTeX,'\\hline\\hline \\\\ \n');
fprintf(fidTeX,[' & Prior distribution & Prior mean & Prior ' ...
's.d. & Posterior mean & Posterior s.d. & HPD inf & HPD sup\\\\ \n']);
fprintf(fidTeX,'\\hline \\\\ \n');
fid = fidTeX;
function TeXCore(fid,name,shape,priormean,priorstd,postmean,poststd,hpd)
fprintf(fid,['$%s$ & %s & %7.3f & %6.4f & %7.3f& %6.4f & %7.4f & %7.4f \\\\ \n'],...
name,...
shape,...
priormean,...
priorstd,...
postmean,...
poststd,...
hpd(1),...
hpd(2));
function TeXEnd(fid,fnum,title)
fprintf(fid,'\\hline\\hline \n');
fprintf(fid,'\\end{tabular}\n ');
fprintf(fid,['\\caption{Results from Metropolis-Hastings (' title ')}\n ']);
fprintf(fid,['\\label{Table:MHPosterior:' int2str(fnum) '}\n']);
fprintf(fid,'\\end{table}\n');
fprintf(fid,'%% End of TeX file.\n');
fclose(fid);
function oo = Filloo(oo,name,type,postmean,hpdinterval,postmedian,postvar,postdecile,density)
eval(['oo.posterior_mean.' type '.' name ' = postmean;']);
eval(['oo.posterior_hpdinf.' type '.' name ' = hpdinterval(1);']);
eval(['oo.posterior_hpdsup.' type '.' name ' = hpdinterval(2);']);
eval(['oo.posterior_median.' type '.' name ' = postmedian;']);
eval(['oo.posterior_variance.' type '.' name ' = postvar;']);
eval(['oo.posterior_deciles.' type '.' name ' = postdecile;']);
eval(['oo.posterior_density.' type '.' name ' = density;']);
\ No newline at end of file
......@@ -88,8 +88,8 @@ for i=1:npar
else
j = i - (nvx+nvn+ncx+ncn);
name = deblank(M_.param_names(estim_params_.param_vals(j,1),:));
eval(['x1 = oo_.posterior_density.' name '(:,1);'])
eval(['f1 = oo_.posterior_density.' name '(:,2);'])
eval(['x1 = oo_.posterior_density.parameters.' name '(:,1);'])
eval(['f1 = oo_.posterior_density.parameters.' name '(:,2);'])
if options_.posterior_mode_estimation
eval(['pmode = oo_.posterior_mode.parameters.' name ';'])
end
......
This diff is collapsed.
......@@ -26,10 +26,14 @@ else
end
end
switch type
case 'irf'
CAPtype = 'IRF';
case 'irf_dsge'
CAPtype = 'IRF_DSGE';
TYPEsize = [ options_.irf , M_.endo_nbr , M_.exo_nbr ];
TYPEarray = 4;
TYPEarray = 4;
case 'irf_bvardsge'
CAPtype = 'IRF_BVARDSGE';
TYPEsize = [ options_.irf , size(options_.varobs,1) , M_.exo_nbr ];
TYPEarray = 4;
case 'smooth'
CAPtype = 'SMOOTH';
TYPEsize = [ M_.endo_nbr , options_.nobs ];
......@@ -59,7 +63,7 @@ end
return
end
TYPEfiles = dir([MhDirectoryName M_.fname '_' type '*']);
TYPEfiles = dir([MhDirectoryName M_.fname '_' type '*.mat']);
NumberOfTYPEfiles = length(TYPEfiles);
B = options_.B;
......@@ -98,9 +102,10 @@ end
%eval(['STOCK_' CAPtype ' = sort(stock_' type ',4);'])
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);
end
for file = 1:NumberOfTYPEfiles
delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
end
% Original file format may be useful in some cases...
% for file = 1:NumberOfTYPEfiles
% delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
% end
case 3
if NumberOfTYPEfiles>1
NumberOfPeriodsPerTYPEfiles = ceil( TYPEsize(2)/NumberOfTYPEfiles );
......@@ -132,7 +137,8 @@ end
%eval(['STOCK_' CAPtype ' = sort(stock_' type ',3);'])
save([MhDirectoryName M_.fname '_' CAPtype 's' int2str(1)],['STOCK_' CAPtype ]);
end
for file = 1:NumberOfTYPEfiles
delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
end
% Original file format may be useful in some cases...
% for file = 1:NumberOfTYPEfiles
% delete([MhDirectoryName M_.fname '_' type int2str(file) '.mat'])
% end
end
\ No newline at end of file
......@@ -650,7 +650,7 @@ OutputDirectoryName = CheckPath('Output');
if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior mode) Latex output
if np
filename = [OutputDirectoryName '\' M_.fname '_Posterior_Mode_1.TeX'];
filename = [OutputDirectoryName '/' M_.fname '_Posterior_Mode_1.TeX'];
fidTeX = fopen(filename,'w');
fprintf(fidTeX,'%% TeX-table generated by dynare_estimation (Dynare).\n');
fprintf(fidTeX,'%% RESULTS FROM POSTERIOR MAXIMIZATION (parameters)\n');
......@@ -670,7 +670,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
M_.param_names_tex(estim_params_.param_vals(i,1),:),...
deblank(pnames(bayestopt_.pshape(ip)+1,:)),...
bayestopt_.pmean(ip),...
estim_params_.param_vals(i,6),...
bayestopt_.pstdev(ip),...
xparam1(ip),...
stdh(ip));
ip = ip + 1;
......@@ -685,7 +685,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
fclose(fidTeX);
end
if nvx
TeXfile = [OutputDirectoryName '\' M_.fname '_Posterior_Mode_2.TeX'];
TeXfile = [OutputDirectoryName '/' M_.fname '_Posterior_Mode_2.TeX'];
fidTeX = fopen(TeXfile,'w');
fprintf(fidTeX,'%% TeX-table generated by dynare_estimation (Dynare).\n');
fprintf(fidTeX,'%% RESULTS FROM POSTERIOR MAXIMIZATION (standard deviation of structural shocks)\n');
......@@ -706,7 +706,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
deblank(M_.exo_names_tex(k,:)),...
deblank(pnames(bayestopt_.pshape(ip)+1,:)),...
bayestopt_.pmean(ip),...
estim_params_.var_exo(i,7),...
bayestopt_.pstdev(ip),...
xparam1(ip), ...
stdh(ip));
ip = ip+1;
......@@ -721,7 +721,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
fclose(fidTeX);
end
if nvn
TeXfile = [OutputDirectoryName '\' M_.fname '_Posterior_Mode_3.TeX'];
TeXfile = [OutputDirectoryName '/' M_.fname '_Posterior_Mode_3.TeX'];
fidTeX = fopen(TeXfile,'w');
fprintf(fidTeX,'%% TeX-table generated by dynare_estimation (Dynare).\n');
fprintf(fidTeX,'%% RESULTS FROM POSTERIOR MAXIMIZATION (standard deviation of measurement errors)\n');
......@@ -741,7 +741,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
deblank(M_.endo_names_tex(idx,:)), ...
deblank(pnames(bayestopt_.pshape(ip)+1,:)), ...
bayestopt_.pmean(ip), ...
estim_params_.var_endo(i,7),...
bayestopt_.pstdev(ip),...
xparam1(ip),...
stdh(ip));
ip = ip+1;
......@@ -755,7 +755,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
fclose(fidTeX);
end
if ncx
TeXfile = [OutputDirectoryName '\' M_.fname '_Posterior_Mode_4.TeX'];
TeXfile = [OutputDirectoryName '/' M_.fname '_Posterior_Mode_4.TeX'];
fidTeX = fopen(TeXfile,'w');
fprintf(fidTeX,'%% TeX-table generated by dynare_estimation (Dynare).\n');
fprintf(fidTeX,'%% RESULTS FROM POSTERIOR MAXIMIZATION (correlation of structural shocks)\n');
......@@ -776,7 +776,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
[deblank(M_.exo_names_tex(k1,:)) ',' deblank(M_.exo_names_tex(k2,:))], ...
deblank(pnames(bayestopt_.pshape(ip)+1,:)), ...
bayestopt_.pmean(ip), ...
estim_params_.corrx(i,8), ...
bayestopt_.pstdev(ip), ...
xparam1(ip), ...
stdh(ip));
ip = ip+1;
......@@ -790,7 +790,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
fclose(fidTeX);
end
if ncn
TeXfile = [OutputDirectoryName '\' M_.fname '_Posterior_Mode_5.TeX'];
TeXfile = [OutputDirectoryName '/' M_.fname '_Posterior_Mode_5.TeX'];
fidTeX = fopen(TeXfile,'w');
fprintf(fidTeX,'%% TeX-table generated by dynare_estimation (Dynare).\n');
fprintf(fidTeX,'%% RESULTS FROM POSTERIOR MAXIMIZATION (correlation of measurement errors)\n');
......@@ -811,7 +811,7 @@ if any(bayestopt_.pshape > 0) & options_.TeX %% Bayesian estimation (posterior m
[deblank(M_.endo_names_tex(k1,:)) ',' deblank(M_.endo_names_tex(k2,:))], ...
pnames(bayestopt_.pshape(ip)+1,:), ...
bayestopt_.pmean(ip), ...
estim_params_.corrn(i,8), ...
bayestopt_.pstdev(ip), ...
xparam1(ip), ...
stdh(ip));
ip = ip+1;
......
function icforecast(ptype,cV,cS,cL,H,mcValue,B,ci)
% stephane.adjemian@ens.fr
global options_ oo_ M_
xparam = get_posterior_parameters(ptype);
gend = options_.nobs;
% Read and demean data
rawdata = read_variables(options_.datafile,options_.varobs,[],options_.xls_sheet,options_.xls_range);
rawdata = rawdata(options_.first_obs:options_.first_obs+gend-1,:);
if options_.loglinear == 1 & ~options_.logdata
rawdata = log(rawdata);
end
if options_.prefilter == 1
bayestopt_.mean_varobs = mean(rawdata,1);
data = transpose(rawdata-ones(gend,1)*bayestopt_.mean_varobs);
else
data = transpose(rawdata);
end
set_parameters(xparam);
[atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff] = DsgeSmoother(xparam,gend,data);
InitState(:,1) = atT(:,end);
[T,R,ys,info] = dynare_resolve;
sQ = sqrt(M_.Sigma_e);
NumberOfStates = length(InitState);
FORCS1 = zeros(NumberOfStates,H+1,B);
for b=1:B
FORCS1(:,1,b) = InitState;
end
EndoSize = size(M_.endo_names,1);
ExoSize = size(M_.exo_names,1);
n1 = size(cV,1);
n2 = size(cS,1);
if n1 ~= n2
disp('imcforecast :: Error!')
disp(['imcforecast :: The number of variables doesn''t match the number of shocks'])
return
end
idx = [];
jdx = [];
for i = 1:n1
idx = [idx ; oo_.dr.inv_order_var(strmatch(deblank(cV(i,:)),M_.endo_names,'exact'))];
jdx = [jdx ; strmatch(deblank(cS(i,:)),M_.exo_names,'exact')];
end
mv = zeros(n1,NumberOfStates);
mu = zeros(ExoSize,n2);
for i=1:n1
mv(i,idx(i)) = 1;
mu(jdx(i),i) = 1;
end