2014-10-20 16:18:54 +02:00
function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, bounds] = dynare_estimation_init ( var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
2009-12-16 18:17:34 +01:00
2016-03-25 20:20:28 +01:00
% function [dataset_, dataset_info, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, bounds] = dynare_estimation_init(var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
2014-09-21 11:51:46 +02:00
% performs initialization tasks before estimation or
2009-12-16 18:17:34 +01:00
% global sensitivity analysis
2011-09-14 23:40:23 +02:00
%
2009-12-16 18:17:34 +01:00
% INPUTS
2014-09-19 16:20:43 +02:00
% var_list_: selected endogenous variables vector
% dname: alternative directory name
% gsa_flag: flag for GSA operation (optional)
% M_: structure storing the model information
% options_: structure storing the options
% oo_: structure storing the results
% estim_params_: structure storing information about estimated
% parameters
% bayestopt_: structure storing information about priors
2017-05-16 15:10:20 +02:00
2009-12-16 18:17:34 +01:00
% OUTPUTS
2014-09-19 16:20:43 +02:00
% dataset_: the dataset after required transformation
% dataset_info: Various informations about the dataset (descriptive statistics and missing observations).
% xparam1: initial value of estimated parameters as returned by
% set_prior() or loaded from mode-file
% hh: hessian matrix at the loaded mode (or empty matrix)
% M_: structure storing the model information
% options_: structure storing the options
% oo_: structure storing the results
% estim_params_: structure storing information about estimated
% parameters
% bayestopt_: structure storing information about priors
2016-03-25 20:20:28 +01:00
% bounds: structure containing prior bounds
2017-05-16 15:10:20 +02:00
%
2009-12-16 18:17:34 +01:00
% SPECIAL REQUIREMENTS
% none
2023-01-13 16:19:53 +01:00
% Copyright © 2003-2023 Dynare Team
2009-12-16 18:17:34 +01:00
%
% 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
2021-06-09 17:33:48 +02:00
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
2009-12-16 18:17:34 +01:00
2013-09-10 21:30:55 +02:00
hh = [ ] ;
2017-06-05 10:51:30 +02:00
xparam1 = [ ] ;
2013-09-10 21:30:55 +02:00
2011-09-14 23:40:23 +02:00
if isempty ( gsa_flag )
2017-10-06 09:18:55 +02:00
gsa_flag = false ;
2013-09-09 12:36:43 +02:00
else
% Decide if a DSGE or DSGE-VAR has to be estimated.
2017-10-10 10:05:59 +02:00
if ~ isempty ( strmatch ( ' dsge_prior_weight' , M_ . param_names ) )
2011-02-25 09:27:33 +01:00
options_ . dsge_var = 1 ;
end
2017-10-06 09:18:55 +02:00
if isempty ( var_list_ )
var_list_ = check_list_of_variables ( options_ , M_ , var_list_ ) ;
options_ . varlist = var_list_ ;
end
if gsa_flag
% Get the list of the endogenous variables for which posterior statistics wil be computed.
options_ . varlist = var_list_ ;
else
% This was done in dynare_estimation_1
end
2009-12-16 18:17:34 +01:00
end
2015-07-08 09:21:50 +02:00
if options_ . dsge_var && options_ . presample ~= 0
error ( ' DSGE-VAR does not support the presample option.' )
end
2013-09-09 14:54:28 +02:00
% Test if observed variables are declared.
2015-08-17 07:28:04 +02:00
if ~ isfield ( options_ , ' varobs' )
error ( ' VAROBS statement is missing!' )
2013-09-09 14:54:28 +02:00
end
2023-09-01 16:07:17 +02:00
% Checks on VAROBS
check_varobs_are_endo_and_declared_once ( options_ . varobs , M_ . endo_names ) ;
2015-08-17 07:28:04 +02:00
% Set the number of observed variables.
options_ . number_of_observed_variables = length ( options_ . varobs ) ;
2020-02-12 12:52:54 +01:00
if options_ . discretionary_policy
if options_ . order > 1
error ( ' discretionary_policy does not support order>1' ) ;
else
M_ = discretionary_policy_initialization ( M_ , options_ ) ;
end
end
2022-08-30 14:16:14 +02:00
% Check the perturbation order for pruning (k order perturbation based nonlinear filters are not yet implemented for k>3).
if options_ . order > 3 && options_ . particle . pruning
2019-12-20 11:27:09 +01:00
error ( ' Higher order nonlinear filters are not compatible with pruning option.' )
end
2009-12-16 18:17:34 +01:00
2016-06-16 10:57:11 +02:00
% analytical derivation is not yet available for kalman_filter_fast
if options_ . analytic_derivation && options_ . fast_kalman_filter
error ( [ ' estimation option conflict: analytic_derivation isn' ' t available ' ...
' for fast_kalman_filter' ] )
end
2016-08-22 23:31:02 +02:00
% fast kalman filter is only available with kalman_algo == 0,1,3
2023-01-13 16:19:53 +01:00
if options_ . fast_kalman_filter && ~ ismember ( options_ . kalman_algo , [ 0 , 1 , 3 ] )
error ( [ ' estimation option conflict: fast_kalman_filter is only available ' ...
2017-05-16 15:10:20 +02:00
' with kalman_algo = 0, 1 or 3' ] )
2016-06-16 10:57:11 +02:00
end
2013-09-09 14:05:56 +02:00
% Set options_.lik_init equal to 3 if diffuse filter is used or kalman_algo refers to a diffuse filter algorithm.
if isequal ( options_ . diffuse_filter , 1 ) || ( options_ . kalman_algo > 2 )
if isequal ( options_ . lik_init , 2 )
error ( [ ' options diffuse_filter, lik_init and/or kalman_algo have contradictory settings' ] )
2011-11-21 12:39:02 +01:00
else
options_ . lik_init = 3 ;
end
2009-12-16 18:17:34 +01:00
end
2016-10-02 09:26:30 +02:00
options_ = select_qz_criterium_value ( options_ ) ;
2011-02-21 11:20:26 +01:00
2011-09-14 23:40:23 +02:00
% Set options related to filtered variables.
2017-01-19 11:18:54 +01:00
if isequal ( options_ . filtered_vars , 0 ) && ~ isempty ( options_ . filter_step_ahead )
options_ . filtered_vars = 1 ;
end
2011-09-14 23:40:23 +02:00
if ~ isequal ( options_ . filtered_vars , 0 ) && isempty ( options_ . filter_step_ahead )
2011-02-21 11:20:26 +01:00
options_ . filter_step_ahead = 1 ;
end
2011-06-08 22:06:41 +02:00
if ~ isequal ( options_ . filtered_vars , 0 ) && isequal ( options_ . filter_step_ahead , 0 )
2009-12-16 18:17:34 +01:00
options_ . filter_step_ahead = 1 ;
end
2011-06-08 22:06:41 +02:00
if ~ isequal ( options_ . filter_step_ahead , 0 )
2009-12-16 18:17:34 +01:00
options_ . nk = max ( options_ . filter_step_ahead ) ;
end
2011-09-14 23:40:23 +02:00
% Set the name of the directory where (intermediary) results will be saved.
if isempty ( dname )
M_ . dname = M_ . fname ;
2011-02-21 11:20:26 +01:00
else
2011-09-14 23:40:23 +02:00
M_ . dname = dname ;
2011-02-21 11:20:26 +01:00
end
2009-12-16 18:17:34 +01:00
2011-09-14 23:40:23 +02:00
% Set priors over the estimated parameters.
2016-08-17 21:47:46 +02:00
if ~ isempty ( estim_params_ ) && ~ ( isfield ( estim_params_ , ' nvx' ) && ( size ( estim_params_ . var_exo , 1 ) + size ( estim_params_ . var_endo , 1 ) + size ( estim_params_ . corrx , 1 ) + size ( estim_params_ . corrn , 1 ) + size ( estim_params_ . param_vals , 1 ) ) == 0 )
2011-02-21 11:20:26 +01:00
[ xparam1 , estim_params_ , bayestopt_ , lb , ub , M_ ] = set_prior ( estim_params_ , M_ , options_ ) ;
2013-09-10 21:30:55 +02:00
end
2015-07-25 07:32:48 +02:00
if ~ isempty ( bayestopt_ ) && any ( bayestopt_ . pshape == 0 ) && any ( bayestopt_ . pshape ~= 0 )
2015-07-23 14:42:09 +02:00
error ( ' Estimation must be either fully ML or fully Bayesian. Maybe you forgot to specify a prior distribution.' )
end
2014-07-21 12:45:49 +02:00
% Check if a _prior_restrictions.m file exists
if exist ( [ M_ . fname ' _prior_restrictions.m' ] )
options_ . prior_restrictions . status = 1 ;
2014-07-28 13:00:31 +02:00
options_ . prior_restrictions . routine = str2func ( [ M_ . fname ' _prior_restrictions' ] ) ;
2014-07-21 12:45:49 +02:00
end
2013-09-10 21:30:55 +02:00
% Check that the provided mode_file is compatible with the current estimation settings.
2016-04-14 20:11:22 +02:00
if ~ isempty ( estim_params_ ) && ~ ( isfield ( estim_params_ , ' nvx' ) && sum ( estim_params_ . nvx + estim_params_ . nvn + estim_params_ . ncx + estim_params_ . ncn + estim_params_ . np ) == 0 ) && ~ isempty ( options_ . mode_file ) && ~ options_ . mh_posterior_mode_estimation
2023-09-01 16:04:06 +02:00
[ xparam1 , hh ] = check_mode_file ( xparam1 , hh , options_ , bayestopt_ ) ;
2013-09-10 21:30:55 +02:00
end
2014-07-20 12:46:14 +02:00
%check for calibrated covariances before updating parameters
2016-04-14 20:11:22 +02:00
if ~ isempty ( estim_params_ ) && ~ ( isfield ( estim_params_ , ' nvx' ) && sum ( estim_params_ . nvx + estim_params_ . nvn + estim_params_ . ncx + estim_params_ . ncn + estim_params_ . np ) == 0 )
2023-10-07 16:34:22 +02:00
estim_params_ = check_for_calibrated_covariances ( estim_params_ , M_ ) ;
2014-07-20 12:46:14 +02:00
end
%%read out calibration that was set in mod-file and can be used for initialization
xparam1_calib = get_all_parameters ( estim_params_ , M_ ) ; %get calibrated parameters
if ~ any ( isnan ( xparam1_calib ) ) %all estimated parameters are calibrated
2015-07-21 16:18:15 +02:00
estim_params_ . full_calibration_detected = 1 ;
2014-07-20 12:46:14 +02:00
else
2015-07-21 16:18:15 +02:00
estim_params_ . full_calibration_detected = 0 ;
2014-07-20 12:46:14 +02:00
end
if options_ . use_calibration_initialization %set calibration as starting values
2015-07-31 11:15:31 +02:00
if ~ isempty ( bayestopt_ ) && all ( bayestopt_ . pshape == 0 ) && any ( all ( isnan ( [ xparam1_calib xparam1 ] ) , 2 ) )
error ( ' Estimation: When using the use_calibration option with ML, the parameters must be properly initialized.' )
else
[ xparam1 , estim_params_ ] = do_parameter_initialization ( estim_params_ , xparam1_calib , xparam1 ) ; %get explicitly initialized parameters that have precedence to calibrated values
end
2014-07-20 12:46:14 +02:00
end
2017-06-05 10:51:30 +02:00
if ~ isempty ( bayestopt_ ) && all ( bayestopt_ . pshape == 0 ) && any ( isnan ( xparam1 ) )
2017-05-26 09:40:37 +02:00
error ( ' ML estimation requires all estimated parameters to be initialized, either in an estimated_params or estimated_params_init-block ' )
end
2014-07-20 12:46:14 +02:00
2016-04-14 20:11:22 +02:00
if ~ isempty ( estim_params_ ) && ~ ( all ( strcmp ( fieldnames ( estim_params_ ) , ' full_calibration_detected' ) ) || ( isfield ( estim_params_ , ' nvx' ) && sum ( estim_params_ . nvx + estim_params_ . nvn + estim_params_ . ncx + estim_params_ . ncn + estim_params_ . np ) == 0 ) )
2013-09-18 11:33:14 +02:00
if ~ isempty ( bayestopt_ ) && any ( bayestopt_ . pshape > 0 )
2011-02-21 11:20:26 +01:00
% Plot prior densities.
2011-11-14 17:56:27 +01:00
if ~ options_ . nograph && options_ . plot_priors
2011-09-14 23:40:23 +02:00
plot_priors ( bayestopt_ , M_ , estim_params_ , options_ )
2010-01-05 11:46:10 +01:00
end
2011-02-21 11:20:26 +01:00
% Set prior bounds
2015-12-05 11:18:01 +01:00
bounds = prior_bounds ( bayestopt_ , options_ . prior_trunc ) ;
2014-10-20 16:18:54 +02:00
bounds . lb = max ( bounds . lb , lb ) ;
bounds . ub = min ( bounds . ub , ub ) ;
2013-09-18 11:23:47 +02:00
else % estimated parameters but no declared priors
2017-05-16 15:10:20 +02:00
% No priors are declared so Dynare will estimate the model by
% maximum likelihood with inequality constraints for the parameters.
2011-02-21 11:20:26 +01:00
options_ . mh_replic = 0 ; % No metropolis.
2014-10-20 16:18:54 +02:00
bounds . lb = lb ;
bounds . ub = ub ;
2013-09-18 11:23:47 +02:00
end
2013-09-18 11:33:14 +02:00
% Test if initial values of the estimated parameters are all between the prior lower and upper bounds.
2014-07-20 12:46:14 +02:00
if options_ . use_calibration_initialization
try
check_prior_bounds ( xparam1 , bounds , M_ , estim_params_ , options_ , bayestopt_ )
catch
e = lasterror ( ) ;
fprintf ( ' Cannot use parameter values from calibration as they violate the prior bounds.' )
rethrow ( e ) ;
end
else
check_prior_bounds ( xparam1 , bounds , M_ , estim_params_ , options_ , bayestopt_ )
2017-05-16 15:10:20 +02:00
end
2013-09-10 21:30:55 +02:00
end
2016-04-14 20:11:22 +02:00
if isempty ( estim_params_ ) || all ( strcmp ( fieldnames ( estim_params_ ) , ' full_calibration_detected' ) ) || ( isfield ( estim_params_ , ' nvx' ) && sum ( estim_params_ . nvx + estim_params_ . nvn + estim_params_ . ncx + estim_params_ . ncn + estim_params_ . np ) == 0 ) % If estim_params_ is empty (e.g. when running the smoother on a calibrated model)
2012-10-08 14:42:09 +02:00
if ~ options_ . smoother
2014-01-30 17:57:36 +01:00
error ( ' Estimation: the ' ' estimated_params' ' block is mandatory (unless you are running a smoother)' )
2012-10-08 14:42:09 +02:00
end
2009-12-16 18:17:34 +01:00
xparam1 = [ ] ;
bayestopt_ . jscale = [ ] ;
bayestopt_ . pshape = [ ] ;
2016-08-17 21:47:46 +02:00
bayestopt_ . name = [ ] ;
2009-12-16 18:17:34 +01:00
bayestopt_ . p1 = [ ] ;
bayestopt_ . p2 = [ ] ;
bayestopt_ . p3 = [ ] ;
bayestopt_ . p4 = [ ] ;
2011-02-21 11:20:26 +01:00
bayestopt_ . p5 = [ ] ;
bayestopt_ . p6 = [ ] ;
bayestopt_ . p7 = [ ] ;
2016-08-21 11:24:29 +02:00
estim_params_ . var_exo = [ ] ;
estim_params_ . var_endo = [ ] ;
estim_params_ . corrx = [ ] ;
estim_params_ . corrn = [ ] ;
estim_params_ . param_vals = [ ] ;
2009-12-16 18:17:34 +01:00
estim_params_ . nvx = 0 ;
estim_params_ . nvn = 0 ;
estim_params_ . ncx = 0 ;
estim_params_ . ncn = 0 ;
estim_params_ . np = 0 ;
2014-12-08 11:29:15 +01:00
bounds . lb = [ ] ;
bounds . ub = [ ] ;
2009-12-16 18:17:34 +01:00
end
2012-04-21 21:28:03 +02:00
% storing prior parameters in results
oo_ . prior . mean = bayestopt_ . p1 ;
2013-09-12 11:58:25 +02:00
oo_ . prior . mode = bayestopt_ . p5 ;
2012-04-21 21:28:03 +02:00
oo_ . prior . variance = diag ( bayestopt_ . p2 .^ 2 ) ;
2013-09-12 11:58:25 +02:00
oo_ . prior . hyperparameters . first = bayestopt_ . p6 ;
oo_ . prior . hyperparameters . second = bayestopt_ . p7 ;
2012-04-21 21:28:03 +02:00
2011-09-17 15:38:49 +02:00
% Is there a linear trend in the measurement equation?
2011-02-21 11:20:26 +01:00
if ~ isfield ( options_ , ' trend_coeffs' ) % No!
2009-12-16 18:17:34 +01:00
bayestopt_ . with_trend = 0 ;
2011-02-21 11:20:26 +01:00
else % Yes!
2009-12-16 18:17:34 +01:00
bayestopt_ . with_trend = 1 ;
bayestopt_ . trend_coeff = { } ;
2013-09-09 14:07:08 +02:00
for i = 1 : options_ . number_of_observed_variables
2015-03-01 15:12:34 +01:00
if i > length ( options_ . trend_coeffs )
2009-12-16 18:17:34 +01:00
bayestopt_ . trend_coeff { i } = ' 0' ;
else
2015-03-01 15:12:34 +01:00
bayestopt_ . trend_coeff { i } = options_ . trend_coeffs { i } ;
2009-12-16 18:17:34 +01:00
end
end
end
2011-09-17 15:38:49 +02:00
% Get informations about the variables of the model.
2023-10-08 22:08:57 +02:00
dr = set_state_space ( oo_ . dr , M_ ) ;
2011-02-21 11:20:26 +01:00
oo_ . dr = dr ;
2012-11-16 20:05:13 +01:00
nstatic = M_ . nstatic ; % Number of static variables.
npred = M_ . nspred ; % Number of predetermined variables.
nspred = M_ . nspred ; % Number of predetermined variables in the state equation.
2009-12-16 18:17:34 +01:00
2017-02-12 19:01:45 +01:00
%% Setting restricted state space (observed + predetermined variables)
2016-04-10 19:17:30 +02:00
% oo_.dr.restrict_var_list: location of union of observed and state variables in decision rules (decision rule order)
% bayestopt_.mfys: position of observables in oo_.dr.ys (declaration order)
% bayestopt_.mf0: position of state variables in restricted state vector (oo_.dr.restrict_var_list)
2017-02-12 19:01:45 +01:00
% bayestopt_.mf1: positions of observed variables in restricted state vector (oo_.dr.restrict_var_list order)
% bayestopt_.mf2: positions of observed variables in decision rules/expanded state vector (decision rule order)
2016-04-10 19:17:30 +02:00
% bayestopt_.smoother_var_list: positions of observed variables and requested smoothed variables in decision rules (decision rule order)
% bayestopt_.smoother_saved_var_list: positions of requested smoothed variables in bayestopt_.smoother_var_list
% bayestopt_.smoother_restrict_columns: positions of states in observed variables and requested smoothed variables in decision rules (decision rule order)
% bayestopt_.smoother_mf: positions of observed variables and requested smoothed variables in bayestopt_.smoother_var_list
2016-04-10 18:12:15 +02:00
var_obs_index_dr = [ ] ;
2009-12-16 18:17:34 +01:00
k1 = [ ] ;
2013-09-09 14:07:08 +02:00
for i = 1 : options_ . number_of_observed_variables
2017-10-10 10:05:59 +02:00
var_obs_index_dr = [ var_obs_index_dr ; strmatch ( options_ . varobs { i } , M_ . endo_names ( dr . order_var ) , ' exact' ) ] ;
k1 = [ k1 ; strmatch ( options_ . varobs { i } , M_ . endo_names , ' exact' ) ] ;
2009-12-16 18:17:34 +01:00
end
2011-06-21 13:23:06 +02:00
k3 = [ ] ;
k3p = [ ] ;
if options_ . selected_variables_only
2014-10-31 11:14:43 +01:00
if options_ . forecast > 0 && options_ . mh_replic == 0 && ~ options_ . load_mh_file
fprintf ( ' \nEstimation: The selected_variables_only option is incompatible with classical forecasts. It will be ignored.\n' )
k3 = ( 1 : M_ . endo_nbr ) ' ;
2017-05-16 15:10:20 +02:00
k3p = ( 1 : M_ . endo_nbr ) ' ;
2014-10-31 11:14:43 +01:00
else
2017-10-10 10:05:59 +02:00
for i = 1 : length ( var_list_ )
k3 = [ k3 ; strmatch ( var_list_ { i } , M_ . endo_names ( dr . order_var ) , ' exact' ) ] ;
k3p = [ k3 ; strmatch ( var_list_ { i } , M_ . endo_names , ' exact' ) ] ;
2014-10-31 11:14:43 +01:00
end
2011-06-21 13:23:06 +02:00
end
else
k3 = ( 1 : M_ . endo_nbr ) ' ;
k3p = ( 1 : M_ . endo_nbr ) ' ;
end
2011-02-21 11:20:26 +01:00
% Define union of observed and state variables
2023-01-13 16:19:53 +01:00
k2 = union ( var_obs_index_dr , [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , ' rows' ) ;
% Set restrict_state to postion of observed + state variables in expanded state vector.
oo_ . dr . restrict_var_list = k2 ;
% set mf0 to positions of state variables in restricted state vector for likelihood computation.
[ ~ , bayestopt_ . mf0 ] = ismember ( [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , k2 ) ;
% Set mf1 to positions of observed variables in restricted state vector for likelihood computation.
[ ~ , bayestopt_ . mf1 ] = ismember ( var_obs_index_dr , k2 ) ;
% Set mf2 to positions of observed variables in expanded state vector for filtering and smoothing.
bayestopt_ . mf2 = var_obs_index_dr ;
bayestopt_ . mfys = k1 ;
[ ~ , ic ] = intersect ( k2 , nstatic + ( 1 : npred ) ' ) ;
oo_ . dr . restrict_columns = [ ic ; length ( k2 ) + ( 1 : nspred - npred ) ' ] ;
bayestopt_ . smoother_var_list = union ( k2 , k3 ) ;
[ ~ , ~ , bayestopt_ . smoother_saved_var_list ] = intersect ( k3 , bayestopt_ . smoother_var_list ( : ) ) ;
[ ~ , ic ] = intersect ( bayestopt_ . smoother_var_list , nstatic + ( 1 : npred ) ' ) ;
bayestopt_ . smoother_restrict_columns = ic ;
[ ~ , bayestopt_ . smoother_mf ] = ismember ( var_obs_index_dr , bayestopt_ . smoother_var_list ) ;
2009-12-16 18:17:34 +01:00
2017-05-16 12:42:01 +02:00
if options_ . analytic_derivation
if options_ . lik_init == 3
2015-04-01 09:00:51 +02:00
error ( ' analytic derivation is incompatible with diffuse filter' )
end
2012-08-21 15:53:02 +02:00
options_ . analytic_derivation = 1 ;
2020-06-18 11:28:22 +02:00
if estim_params_ . np || isfield ( options_ , ' identification_check_endogenous_params_with_no_prior' )
2012-07-05 10:14:10 +02:00
% check if steady state changes param values
M = M_ ;
2020-06-18 11:28:22 +02:00
if isfield ( options_ , ' identification_check_endogenous_params_with_no_prior' )
M . params = M . params * 1.01 ; %vary parameters
else
M . params ( estim_params_ . param_vals ( : , 1 ) ) = xparam1 ( estim_params_ . nvx + estim_params_ . ncx + estim_params_ . nvn + estim_params_ . ncn + 1 : end ) ; %set parameters
M . params ( estim_params_ . param_vals ( : , 1 ) ) = M . params ( estim_params_ . param_vals ( : , 1 ) ) * 1.01 ; %vary parameters
end
2016-05-10 15:54:11 +02:00
if options_ . diffuse_filter || options_ . steadystate . nocheck
2012-07-05 10:14:10 +02:00
steadystate_check_flag = 0 ;
else
steadystate_check_flag = 1 ;
end
2023-06-07 17:18:18 +02:00
[ tmp1 , params ] = evaluate_steady_state ( oo_ . steady_state , [ oo_ . exo_steady_state ; oo_ . exo_det_steady_state ] , M , options_ , steadystate_check_flag ) ;
2012-07-05 10:14:10 +02:00
change_flag = any ( find ( params - M . params ) ) ;
2017-05-16 12:42:01 +02:00
if change_flag
skipline ( )
2014-10-29 09:02:29 +01:00
if any ( isnan ( params ) )
disp ( ' After computing the steadystate, the following parameters are still NaN: ' ) ,
2017-10-10 10:05:59 +02:00
disp ( char ( M . param_names ( isnan ( params ) ) ) )
2014-10-29 09:02:29 +01:00
end
if any ( find ( params ( ~ isnan ( params ) ) - M . params ( ~ isnan ( params ) ) ) )
disp ( ' The steadystate file changed the values for the following parameters: ' ) ,
2017-10-10 10:05:59 +02:00
disp ( char ( M . param_names ( find ( params ( ~ isnan ( params ) ) - M . params ( ~ isnan ( params ) ) ) ) ) )
2014-10-29 09:02:29 +01:00
end
2012-07-05 10:14:10 +02:00
disp ( ' The derivatives of jacobian and steady-state will be computed numerically' ) ,
disp ( ' (re-set options_.analytic_derivation_mode= -2)' ) ,
options_ . analytic_derivation_mode = - 2 ;
end
end
2012-04-27 15:57:58 +02:00
end
2022-05-31 21:23:57 +02:00
% If jscale isn't specified for an estimated parameter, use global option options_.jscale, set to optimal value for a normal distribution by default.
2016-06-10 20:08:09 +02:00
% Note that check_posterior_sampler_options and mode_compute=6 may overwrite the setting
2022-05-31 21:23:57 +02:00
if isempty ( options_ . mh_jscale )
options_ . mh_jscale = 2.38 / sqrt ( length ( xparam1 ) ) ;
end
2013-04-12 18:24:22 +02:00
k = find ( isnan ( bayestopt_ . jscale ) ) ;
bayestopt_ . jscale ( k ) = options_ . mh_jscale ;
2014-06-16 17:41:59 +02:00
% Build the dataset
2014-08-21 13:18:38 +02:00
if ~ isempty ( options_ . datafile )
[ pathstr , name , ext ] = fileparts ( options_ . datafile ) ;
if strcmp ( name , M_ . fname )
error ( ' Data-file and mod-file are not allowed to have the same name. Please change the name of the data file.' )
end
end
2017-03-20 20:29:19 +01:00
if isnan ( options_ . first_obs )
options_ . first_obs = 1 ;
end
2014-07-16 17:04:13 +02:00
[ dataset_ , dataset_info , newdatainterfaceflag ] = makedataset ( options_ , options_ . dsge_var * options_ . dsge_varlag , gsa_flag ) ;
2015-03-01 14:41:30 +01:00
%set options for old interface from the ones for new interface
2015-05-26 07:50:58 +02:00
if ~ isempty ( dataset_ )
options_ . nobs = dataset_ . nobs ;
2020-11-13 10:54:44 +01:00
if options_ . endogenous_prior
2023-08-23 09:32:24 +02:00
if ~ isnan ( dataset_info . missing . number_of_observations ) && ~ ( dataset_info . missing . number_of_observations == 0 ) %missing observations present
if dataset_info . missing . no_more_missing_observations < dataset_ . nobs - 10
fprintf ( ' \ndynare_estimation_init: There are missing observations in the data.\n' )
fprintf ( ' dynare_estimation_init: I am computing the moments for the endogenous prior only\n' )
fprintf ( ' dynare_estimation_init: on the observations after the last missing one, i.e. %u.\n' , dataset_info . missing . no_more_missing_observations )
else
fprintf ( ' \ndynare_estimation_init: There are too many missing observations in the data.\n' )
fprintf ( ' dynare_estimation_init: The endogenous_prior-option needs a consistent sample of \n' )
fprintf ( ' dynare_estimation_init: at least 10 full observations at the end.\n' )
error ( ' The endogenous_prior-option does not support your missing data.' )
end
2020-11-13 10:54:44 +01:00
end
end
2015-05-26 07:50:58 +02:00
end
2017-03-20 20:29:19 +01:00
2014-01-30 10:07:41 +01:00
% setting steadystate_check_flag option
2016-05-10 15:54:11 +02:00
if options_ . diffuse_filter || options_ . steadystate . nocheck
2011-11-01 18:23:12 +01:00
steadystate_check_flag = 0 ;
else
steadystate_check_flag = 1 ;
end
2014-06-16 17:41:59 +02:00
2017-10-03 14:09:19 +02:00
%check steady state at initial parameters
2011-12-14 21:05:48 +01:00
M = M_ ;
nvx = estim_params_ . nvx ;
ncx = estim_params_ . ncx ;
nvn = estim_params_ . nvn ;
ncn = estim_params_ . ncn ;
2013-06-21 12:42:38 +02:00
if estim_params_ . np
2017-05-16 15:10:20 +02:00
M . params ( estim_params_ . param_vals ( : , 1 ) ) = xparam1 ( nvx + ncx + nvn + ncn + 1 : end ) ;
2013-06-21 12:42:38 +02:00
end
2023-06-07 17:18:18 +02:00
[ oo_ . steady_state , params , info ] = evaluate_steady_state ( oo_ . steady_state , [ oo_ . exo_steady_state ; oo_ . exo_det_steady_state ] , M , options_ , steadystate_check_flag ) ;
2014-07-20 12:46:14 +02:00
if info ( 1 )
2017-06-11 10:58:19 +02:00
fprintf ( ' \ndynare_estimation_init:: The steady state at the initial parameters cannot be computed.\n' )
2017-10-11 09:57:04 +02:00
if options_ . debug
2019-12-20 16:28:06 +01:00
M . params = params ;
2017-10-11 09:57:04 +02:00
plist = list_of_parameters_calibrated_as_NaN ( M ) ;
if ~ isempty ( plist )
message = [ ' dynare_estimation_init:: Some of the parameters are NaN (' ] ;
2018-01-10 10:35:17 +01:00
for i = 1 : length ( plist )
if i < length ( plist )
message = [ message , plist { i } ' , ' ] ;
2017-10-11 09:57:04 +02:00
else
2018-01-10 10:35:17 +01:00
message = [ message , plist { i } ' )' ] ;
2017-10-11 09:57:04 +02:00
end
end
end
fprintf ( ' %s\n' , message )
plist = list_of_parameters_calibrated_as_Inf ( M ) ;
if ~ isempty ( plist )
message = [ ' dynare_estimation_init:: Some of the parameters are Inf (' ] ;
2018-01-10 10:35:17 +01:00
for i = 1 : length ( plist )
if i < size ( plist )
message = [ message , plist { i } ' , ' ] ;
2017-10-11 09:57:04 +02:00
else
2018-01-10 10:35:17 +01:00
message = [ message , plist { i } ' )' ] ;
2017-10-11 09:57:04 +02:00
end
end
2019-12-20 16:28:06 +01:00
end
2017-10-11 09:57:04 +02:00
fprintf ( ' %s\n' , message )
end
2014-07-20 12:46:14 +02:00
print_info ( info , 0 , options_ ) ;
end
2017-10-03 14:09:19 +02:00
% If the steady state of the observed variables is non zero, set noconstant equal 0 ()
2014-06-15 12:29:03 +02:00
if ( ~ options_ . loglinear && all ( abs ( oo_ . steady_state ( bayestopt_ . mfys ) ) < 1e-9 ) ) || ( options_ . loglinear && all ( abs ( log ( oo_ . steady_state ( bayestopt_ . mfys ) ) ) < 1e-9 ) )
2021-08-20 13:31:31 +02:00
options_ . noconstant = 0 ; %identifying the constant based on just the initial parameter value is not feasible
2011-11-01 18:23:12 +01:00
else
options_ . noconstant = 0 ;
2014-01-30 10:07:41 +01:00
% If the data are prefiltered then there must not be constants in the
% measurement equation of the DSGE model or in the DSGE-VAR model.
2014-01-30 17:57:36 +01:00
if options_ . prefilter
skipline ( )
disp ( ' You have specified the option "prefilter" to demean your data but the' )
disp ( ' steady state of of the observed variables is non zero.' )
disp ( ' Either change the measurement equations, by centering the observed' )
disp ( ' variables in the model block, or drop the prefiltering.' )
2014-01-30 10:07:41 +01:00
error ( ' The option "prefilter" is inconsistent with the non-zero mean measurement equations in the model.' )
end
end
2015-12-10 15:13:35 +01:00
%% get the non-zero rows and columns of Sigma_e and H
2020-06-22 14:03:56 +02:00
estim_params_ = get_matrix_entries_for_psd_check ( M_ , estim_params_ ) ;
2015-09-25 12:57:44 +02:00
2016-12-17 16:05:17 +01:00
if options_ . load_results_after_load_mh
2022-08-10 12:55:00 +02:00
if ~ exist ( [ M_ . dname filesep ' Output' filesep M_ . fname ' _results.mat' ] , ' file' )
2016-12-17 16:05:17 +01:00
fprintf ( ' \ndynare_estimation_init:: You specified the load_results_after_load_mh, but no _results.mat-file\n' )
fprintf ( ' dynare_estimation_init:: was found. Results will be recomputed.\n' )
options_ . load_results_after_load_mh = 0 ;
end
end
2017-05-16 12:42:01 +02:00
if options_ . mh_replic || options_ . load_mh_file
2023-09-01 15:48:28 +02:00
[ current_options , options_ , bayestopt_ ] = check_posterior_sampler_options ( [ ] , M_ . fname , M_ . dname , options_ , bounds , bayestopt_ ) ;
2016-05-13 21:35:59 +02:00
options_ . posterior_sampler_options . current_options = current_options ;
2015-09-25 12:57:44 +02:00
end
2021-05-02 17:07:12 +02:00
%% set heteroskedastic shocks
if options_ . heteroskedastic_filter
if options_ . fast_kalman_filter
error ( ' estimation option conflict: "heteroskedastic_filter" incompatible with "fast_kalman_filter"' )
end
if options_ . analytic_derivation
error ( [ ' estimation option conflict: analytic_derivation isn' ' t available ' ...
' for heteroskedastic_filter' ] )
end
2021-06-15 12:54:54 +02:00
2021-05-02 17:07:12 +02:00
M_ . heteroskedastic_shocks . Qvalue = NaN ( M_ . exo_nbr , options_ . nobs ) ;
M_ . heteroskedastic_shocks . Qscale = NaN ( M_ . exo_nbr , options_ . nobs ) ;
2021-06-15 12:54:54 +02:00
for k = 1 : length ( M_ . heteroskedastic_shocks . Qvalue_orig )
v = M_ . heteroskedastic_shocks . Qvalue_orig ( k ) ;
2022-01-06 14:59:33 +01:00
temp_periods = v . periods ( v . periods < options_ . nobs + options_ . first_obs ) ;
temp_periods = temp_periods ( temp_periods > = options_ . first_obs ) ;
2021-12-13 11:57:39 +01:00
M_ . heteroskedastic_shocks . Qvalue ( v . exo_id , temp_periods - ( options_ . first_obs - 1 ) ) = v . value ^2 ;
2021-06-15 12:54:54 +02:00
end
for k = 1 : length ( M_ . heteroskedastic_shocks . Qscale_orig )
v = M_ . heteroskedastic_shocks . Qscale_orig ( k ) ;
2022-01-06 14:59:33 +01:00
temp_periods = v . periods ( v . periods < options_ . nobs + options_ . first_obs ) ;
temp_periods = temp_periods ( temp_periods > = options_ . first_obs ) ;
2021-12-13 11:57:39 +01:00
M_ . heteroskedastic_shocks . Qscale ( v . exo_id , temp_periods - ( options_ . first_obs - 1 ) ) = v . scale ^2 ;
2021-06-15 12:54:54 +02:00
end
if any ( any ( ~ isnan ( M_ . heteroskedastic_shocks . Qvalue ) & ~ isnan ( M_ . heteroskedastic_shocks . Qscale ) ) )
fprintf ( ' \ndynare_estimation_init: With the option "heteroskedastic_shocks" you cannot define\n' )
fprintf ( ' dynare_estimation_init: the scale and the value for the same shock \n' )
fprintf ( ' dynare_estimation_init: in the same period!\n' )
error ( ' Scale and value defined for the same shock in the same period with "heteroskedastic_shocks".' )
2021-05-02 17:07:12 +02:00
end
end
2021-05-17 21:24:25 +02:00
2022-12-09 13:19:32 +01:00
if ( options_ . occbin . likelihood . status && options_ . occbin . likelihood . inversion_filter ) || ( options_ . occbin . smoother . status && options_ . occbin . smoother . inversion_filter )
2021-05-17 21:24:25 +02:00
if isempty ( options_ . occbin . likelihood . IVF_shock_observable_mapping )
options_ . occbin . likelihood . IVF_shock_observable_mapping = find ( diag ( M . Sigma_e ) ~= 0 ) ;
else
zero_var_shocks = find ( diag ( M . Sigma_e ) == 0 ) ;
if any ( ismember ( options_ . occbin . likelihood . IVF_shock_observable_mapping , zero_var_shocks ) )
error ( ' IVF-filter: an observable is mapped to a zero variance shock.' )
end
end
2022-07-26 14:43:31 +02:00
end
if options_ . occbin . smoother . status && options_ . occbin . smoother . inversion_filter
if ~ isempty ( options_ . nk )
fprintf ( ' dynare_estimation_init: the inversion filter does not support filter_step_ahead. Disabling the option.\n' )
options_ . nk = [ ] ;
end
if options_ . filter_covariance
fprintf ( ' dynare_estimation_init: the inversion filter does not support filter_covariance. Disabling the option.\n' )
options_ . filter_covariance = false ;
end
if options_ . smoothed_state_uncertainty
fprintf ( ' dynare_estimation_init: the inversion filter does not support smoothed_state_uncertainty. Disabling the option.\n' )
options_ . smoothed_state_uncertainty = false ;
end
2023-01-13 16:19:53 +01:00
end
2023-06-01 22:11:51 +02:00
if options_ . occbin . smoother . status || options_ . occbin . likelihood . status
if isfield ( M_ , ' surprise_shocks' ) && ~ isempty ( M_ . surprise_shocks )
fprintf ( ' dynare_estimation_init: OccBin smoother/filter: previous shocks(surprise) block detected. Deleting its content.\n' )
options_ . occbin . simul . SHOCKS = zeros ( 1 , M_ . exo_nbr ) ;
options_ . occbin . simul . exo_pos = 1 : M_ . exo_nbr ;
M_ . surprise_shocks = [ ] ;
end
2023-06-07 17:18:18 +02:00
end