From 6ffeb2e9a4b026c76934f5c6e99d139177ac51e2 Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx.de>
Date: Mon, 23 Sep 2024 15:23:11 +0200
Subject: [PATCH] moments_varendo and prior_posterior_statistics: account for
 different paths of various posterior samplers

---
 matlab/estimation/PosteriorIRF.m              |  9 ++--
 matlab/estimation/ReshapeMatFiles.m           |  8 ++--
 .../check_posterior_analysis_data.m           |  4 +-
 ...al_variance_decomposition_ME_mc_analysis.m |  5 ++-
 ...ional_variance_decomposition_mc_analysis.m |  5 ++-
 matlab/estimation/correlation_mc_analysis.m   |  5 ++-
 matlab/estimation/covariance_mc_analysis.m    |  5 ++-
 ...tical_conditional_variance_decomposition.m | 16 +++----
 .../dsge_simulated_theoretical_correlation.m  |  6 ++-
 .../dsge_simulated_theoretical_covariance.m   | 16 +++----
 ...lated_theoretical_variance_decomposition.m | 16 +++----
 matlab/estimation/get_posterior_folder_name.m | 42 +++++++++++++++++++
 .../estimation/prior_posterior_statistics.m   |  3 +-
 .../prior_posterior_statistics_core.m         |  3 +-
 matlab/estimation/selec_posterior_draws.m     |  2 +-
 .../variance_decomposition_ME_mc_analysis.m   |  5 ++-
 .../variance_decomposition_mc_analysis.m      |  5 ++-
 17 files changed, 108 insertions(+), 47 deletions(-)
 create mode 100644 matlab/estimation/get_posterior_folder_name.m

