Kalman filter estimate

Dear dynare community,

I have estimated a DSGE model in dynare by using bayesian techniques.
I would like to obtain the Kalman filter estimate of an endogenous variable used in the model at the posterior mode, in order to compare its evolution (i.e., the path of the variable generated by the model) against its observed evolution (the observed time series).
Essentially, I would like to replicate figure 5, pag 116, of the paper I attached to this message.
How does this can be accomplished into dynare?

thanks in advance for the help
justiniano-primicieri-tambalotti.pdf (362 KB)

  1. For observed variables, the smoothed variables from the Kalman filter will always be equal to the observed ones. JPT compare the smoothed variable to outside evidence not used for the model estimation
  2. To generate the smoothed variables at the mode, use estimation with

Or alternatively, if you run estimation with MCMC, use the

command with

Dear jpfeifer,

thanks for the reply. I run the estimation with MCMC, after the estimation command I added this line

but after the estimation it gives me the following error:

[code]??? Attempted to access xparam1(1); index out of bounds because
numel(xparam1)=0.

Error in ==> set_all_parameters at 68
Sigma_e(k,k) = xparam1(i)^2;

Error in ==> DsgeSmoother at 65
M_ = set_all_parameters(xparam1,estim_params_,M_);

Error in ==> evaluate_smoother at 90
[atT,innov,measurement_error,updated_variables,ys,trend_coeff,aK,T,R,P,PK,decomp]
= …

Error in ==> final_model at 587
evaluate_smoother(‘calibration’,var_list_);

Error in ==> dynare at 180
evalin(‘base’,fname) ;[/code]

Moreover, if I add into parenthesis in the calib_smoother command

I get an error.

How can I solve this?
thanks

I would need to see the files.

Dear jpfeifer,

thanks for the help

I attached the .mod file
final_model.mod (12.6 KB)

You are missing the data file.

I was wrong. calib_smoother does not support the parameter_set option yet, see github.com/DynareTeam/dynare/issues/1477

Instead use the following code

verbatim;
options_.datafile = 'data_80_16_hp';
var_list_ = char('q');
options_.smoother = 1;
options_.order = 1;
[oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);
end;

Dear Johannes Pfeifer,

thanks a lot for deserving me your time.

However, the solution you proposed me does not work, I get the following error:

I attach you both the .mod file and the .xls data

thanks for your attention
data_80_16_hp.rar (24 KB)
final_model.mod (12.8 KB)

The mode-file is missing. But from the error message I infer that you are not using Dynare 4.5

Thanks for the help, the problem was the dynare version

Thanks again for your kindness

A question related to this old thread.

After a MCMC, is oo_.SmoothedVariables.VariableName a smoothed (unobserved) variable at the posterior mean?

If yes, why is this different from oo_.SmoothedVariables.Mean.VariableName generated with the option “smoother”?

Thank you!

oo_.SmoothedVariables.VariableName should only generated if you do not run a Metropolis or use the calib_smoother-command. It should be the smoothed variable at the posterior mode. In contrast, oo_.SmoothedVariables.Mean.VariableName is the mean smoothed estimate after a Metropolis run, where the mean is taken over the posterior draws

I am using the latest version and just checked the following. The oo_.SmoothedVariables.VariableName is generated in the following cases:

1.After a MCMC without the smoother option;
2.When a previous mcmc is loaded with the load_mh_file without the smoother option;
3. After a MCMC when “shock_decomposition” is specified (with and without the smoother option);

What oo_.SmoothedVariables.VariableName represents in this case?

My guess is that this is the smoothed variable at the mean.

Thank you!