Construct smoothed state series given parameter vector

Hello,

I have a question that is quite similar to this one.

Just like the author of that post, I use Dynare to construct the statespace of the model, and to estimate it. After doing that, I’d like to be able to, in a .m file or the Matlab console, extract the smoothed & updated states from the Kalman filtering process when the model is defined by an arbitrary parameter vector.

My ideal .m file would look something like this:

addpath C:\dynare\6.1\matlab;
dynare_config; % makes `dseries` objects interpretable
load {MOD_FILENAME}_results.mat;

N = 10; % number of times to run Kalman process
K = length(M_.state_var);
T = dseries_.nobs;

random_params = randn(N, M_.param_nbr);
random_states = zeros(T, K, N);

for i = 1:N
    theta_i = random_params(i, :);
    set_all_parameters(theta_i, estim_params_, M_);

    random_states(:, :, i) = handy_kalman_function(dataset_, M_, obs_);
end

Is there a built-in Dynare function that would be able to do this?

The closest I’ve been able to get to this is:

addpath C:\dynare\6.1\matlab;
dynare_config; % makes `dseries` objects interpretable
load {MOD_FILENAME}_results.mat;

params = oo_.posterior_mode.parameters;
theta0 = cellfun(@(x)(params.(x)), fieldnames(params));

nobs = dataset_.nobs;
Y    = transpose(dataset_.data);

aindex = dataset_info.missing.aindex;
state  = dataset_info.missing.state;

DsgeSmoother(theta0, nobs, Y, aindex, state, M_, oo_, options_, bayestopt_, estim_params_, dataset_, dataset_info);

However, this throws an error in the stochastic_solvers function. The full error message is in the attached file.
error_trace.txt (990 Bytes)

Thank you to anyone who might be able to help. Best,
Logan

Typically, you would call the function

[oo_,M_,options_,bayestopt_,Smoothed_variables_declaration_order_deviation_form,initial_date]=evaluate_smoother(parameters,var_list,M_,oo_,options_,bayestopt_,estim_params_)

The posted error message comes from a missing

if isempty(options_.qz_criterium)
    options_.qz_criterium = 1+1e-6;
end

This does exactly what I need - thank you Johannes!

I have a couple follow-up questions, if you have the time:

  1. Is there documentation of this function anywhere? If I search the Dynare documentation for evaluate_smoother, nothing comes up. I would like to know what the variables in var_list would be used for, for instance. That M_ and oo_ are both returned make me think that some fields are modified, as well, but there isn’t a quick way to figure out how those modified fields are altered.
  2. It seems evaluate_smoother reads in my estimation datafile each time it is called. At first I thought this was because I read in the dataset in my .mod file to create some calibration targets. However, even if I hard-code those targets, so that the only reference to the datafile is in the estimation command, evaluate_smoother still calls load_csv_file_data. Is there a workaround available, maybe one that involves feeding dataset_ in as an argument? I ask because what I’d like to do with evaluate_smoother is feed it one million of the parameter draws from the posterior, save the entirety of the implied paths of the smoothed variables, and then compute the median path of those one million paths (along with confidence bands). Reading in the dataset one million times takes roughly an hour and a half.

Thank you again! Best,
Logan

For the application you describe, you indeed need to just loop over

[alphahat,etahat,epsilonhat,ahat,SteadyState,trend_coeff,aK,T,R,P,PK,decomp,trend_addition,state_uncertainty,oo_,bayestopt_,alphahat0,state_uncertainty0,d] = DsgeSmoother(xparam1,gend,Y,data_index,missing_value,M_,oo_,options_,bayestopt_,estim_params_,varargin)

Those are internal Dynare function that do not have separate documentation apart from what is written in their headers.

I see - I’ve set the qz_criterium field in the way you describe above, and now I’m able to use DsgeSmoother with no problem.

The headers are indeed quite descriptive, I guess what I meant to say is that it would be nice to have a listing of all these internal functions that are useful for post-estimation tasks somewhere.

Thank you so much, again!
-Logan