diff --git a/matlab/estimation/PosteriorIRF.m b/matlab/estimation/PosteriorIRF.m
index d6cf33ea5..e5a9861ef 100644
--- a/matlab/estimation/PosteriorIRF.m
+++ b/matlab/estimation/PosteriorIRF.m
@@ -25,7 +25,7 @@ function oo_=PosteriorIRF(type,options_,estim_params_,oo_,M_,bayestopt_,dataset_
 % functions associated with it(the _core1 and _core2).
 % See also the comments posterior_sampler.m funtion.
 
-% Copyright © 2006-2023 Dynare Team
+% Copyright © 2006-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -83,12 +83,13 @@ end
 
 DirectoryName = CheckPath('Output',M_.dname);
 if strcmpi(type,'posterior')
-    MhDirectoryName = CheckPath('metropolis',M_.dname);
+    folder_name=get_posterior_folder_name(options_);
+    MhDirectoryName = CheckPath(folder_name,M_.dname);
 elseif strcmpi(type,'gsa')
     if options_.opt_gsa.pprior
-        MhDirectoryName = CheckPath(['GSA' filesep 'prior'],M_.dname);
+        MhDirectoryName = CheckPath(['gsa' filesep 'prior'],M_.dname);
     else
-        MhDirectoryName = CheckPath(['GSA' filesep 'mc'],M_.dname);
+        MhDirectoryName = CheckPath(['gsa' filesep 'mc'],M_.dname);
     end
 else
     MhDirectoryName = CheckPath('prior',M_.dname);
diff --git a/matlab/estimation/ReshapeMatFiles.m b/matlab/estimation/ReshapeMatFiles.m
index 58107602e..a4051bfb4 100644
--- a/matlab/estimation/ReshapeMatFiles.m
+++ b/matlab/estimation/ReshapeMatFiles.m
@@ -30,7 +30,7 @@ function ReshapeMatFiles(fname, dname, exo_nbr, endo_nbr, options_, type, type2)
 % SPECIAL REQUIREMENTS
 %    none
 
-% Copyright © 2003-2023 Dynare Team
+% Copyright © 2003-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -48,10 +48,12 @@ function ReshapeMatFiles(fname, dname, exo_nbr, endo_nbr, options_, type, type2)
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if nargin==6
-    MhDirectoryName = [ CheckPath('metropolis',dname) filesep ];
+    folder_name=get_posterior_folder_name(options_);
+    MhDirectoryName = [CheckPath(folder_name,dname) filesep ];
 else
     if strcmpi(type2,'posterior')
-        MhDirectoryName = [CheckPath('metropolis',dname) filesep ];
+        folder_name=get_posterior_folder_name(options_);
+        MhDirectoryName = [CheckPath(folder_name,dname) filesep ];
     elseif strcmpi(type2,'gsa')
         if options_.opt_gsa.morris==1
             MhDirectoryName = [CheckPath('gsa/screen',dname) filesep ];
diff --git a/matlab/estimation/check_posterior_analysis_data.m b/matlab/estimation/check_posterior_analysis_data.m
index 90c836afc..6de65d2de 100644
--- a/matlab/estimation/check_posterior_analysis_data.m
+++ b/matlab/estimation/check_posterior_analysis_data.m
@@ -67,10 +67,10 @@ if isempty(drawsinfo)
     end
     return
 else
-    mhname = get_name_of_the_last_mh_file(M_);
+    number_of_last_posterior_draws_file = length(drawsinfo);
     if ~issmc(options_)
+        mhname = get_name_of_the_last_mh_file(M_);
         mhdate = get_date_of_a_file([MetropolisFolder filesep mhname]);
-        number_of_last_posterior_draws_file = length(drawsinfo);
     else
         if ishssmc(options_)
             % Load draws from the posterior distribution
diff --git a/matlab/estimation/conditional_variance_decomposition_ME_mc_analysis.m b/matlab/estimation/conditional_variance_decomposition_ME_mc_analysis.m
index 6c787b0c8..f09dff723 100644
--- a/matlab/estimation/conditional_variance_decomposition_ME_mc_analysis.m
+++ b/matlab/estimation/conditional_variance_decomposition_ME_mc_analysis.m
@@ -23,7 +23,7 @@ function oo_ = ...
 % OUTPUTS
 %   oo_          [structure]        Dynare structure where the results are saved.
 
-% Copyright © 2017-2023 Dynare Team
+% Copyright © 2017-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -41,8 +41,9 @@ function oo_ = ...
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep ];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
diff --git a/matlab/estimation/conditional_variance_decomposition_mc_analysis.m b/matlab/estimation/conditional_variance_decomposition_mc_analysis.m
index ab4f7e77d..b84a7b64c 100644
--- a/matlab/estimation/conditional_variance_decomposition_mc_analysis.m
+++ b/matlab/estimation/conditional_variance_decomposition_mc_analysis.m
@@ -23,7 +23,7 @@ function oo_ = ...
 % OUTPUTS
 %   oo_          [structure]        Dynare structure where the results are saved.
 
-% Copyright © 2009-2018 Dynare Team
+% Copyright © 2009-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -41,8 +41,9 @@ function oo_ = ...
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
diff --git a/matlab/estimation/correlation_mc_analysis.m b/matlab/estimation/correlation_mc_analysis.m
index 94b10bb74..d4b8235ec 100644
--- a/matlab/estimation/correlation_mc_analysis.m
+++ b/matlab/estimation/correlation_mc_analysis.m
@@ -2,7 +2,7 @@ function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,v
 % This function analyses the (posterior or prior) distribution of the
 % endogenous variables correlation function.
 
