2013-09-10 21:30:55 +02:00
function [dataset_, xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_, fake] = dynare_estimation_init ( var_list_, dname, gsa_flag, M_, options_, oo_, estim_params_, bayestopt_)
2009-12-16 18:17:34 +01:00
2011-02-21 11:20:26 +01:00
% function dynare_estimation_init(var_list_, gsa_flag)
2009-12-16 18:17:34 +01:00
% preforms initialization tasks before estimation or
% global sensitivity analysis
2011-09-14 23:40:23 +02:00
%
2009-12-16 18:17:34 +01:00
% INPUTS
% var_list_: selected endogenous variables vector
2011-02-22 10:12:37 +01:00
% dname: alternative directory name
2011-02-21 11:20:26 +01:00
% gsa_flag: flag for GSA operation (optional)
2011-09-14 23:40:23 +02:00
%
2009-12-16 18:17:34 +01:00
% OUTPUTS
% data: data after required transformation
2011-02-21 11:20:26 +01:00
% rawdata: data as in the data file
% xparam1: initial value of estimated parameters as returned by
% set_prior()
2009-12-16 18:17:34 +01:00
%
% SPECIAL REQUIREMENTS
% none
2013-06-12 16:42:09 +02:00
% Copyright (C) 2003-2013 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
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2012-08-28 12:17:07 +02:00
global objective_function_penalty_base
2013-09-10 21:30:55 +02:00
hh = [ ] ;
2011-09-14 23:40:23 +02:00
if isempty ( gsa_flag )
2011-02-21 11:20:26 +01:00
gsa_flag = 0 ;
2011-09-14 23:40:23 +02:00
else % Decide if a DSGE or DSGE-VAR has to be estimated.
2011-02-25 09:27:33 +01:00
if ~ isempty ( strmatch ( ' dsge_prior_weight' , M_ . param_names ) )
options_ . dsge_var = 1 ;
end
var_list_ = check_list_of_variables ( options_ , M_ , var_list_ ) ;
options_ . varlist = var_list_ ;
2009-12-16 18:17:34 +01:00
end
2011-09-14 23:40:23 +02:00
% Get the indices of the observed variables in M_.endo_names.
2009-12-16 18:17:34 +01:00
options_ . lgyidx2varobs = zeros ( size ( M_ . endo_names , 1 ) , 1 ) ;
for i = 1 : size ( M_ . endo_names , 1 )
tmp = strmatch ( deblank ( M_ . endo_names ( i , : ) ) , options_ . varobs , ' exact' ) ;
if ~ isempty ( tmp )
2011-05-06 15:53:48 +02:00
if length ( tmp ) > 1
2013-07-10 17:12:34 +02:00
skipline ( )
2011-05-06 15:53:48 +02:00
error ( [ ' Multiple declarations of ' deblank ( M_ . endo_names ( i , : ) ) ' as an observed variable is not allowed!' ] )
end
2011-09-14 23:40:23 +02:00
options_ . lgyidx2varobs ( i ) = tmp ;
2009-12-16 18:17:34 +01:00
end
end
2012-03-03 16:57:01 +01:00
if options_ . order > 2
error ( [ ' I cannot estimate a model with a ' int2str ( options_ . order ) ' order approximation of the model!' ] )
2009-12-16 18:17:34 +01:00
end
2011-10-21 14:21:40 +02:00
% Set options_.lik_init equal to 3 if diffuse filter is used or
% kalman_algo refers to a diffuse filter algorithm.
if ( options_ . diffuse_filter == 1 ) || ( options_ . kalman_algo > 2 )
2011-11-21 12:39:02 +01:00
if options_ . lik_init == 2
error ( [ ' options diffuse_filter, lik_init and/or kalman_algo have ' ...
' contradictory settings' ] )
else
options_ . lik_init = 3 ;
end
2009-12-16 18:17:34 +01:00
end
2011-09-14 23:40:23 +02:00
% If options_.lik_init == 1
% set by default options_.qz_criterium to 1-1e-6
% and check options_.qz_criterium < 1-eps if options_.lik_init == 1
% Else set by default options_.qz_criterium to 1+1e-6
2011-02-21 11:20:26 +01:00
if options_ . lik_init == 1
if isempty ( options_ . qz_criterium )
options_ . qz_criterium = 1 - 1e-6 ;
elseif options_ . qz_criterium > 1 - eps
error ( [ ' estimation: option qz_criterium is too large for estimating ' ...
' a stationary model. If your model contains unit roots, use ' ...
' option diffuse_filter' ] )
end
elseif isempty ( options_ . qz_criterium )
options_ . qz_criterium = 1 + 1e-6 ;
end
2011-09-14 23:40:23 +02: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.
2009-12-16 18:17:34 +01:00
if options_ . prefilter == 1
options_ . noconstant = 1 ;
end
2011-09-14 23:40:23 +02:00
% Set options related to filtered variables.
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 the number of observed variables.
2011-02-21 11:20:26 +01:00
n_varobs = size ( options_ . varobs , 1 ) ;
2009-12-16 18:17:34 +01:00
2011-09-14 23:40:23 +02:00
% Set priors over the estimated parameters.
2009-12-16 18:17:34 +01:00
if ~ isempty ( estim_params_ )
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
% Check that the provided mode_file is compatible with the current estimation settings.
if ~ isempty ( estim_params_ ) && ~ isempty ( options_ . mode_file ) && ~ options_ . mh_posterior_mode_estimation
number_of_estimated_parameters = length ( xparam1 ) ;
mode_file = load ( options_ . mode_file ) ;
if number_of_estimated_parameters > length ( mode_file . xparam1 )
skipline ( )
disp ( [ ' The posterior mode file ' options_ . mode_file ' has been generated using another specification of the model or another model!' ] )
disp ( [ ' Your mode file contains estimates for ' int2str ( length ( mode_file . xparam1 ) ) ' parameters, while you are attempting to estimate ' int2str ( number_of_estimated_parameters ) ' parameters:' ] )
for i = 1 : number_of_estimated_parameters
id = strmatch ( deblank ( bayestopt_ . name ( i , : ) ) , mode_file . parameter_names , ' exact' ) ;
if isempty ( id )
disp ( [ ' --> Estimated parameter ' bayestopt_ . name { i } ' is not present in the loaded mod_file.' ] )
end
end
for i = 1 : length ( mode_file . xparam1 )
id = strmatch ( mode_file . parameter_names { i } , bayestopt_ . name , ' exact' ) ;
if isempty ( id )
disp ( [ ' --> Parameter ' mode_file . parameter_names { i } ' is not estimated according to the current mod file.' ] )
end
end
error ( ' Please change the mode_file option or the list of estimated parameters.' )
elseif number_of_estimated_parameters < length ( mode_file . xparam1 )
skipline ( )
disp ( [ ' The posterior mode file ' options_ . mode_file ' has been generated using another specification of the model or another model!' ] )
disp ( [ ' Your mode file contains estimates for ' int2str ( length ( mode_file . xparam1 ) ) ' parameters, while you are attempting to estimate only ' int2str ( number_of_estimated_parameters ) ' parameters:' ] )
Id = [ ] ;
for i = 1 : number_of_estimated_parameters
id = strmatch ( deblank ( bayestopt_ . name ( i , : ) ) , mode_file . parameter_names , ' exact' ) ;
if isempty ( id )
disp ( [ ' --> Estimated parameter ' deblank ( bayestopt_ . name ( i , : ) ) ' is not present in the loaded mode file.' ] )
Id = [ ] ;
break
else
Id = [ Id ; id ] ;
end
end
for i = 1 : length ( mode_file . xparam1 )
id = strmatch ( mode_file . parameter_names { i } , bayestopt_ . name , ' exact' ) ;
if isempty ( id )
disp ( [ ' --> Parameter ' mode_file . parameter_names { i } ' is not estimated according to the current mod file.' ] )
end
end
if isempty ( Id )
% None of the estimated parameters are present in the mode_file.
error ( ' Please change the mode_file option or the list of estimated parameters.' )
else
% If possible, fix the mode_file.
if isequal ( length ( Id ) , number_of_estimated_parameters )
disp ( ' ==> Fix mode file (remove unused parameters).' )
mode_file . parameter_names = mode_file . parameter_names ( Id , : ) ;
mode_file . xparam1 = mode_file . xparam1 ( Id ) ;
2013-09-19 15:25:23 +02:00
if isfield ( mode_file , ' hh' )
mode_file . hh = mode_file . hh ( Id , Id ) ;
end
2013-09-10 21:30:55 +02:00
end
end
else
% The number of declared estimated parameters match the number of parameters in the mode file.
% Check that the parameters in the mode file and according to the current mod file are identical.
if isequal ( mode_file . parameter_names , bayestopt_ . name )
% Ok! Nothing to do here.
else
skipline ( )
disp ( [ ' The posterior mode file ' options_ . mode_file ' has been generated using another specification of the model or another model!' ] )
% Check if this only an ordering issue.
Id = [ ] ;
for i = 1 : number_of_estimated_parameters
id = strmatch ( deblank ( bayestopt_ . name ( i , : ) ) , mode_file . parameter_names , ' exact' ) ;
if isempty ( id )
disp ( [ ' --> Estimated parameter ' bayestopt_ . name { i } ' is not present in the loaded mode file.' ] )
Id = [ ] ;
break
else
Id = [ Id ; id ] ;
end
end
if isempty ( Id )
% None of the estimated parameters are present in the mode_file.
error ( ' Please change the mode_file option or the list of estimated parameters.' )
else
% If possible, fix the mode_file.
if isequal ( length ( Id ) , number_of_estimated_parameters )
disp ( ' ==> Fix mode file (reorder the parameters).' )
mode_file . parameter_names = mode_file . parameter_names ( Id , : ) ;
mode_file . xparam1 = mode_file . xparam1 ( Id ) ;
2013-09-19 15:25:23 +02:00
if isfield ( mode_file , ' hh' )
mode_file . hh = mode_file . hh ( Id , Id ) ;
end
2013-09-10 21:30:55 +02:00
end
end
2013-04-26 21:10:36 +02:00
end
end
2013-09-10 21:30:55 +02:00
xparam1 = mode_file . xparam1 ;
2013-09-19 15:25:23 +02:00
if isfield ( mode_file , ' hh' )
hh = mode_file . hh ;
end
2013-09-10 21:30:55 +02:00
skipline ( )
end
2013-09-18 11:33:14 +02:00
if ~ isempty ( estim_params_ )
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
2011-09-14 23:40:23 +02:00
bounds = prior_bounds ( bayestopt_ , options_ ) ;
2011-02-21 11:20:26 +01:00
bounds ( : , 1 ) = max ( bounds ( : , 1 ) , lb ) ;
bounds ( : , 2 ) = min ( bounds ( : , 2 ) , ub ) ;
2013-09-18 11:23:47 +02:00
else % estimated parameters but no declared priors
2011-02-21 11:20:26 +01:00
% No priors are declared so Dynare will estimate the model by
% maximum likelihood with inequality constraints for the parameters.
options_ . mh_replic = 0 ; % No metropolis.
bounds ( : , 1 ) = lb ;
bounds ( : , 2 ) = 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.
2013-07-06 00:20:07 +02:00
outside_bound_pars = find ( xparam1 < bounds ( : , 1 ) | xparam1 > bounds ( : , 2 ) ) ;
if ~ isempty ( outside_bound_pars )
for ii = 1 : length ( outside_bound_pars )
2013-09-30 17:02:25 +02:00
outside_bound_par_names { ii , 1 } = get_the_name ( outside_bound_pars ( ii ) , 0 , M_ , estim_params_ , options_ ) ;
2013-07-06 00:20:07 +02:00
end
disp_string = [ outside_bound_par_names { 1 , : } ] ;
for ii = 2 : size ( outside_bound_par_names , 1 )
disp_string = [ disp_string , ' , ' , outside_bound_par_names { ii , : } ] ;
2012-07-19 12:30:41 +02:00
end
2013-04-26 21:10:36 +02:00
error ( [ ' Initial value(s) of ' , disp_string , ' are outside parameter bounds. Potentially, you should set prior_trunc=0. If you used the mode_file-option, check whether your mode-file is consistent with the priors.' ] )
2009-12-16 18:17:34 +01:00
end
2013-09-29 16:13:14 +02:00
inadmissible_inverse_gamma_values = find ( bayestopt_ . pshape == 4 & xparam1 == 0 ) ;
if ~ isempty ( inadmissible_inverse_gamma_values )
for ii = 1 : length ( inadmissible_inverse_gamma_values )
inadmissible_inverse_gamma_par_names { ii , 1 } = get_the_name ( inadmissible_inverse_gamma_values ( ii ) , 0 , M_ , estim_params_ , options_ ) ;
end
disp_string = [ inadmissible_inverse_gamma_par_names { 1 , : } ] ;
for ii = 2 : size ( inadmissible_inverse_gamma_par_names , 1 )
disp_string = [ disp_string , ' , ' , inadmissible_inverse_gamma_par_names { ii , : } ] ;
end
error ( [ ' Initial value(s) of ' , disp_string , ' is zero. This is not allowed when using an inverse gamma prior.\n' ] )
end
2009-12-16 18:17:34 +01:00
lb = bounds ( : , 1 ) ;
ub = bounds ( : , 2 ) ;
bayestopt_ . lb = lb ;
bayestopt_ . ub = ub ;
2013-09-10 21:30:55 +02:00
end
if isempty ( estim_params_ ) % 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
error ( ' ESTIMATION: the ' ' estimated_params' ' block is mandatory (unless you are running a smoother)' )
end
2009-12-16 18:17:34 +01:00
xparam1 = [ ] ;
bayestopt_ . lb = [ ] ;
bayestopt_ . ub = [ ] ;
bayestopt_ . jscale = [ ] ;
bayestopt_ . pshape = [ ] ;
bayestopt_ . p1 = [ ] ;
bayestopt_ . p2 = [ ] ;
bayestopt_ . p3 = [ ] ;
bayestopt_ . p4 = [ ] ;
2011-02-21 11:20:26 +01:00
bayestopt_ . p5 = [ ] ;
bayestopt_ . p6 = [ ] ;
bayestopt_ . p7 = [ ] ;
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 ;
end
2012-04-21 21:28:03 +02:00
% storing prior parameters in results
oo_ . prior . mean = bayestopt_ . p1 ;
oo_ . prior . variance = diag ( bayestopt_ . p2 .^ 2 ) ;
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 = { } ;
trend_coeffs = options_ . trend_coeffs ;
nt = length ( trend_coeffs ) ;
for i = 1 : n_varobs
if i > length ( trend_coeffs )
bayestopt_ . trend_coeff { i } = ' 0' ;
else
bayestopt_ . trend_coeff { i } = trend_coeffs { i } ;
end
end
end
2011-09-17 15:38:49 +02:00
% Set the "size" of penalty.
2012-08-28 12:17:07 +02:00
objective_function_penalty_base = 1e8 ;
2009-12-16 18:17:34 +01:00
2011-09-17 15:38:49 +02:00
% Get informations about the variables of the model.
2012-07-06 09:50:30 +02:00
dr = set_state_space ( oo_ . dr , M_ , options_ ) ;
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
2011-09-17 15:38:49 +02:00
% Test if observed variables are declared.
2009-12-16 18:17:34 +01:00
if isempty ( options_ . varobs )
2011-02-21 11:20:26 +01:00
error ( ' VAROBS is missing' )
2009-12-16 18:17:34 +01:00
end
2011-09-17 15:38:49 +02:00
% Setting resticted state space (observed + predetermined variables)
2011-02-21 11:20:26 +01:00
var_obs_index = [ ] ;
2009-12-16 18:17:34 +01:00
k1 = [ ] ;
for i = 1 : n_varobs
2011-11-02 17:54:48 +01:00
var_obs_index = [ var_obs_index ; strmatch ( deblank ( options_ . varobs ( i , : ) ) , M_ . endo_names ( dr . order_var , : ) , ' exact' ) ] ;
k1 = [ k1 ; strmatch ( deblank ( options_ . varobs ( i , : ) ) , M_ . endo_names , ' exact' ) ] ;
2009-12-16 18:17:34 +01:00
end
2011-06-21 13:23:06 +02:00
2011-09-17 15:38:49 +02:00
% Define union of observed and state variables
2012-11-16 20:05:13 +01:00
k2 = union ( var_obs_index , [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , ' rows' ) ;
2011-09-17 15:38:49 +02:00
% Set restrict_state to postion of observed + state variables in expanded state vector.
oo_ . dr . restrict_var_list = k2 ;
2012-03-03 18:27:25 +01:00
bayestopt_ . restrict_var_list = k2 ;
2011-09-17 15:38:49 +02:00
% set mf0 to positions of state variables in restricted state vector for likelihood computation.
2012-11-16 20:05:13 +01:00
[ junk , bayestopt_ . mf0 ] = ismember ( [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , k2 ) ;
2011-09-17 15:38:49 +02:00
% Set mf1 to positions of observed variables in restricted state vector for likelihood computation.
[ junk , bayestopt_ . mf1 ] = ismember ( var_obs_index , k2 ) ;
% Set mf2 to positions of observed variables in expanded state vector for filtering and smoothing.
bayestopt_ . mf2 = var_obs_index ;
bayestopt_ . mfys = k1 ;
[ junk , ic ] = intersect ( k2 , nstatic + ( 1 : npred ) ' ) ;
oo_ . dr . restrict_columns = [ ic ; length ( k2 ) + ( 1 : nspred - npred ) ' ] ;
2011-06-21 13:23:06 +02:00
k3 = [ ] ;
k3p = [ ] ;
if options_ . selected_variables_only
for i = 1 : size ( var_list_ , 1 )
k3 = [ k3 ; strmatch ( var_list_ ( i , : ) , M_ . endo_names ( dr . order_var , : ) , ...
' exact' ) ] ;
k3p = [ k3 ; strmatch ( var_list_ ( i , : ) , M_ . endo_names , ...
' exact' ) ] ;
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
2011-06-18 17:43:45 +02:00
if options_ . block == 1
2011-11-25 13:03:19 +01:00
k1 = k1 ' ;
2011-06-18 17:43:45 +02:00
[ k2 , i_posA , i_posB ] = union ( k1 ' , M_ . state_var ' , ' rows' ) ;
% Set restrict_state to postion of observed + state variables in expanded state vector.
oo_ . dr . restrict_var_list = [ k1 ( i_posA ) M_ . state_var ( sort ( i_posB ) ) ] ;
% set mf0 to positions of state variables in restricted state vector for likelihood computation.
[ junk , bayestopt_ . mf0 ] = ismember ( M_ . state_var ' , oo_ . dr . restrict_var_list ) ;
% Set mf1 to positions of observed variables in restricted state vector for likelihood computation.
2011-09-14 23:40:23 +02:00
[ junk , bayestopt_ . mf1 ] = ismember ( k1 , oo_ . dr . restrict_var_list ) ;
2011-06-18 17:43:45 +02:00
% Set mf2 to positions of observed variables in expanded state vector for filtering and smoothing.
bayestopt_ . mf2 = var_obs_index ;
bayestopt_ . mfys = k1 ;
oo_ . dr . restrict_columns = [ size ( i_posA , 1 ) + ( 1 : size ( M_ . state_var , 2 ) ) ] ;
2011-06-21 13:23:06 +02:00
[ k2 , i_posA , i_posB ] = union ( k3p , M_ . state_var ' , ' rows' ) ;
bayestopt_ . smoother_var_list = [ k3p ( i_posA ) ; M_ . state_var ( sort ( i_posB ) ) ' ] ;
2012-04-18 21:15:18 +02:00
[ junk , junk , bayestopt_ . smoother_saved_var_list ] = intersect ( k3p , bayestopt_ . smoother_var_list ( : ) ) ;
2011-06-21 13:23:06 +02:00
[ junk , ic ] = intersect ( bayestopt_ . smoother_var_list , M_ . state_var ) ;
bayestopt_ . smoother_restrict_columns = ic ;
[ junk , bayestopt_ . smoother_mf ] = ismember ( k1 , ...
bayestopt_ . smoother_var_list ) ;
2011-06-18 17:43:45 +02:00
else
2012-11-16 20:05:13 +01:00
k2 = union ( var_obs_index , [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , ' rows' ) ;
2011-06-18 17:43:45 +02:00
% 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.
2012-11-16 20:05:13 +01:00
[ junk , bayestopt_ . mf0 ] = ismember ( [ M_ . nstatic + 1 : M_ . nstatic + M_ . nspred ] ' , k2 ) ;
2011-06-18 17:43:45 +02:00
% Set mf1 to positions of observed variables in restricted state vector for likelihood computation.
2011-09-14 23:40:23 +02:00
[ junk , bayestopt_ . mf1 ] = ismember ( var_obs_index , k2 ) ;
2011-06-18 17:43:45 +02:00
% Set mf2 to positions of observed variables in expanded state vector for filtering and smoothing.
bayestopt_ . mf2 = var_obs_index ;
bayestopt_ . mfys = k1 ;
[ junk , ic ] = intersect ( k2 , nstatic + ( 1 : npred ) ' ) ;
oo_ . dr . restrict_columns = [ ic ; length ( k2 ) + ( 1 : nspred - npred ) ' ] ;
2011-06-21 13:23:06 +02:00
bayestopt_ . smoother_var_list = union ( k2 , k3 ) ;
2012-04-18 21:15:18 +02:00
[ junk , junk , bayestopt_ . smoother_saved_var_list ] = intersect ( k3 , bayestopt_ . smoother_var_list ( : ) ) ;
2011-06-21 13:23:06 +02:00
[ junk , ic ] = intersect ( bayestopt_ . smoother_var_list , nstatic + ( 1 : npred ) ' ) ;
bayestopt_ . smoother_restrict_columns = ic ;
[ junk , bayestopt_ . smoother_mf ] = ismember ( var_obs_index , ...
bayestopt_ . smoother_var_list ) ;
2011-06-18 17:43:45 +02:00
end ;
2009-12-16 18:17:34 +01:00
2012-04-27 15:57:58 +02:00
if options_ . analytic_derivation ,
2012-08-21 15:53:02 +02:00
options_ . analytic_derivation = 1 ;
2012-07-05 10:14:10 +02:00
if ~ ( exist ( ' sylvester3' , ' file' ) == 2 ) ,
2012-04-27 15:57:58 +02:00
dynareroot = strrep ( which ( ' dynare' ) , ' dynare.m' , ' ' ) ;
addpath ( [ dynareroot ' gensylv' ] )
end
2012-07-05 10:14:10 +02:00
if estim_params_ . np ,
% check if steady state changes param values
M = M_ ;
M . params ( estim_params_ . param_vals ( : , 1 ) ) = M . params ( estim_params_ . param_vals ( : , 1 ) ) * 1.01 ;
if options_ . diffuse_filter
steadystate_check_flag = 0 ;
else
steadystate_check_flag = 1 ;
end
[ tmp1 , params ] = evaluate_steady_state ( oo_ . steady_state , M , options_ , oo_ , steadystate_check_flag ) ;
change_flag = any ( find ( params - M . params ) ) ;
if change_flag ,
disp ( ' The steadystate file changed the values for the following parameters: ' ) ,
disp ( M . param_names ( find ( params - M . params ) , : ) )
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
2011-09-17 15:38:49 +02:00
% Test if the data file is declared.
2011-02-21 11:20:26 +01:00
if isempty ( options_ . datafile )
if gsa_flag
2011-09-28 20:48:47 +02:00
dataset_ = [ ] ;
% rawdata = [];
% data_info = [];
2011-02-21 11:20:26 +01:00
return
2009-12-16 18:17:34 +01:00
else
2011-02-21 11:20:26 +01:00
error ( ' datafile option is missing' )
2011-09-14 23:40:23 +02:00
end
2009-12-16 18:17:34 +01:00
end
2011-09-17 15:38:49 +02:00
% If jscale isn't specified for an estimated parameter, use global option options_.jscale, set to 0.2, by default.
2009-12-16 18:17:34 +01:00
k = find ( isnan ( bayestopt_ . jscale ) ) ;
bayestopt_ . jscale ( k ) = options_ . mh_jscale ;
2011-09-17 15:38:49 +02:00
% Load and transform data.
transformation = [ ] ;
if options_ . loglinear && ~ options_ . logdata
transformation = @ log ;
2009-12-16 18:17:34 +01:00
end
2011-09-17 15:38:49 +02:00
xls . sheet = options_ . xls_sheet ;
xls . range = options_ . xls_range ;
2011-09-18 14:37:29 +02:00
if ~ isfield ( options_ , ' nobs' )
options_ . nobs = [ ] ;
end
2011-09-18 12:00:11 +02:00
2011-09-18 14:37:29 +02:00
dataset_ = initialize_dataset ( options_ . datafile , options_ . varobs , options_ . first_obs , options_ . nobs , transformation , options_ . prefilter , xls ) ;
2011-09-18 12:00:11 +02:00
2011-09-18 14:49:43 +02:00
options_ . nobs = dataset_ . info . ntobs ;
2011-11-01 18:23:12 +01:00
% setting noconstant option
if options_ . diffuse_filter
steadystate_check_flag = 0 ;
else
steadystate_check_flag = 1 ;
end
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
2012-02-17 10:36:21 +01:00
M . params ( estim_params_ . param_vals ( : , 1 ) ) = xparam1 ( nvx + ncx + nvn + ncn + 1 : end ) ;
2013-06-21 12:42:38 +02:00
end
2012-07-05 10:14:10 +02:00
[ oo_ . steady_state , params ] = evaluate_steady_state ( oo_ . steady_state , M , options_ , oo_ , steadystate_check_flag ) ;
2011-11-01 18:23:12 +01:00
if all ( abs ( oo_ . steady_state ( bayestopt_ . mfys ) ) < 1e-9 )
options_ . noconstant = 1 ;
else
options_ . noconstant = 0 ;
2013-06-21 12:42:38 +02:00
end