-% Copyright © 2008-2017 Dynare Team
+% Copyright © 2008-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -20,8 +20,9 @@ function oo_ = correlation_mc_analysis(SampleSize,type,dname,fname,vartan,nvar,v
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
diff --git a/matlab/estimation/covariance_mc_analysis.m b/matlab/estimation/covariance_mc_analysis.m
index 92b7b451c..d0c4f77f7 100644
--- a/matlab/estimation/covariance_mc_analysis.m
+++ b/matlab/estimation/covariance_mc_analysis.m
@@ -19,7 +19,7 @@ function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,varta
 % OUTPUTS
 %   oo_                     [structure]        Dynare structure where the results are saved.
 
-% Copyright © 2008-2017 Dynare Team
+% Copyright © 2008-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -37,8 +37,9 @@ function oo_ = covariance_mc_analysis(NumberOfSimulations,type,dname,fname,varta
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
diff --git a/matlab/estimation/dsge_simulated_theoretical_conditional_variance_decomposition.m b/matlab/estimation/dsge_simulated_theoretical_conditional_variance_decomposition.m
index 6e052b6ec..c0ca04a89 100644
--- a/matlab/estimation/dsge_simulated_theoretical_conditional_variance_decomposition.m
+++ b/matlab/estimation/dsge_simulated_theoretical_conditional_variance_decomposition.m
@@ -19,7 +19,7 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
 %   vartan                           [char]     array of characters (with nvar rows).
 %   NumberOfConditionalDecompFiles   [integer]  scalar, number of prior or posterior data files (for covariance).
 
-% Copyright © 2009-2023 Dynare Team
+% Copyright © 2009-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -37,9 +37,11 @@ function [nvar,vartan,NumberOfConditionalDecompFiles] = ...
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 
+folder_name=get_posterior_folder_name(options_);
+
 % Get informations about the _posterior_draws files.
 if strcmpi(type,'posterior')
-    NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
+    NumberOfDrawsFiles = length(dir([M_.dname filesep folder_name filesep M_.fname '_' type '_draws*' ]));
     posterior = 1;
 elseif strcmpi(type,'prior')
     NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
@@ -51,8 +53,8 @@ end
 
 %delete old stale files before creating new ones
 if posterior
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition*'])
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecompositionME*'])
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_PosteriorConditionalVarianceDecomposition*'])
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_PosteriorConditionalVarianceDecompositionME*'])
 else
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition*'])
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecompositionME*'])
@@ -118,7 +120,7 @@ linea = 0;
 linea_ME = 0;
 for file = 1:NumberOfDrawsFiles
     if posterior
-        temp=load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
+        temp=load([M_.dname filesep folder_name filesep M_.fname '_' type '_draws' num2str(file) ]);
     else
         temp=load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
     end
@@ -146,7 +148,7 @@ for file = 1:NumberOfDrawsFiles
             ConditionalDecompFileNumber = ConditionalDecompFileNumber + 1;
             linea = 0;
             if posterior
-                save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
+                save([M_.dname filesep folder_name filesep M_.fname '_PosteriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
                      'Conditional_decomposition_array','endo_names');
             else
                 save([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecomposition' int2str(ConditionalDecompFileNumber) '.mat' ], ...
@@ -167,7 +169,7 @@ for file = 1:NumberOfDrawsFiles
                 ConditionalDecompFileNumber_ME = ConditionalDecompFileNumber_ME + 1;
                 linea_ME = 0;
                 if posterior
-                    save([M_.dname '/metropolis/' M_.fname '_PosteriorConditionalVarianceDecompME' int2str(ConditionalDecompFileNumber_ME) '.mat' ], ...
+                    save([M_.dname filesep folder_name filesep M_.fname '_PosteriorConditionalVarianceDecompME' int2str(ConditionalDecompFileNumber_ME) '.mat' ], ...
                          'Conditional_decomposition_array_ME','endo_names');
                 else
                     save([M_.dname '/prior/moments/' M_.fname '_PriorConditionalVarianceDecompME' int2str(ConditionalDecompFileNumber_ME) '.mat' ], ...
diff --git a/matlab/estimation/dsge_simulated_theoretical_correlation.m b/matlab/estimation/dsge_simulated_theoretical_correlation.m
index d874cb54b..7fa195a2c 100644
--- a/matlab/estimation/dsge_simulated_theoretical_correlation.m
+++ b/matlab/estimation/dsge_simulated_theoretical_correlation.m
@@ -18,7 +18,7 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(S
 %   vartan         [char]           array of characters (with nvar rows).
 %   CorrFileNumber [integer]        scalar, number of prior or posterior data files (for correlation).
 
-% Copyright © 2007-2021 Dynare Team
+% Copyright © 2007-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -38,9 +38,11 @@ function [nvar,vartan,CorrFileNumber] = dsge_simulated_theoretical_correlation(S
 [ivar,vartan] = get_variables_list(options_, M_);
 nvar = length(ivar);
 
+folder_name=get_posterior_folder_name(options_);
+
 % Get informations about the _posterior_draws files.
 if strcmpi(type,'posterior')
-    CorrFileNumber = length(dir([M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations*']));
+    CorrFileNumber = length(dir([M_.dname filesep folder_name filesep M_.fname '_PosteriorCorrelations*']));
 elseif strcmpi(type,'prior')
     CorrFileNumber = length(dir([M_.dname '/prior/moments/' M_.fname '_PriorCorrelations*']));
 else
diff --git a/matlab/estimation/dsge_simulated_theoretical_covariance.m b/matlab/estimation/dsge_simulated_theoretical_covariance.m
index 31d5a1486..cb976ff68 100644
--- a/matlab/estimation/dsge_simulated_theoretical_covariance.m
+++ b/matlab/estimation/dsge_simulated_theoretical_covariance.m
@@ -16,7 +16,7 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(S
 %   vartan            [char]     array of characters (with nvar rows).
 %   CovarFileNumber   [integer]  scalar, number of prior or posterior data files (for covariance).
 
-% Copyright © 2007-2021 Dynare Team
+% Copyright © 2007-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -35,9 +35,11 @@ function [nvar,vartan,CovarFileNumber] = dsge_simulated_theoretical_covariance(S
 
 nodecomposition = 1;
 
+folder_name=get_posterior_folder_name(options_);
+    
 % Get informations about the _posterior_draws files.
 if strcmpi(type,'posterior')
-    NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
+    NumberOfDrawsFiles = length(dir([M_.dname filesep folder_name filesep M_.fname '_' type '_draws*' ]));
     posterior = 1;
 elseif strcmpi(type,'prior')
     NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
@@ -49,8 +51,8 @@ end
 
 %delete old stale files before creating new ones
 if posterior
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments*'])
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations*']);
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_Posterior2ndOrderMoments*'])
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_PosteriorCorrelations*']);
 else
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments*'])
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorCorrelations*']);
@@ -112,7 +114,7 @@ linea_cov = 0;
 linea_corr = 0;
 for file = 1:NumberOfDrawsFiles
     if posterior
-        temp=load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
+        temp=load([M_.dname filesep folder_name filesep M_.fname '_' type '_draws' num2str(file) ]);
     else
         temp=load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
     end
@@ -148,7 +150,7 @@ for file = 1:NumberOfDrawsFiles
 
         if linea_cov == NumberOfCovarLines
             if posterior
-                save([ M_.dname '/metropolis/' M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix','endo_names');
+                save([ M_.dname filesep folder_name filesep M_.fname '_Posterior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix','endo_names');
             else
                 save([ M_.dname '/prior/moments/' M_.fname '_Prior2ndOrderMoments' int2str(CovarFileNumber) '.mat' ],'Covariance_matrix','endo_names');
             end
@@ -166,7 +168,7 @@ for file = 1:NumberOfDrawsFiles
         end
         if linea_corr == NumberOfCorrLines
             if posterior
-                save([ M_.dname '/metropolis/' M_.fname '_PosteriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array','endo_names');
+                save([ M_.dname filesep folder_name filesep M_.fname '_PosteriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array','endo_names');
             else
                 save([ M_.dname '/prior/moments/' M_.fname '_PriorCorrelations' int2str(CorrFileNumber) '.mat' ],'Correlation_array','endo_names');
             end
diff --git a/matlab/estimation/dsge_simulated_theoretical_variance_decomposition.m b/matlab/estimation/dsge_simulated_theoretical_variance_decomposition.m
index 880b27438..209efad68 100644
--- a/matlab/estimation/dsge_simulated_theoretical_variance_decomposition.m
+++ b/matlab/estimation/dsge_simulated_theoretical_variance_decomposition.m
@@ -18,7 +18,7 @@ function [nvar,vartan,NumberOfDecompFiles] = ...
 %   vartan            [char]     array of characters (with nvar rows).
 %   CovarFileNumber   [integer]  scalar, number of prior or posterior data files (for covariance).
 
-% Copyright © 2007-2021 Dynare Team
+% Copyright © 2007-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -37,9 +37,11 @@ function [nvar,vartan,NumberOfDecompFiles] = ...
 
 nodecomposition = 0;
 
+folder_name=get_posterior_folder_name(options_);
+
 % Get informations about the _posterior_draws files.
 if strcmpi(type,'posterior')
-    NumberOfDrawsFiles = length(dir([M_.dname '/metropolis/' M_.fname '_' type '_draws*' ]));
+    NumberOfDrawsFiles = length(dir([M_.dname filesep folder_name filesep M_.fname '_' type '_draws*' ]));
     posterior = 1;
 elseif strcmpi(type,'prior')
     NumberOfDrawsFiles = length(dir([M_.dname '/prior/draws/' type '_draws*' ]));
@@ -51,8 +53,8 @@ end
 
 %delete old stale files before creating new ones
 if posterior
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition*']);
-    delete_stale_file([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecompME*']);
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_PosteriorVarianceDecomposition*']);
+    delete_stale_file([M_.dname filesep folder_name filesep M_.fname '_PosteriorVarianceDecompME*']);
 else
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecomposition*']);
     delete_stale_file([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecompME*']);
@@ -122,7 +124,7 @@ linea_ME = 0;
 only_non_stationary_vars=0;
 for file = 1:NumberOfDrawsFiles
     if posterior
-        temp=load([M_.dname '/metropolis/' M_.fname '_' type '_draws' num2str(file) ]);
+        temp=load([M_.dname filesep folder_name filesep M_.fname '_' type '_draws' num2str(file) ]);
     else
         temp=load([M_.dname '/prior/draws/' type '_draws' num2str(file) ]);
     end
@@ -170,7 +172,7 @@ for file = 1:NumberOfDrawsFiles
         end
         if linea == NumberOfDecompLines
             if posterior
-                save([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array','endo_names');
+                save([M_.dname filesep folder_name filesep M_.fname '_PosteriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array','endo_names');
             else
                 save([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecomposition' int2str(DecompFileNumber) '.mat' ],'Decomposition_array','endo_names');
             end
@@ -189,7 +191,7 @@ for file = 1:NumberOfDrawsFiles
         if ME_present
             if linea_ME == NumberOfDecompLines_ME
                 if posterior
-                    save([M_.dname '/metropolis/' M_.fname '_PosteriorVarianceDecompME' int2str(DecompFileNumber_ME) '.mat' ],'Decomposition_array_ME','endo_names');
+                    save([M_.dname filesep folder_name filesep M_.fname '_PosteriorVarianceDecompME' int2str(DecompFileNumber_ME) '.mat' ],'Decomposition_array_ME','endo_names');
                 else
                     save([M_.dname '/prior/moments/' M_.fname '_PriorVarianceDecompME' int2str(DecompFileNumber_ME) '.mat' ],'Decomposition_array_ME','endo_names');
                 end
diff --git a/matlab/estimation/get_posterior_folder_name.m b/matlab/estimation/get_posterior_folder_name.m
new file mode 100644
index 000000000..25b86f1c8
--- /dev/null
+++ b/matlab/estimation/get_posterior_folder_name.m
@@ -0,0 +1,42 @@
+function folder_name=get_posterior_folder_name(options_)
+% function folder_name=get_posterior_folder_name(options_)
+% runs the estimation of the model
+%
+% INPUTS
+%   options_            [structure] describing the options
+%
+% OUTPUTS
+%   folder_name         [char]      output folder for different posterior
+%                                   samplers
+%
+% SPECIAL REQUIREMENTS
+%   none
+
+% Copyright © 2024 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 <https://www.gnu.org/licenses/>.
+
+if ~issmc(options_)
+    folder_name='metropolis';
+else
+    if ishssmc(options_)
+        folder_name='hssmc';
+    elseif isdime(options_)
+        folder_name='dime';
+    else
+        error('get_posterior_folder_name:: case should not happen. Please contact the developers')
+    end
+end
\ No newline at end of file
diff --git a/matlab/estimation/prior_posterior_statistics.m b/matlab/estimation/prior_posterior_statistics.m
index 7ff142419..8b98c63db 100644
--- a/matlab/estimation/prior_posterior_statistics.m
+++ b/matlab/estimation/prior_posterior_statistics.m
@@ -62,7 +62,8 @@ end
 maxlag = M_.maximum_endo_lag;
 
 if strcmpi(type,'posterior')
-    DirectoryName = CheckPath('metropolis',M_.dname);
+    folder_name=get_posterior_folder_name(options_);
+    DirectoryName = CheckPath(folder_name,M_.dname);
     B = options_.sub_draws;
 elseif strcmpi(type,'gsa')
     RootDirectoryName = CheckPath('gsa',M_.dname);
diff --git a/matlab/estimation/prior_posterior_statistics_core.m b/matlab/estimation/prior_posterior_statistics_core.m
index 65660dabb..5cf8f364e 100644
--- a/matlab/estimation/prior_posterior_statistics_core.m
+++ b/matlab/estimation/prior_posterior_statistics_core.m
@@ -119,7 +119,8 @@ end
 
 % DirectoryName = myinputs.DirectoryName;
 if strcmpi(type,'posterior')
-    DirectoryName = CheckPath('metropolis',M_.dname);
+    folder_name=get_posterior_folder_name(options_);
+    DirectoryName = CheckPath(folder_name,M_.dname);
 elseif strcmpi(type,'gsa')
     if options_.opt_gsa.pprior
         DirectoryName = CheckPath(['gsa',filesep,'prior'],M_.dname);
diff --git a/matlab/estimation/selec_posterior_draws.m b/matlab/estimation/selec_posterior_draws.m
index e001e1bc1..161f8e8e3 100644
--- a/matlab/estimation/selec_posterior_draws.m
+++ b/matlab/estimation/selec_posterior_draws.m
@@ -69,7 +69,7 @@ if ~issmc(options_)
     MetropolisFolder = CheckPath('metropolis',M_.dname);
 else
     if ishssmc(options_)
-        [MetropolisFolder] = CheckPath('metropolis',M_.dname);
+        [MetropolisFolder] = CheckPath('hssmc',M_.dname);
     elseif isdime(options_)
         [MetropolisFolder] = CheckPath('dime',M_.dname);
     else
diff --git a/matlab/estimation/variance_decomposition_ME_mc_analysis.m b/matlab/estimation/variance_decomposition_ME_mc_analysis.m
index 91939d23b..22c84544d 100644
--- a/matlab/estimation/variance_decomposition_ME_mc_analysis.m
+++ b/matlab/estimation/variance_decomposition_ME_mc_analysis.m
@@ -25,7 +25,7 @@ function oo_ = variance_decomposition_ME_mc_analysis(NumberOfSimulations,type,dn
 
 
 
-% Copyright © 2017 Dynare Team
+% Copyright © 2017-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -43,8 +43,9 @@ function oo_ = variance_decomposition_ME_mc_analysis(NumberOfSimulations,type,dn
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
diff --git a/matlab/estimation/variance_decomposition_mc_analysis.m b/matlab/estimation/variance_decomposition_mc_analysis.m
index d55de6989..a34a507cf 100644
--- a/matlab/estimation/variance_decomposition_mc_analysis.m
+++ b/matlab/estimation/variance_decomposition_mc_analysis.m
@@ -25,7 +25,7 @@ function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname
 
 
 
-% Copyright © 2008-2017 Dynare Team
+% Copyright © 2008-2024 Dynare Team
 %
 % This file is part of Dynare.
 %
@@ -43,8 +43,9 @@ function oo_ = variance_decomposition_mc_analysis(NumberOfSimulations,type,dname
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 if strcmpi(type,'posterior')
+    folder_name=get_posterior_folder_name(options_);
     TYPE = 'Posterior';
-    PATH = [dname '/metropolis/'];
+    PATH = [dname filesep folder_name filesep];
 else
     TYPE = 'Prior';
     PATH = [dname '/prior/moments/'];
-- 
GitLab