Page 1 of 1

kalman filter estimate

PostPosted: Mon Jul 03, 2017 4:28 pm
by marco_dp
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

Re: kalman filter estimate

PostPosted: Tue Jul 04, 2017 12:19 pm
by jpfeifer
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
Code: Select all
mh_replic=0

Or alternatively, if you run estimation with MCMC, use the
Code: Select all
calib_smoother

command with
Code: Select all
parameter_set=posterior_mode

Re: kalman filter estimate

PostPosted: Wed Jul 05, 2017 9:50 am
by marco_dp
Dear jpfeifer,

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

Code: Select all
calib_smoother(datafile=dataset1) var1;


but after the estimation it gives me the following error:

Code: Select all
??? 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) ;


Moreover, if I add into parenthesis in the calib_smoother command
Code: Select all
parameter_set=posterior_mode


I get an error.

How can I solve this?
thanks

Re: kalman filter estimate

PostPosted: Wed Jul 05, 2017 9:54 am
by jpfeifer
I would need to see the files.

Re: kalman filter estimate

PostPosted: Wed Jul 05, 2017 12:18 pm
by marco_dp
Dear jpfeifer,

thanks for the help

I attached the .mod file

Re: kalman filter estimate

PostPosted: Fri Jul 07, 2017 3:55 pm
by jpfeifer
You are missing the data file.

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

Instead use the following code
Code: Select all
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;

Re: kalman filter estimate

PostPosted: Sat Jul 08, 2017 10:36 am
by marco_dp
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:

??? Error using ==> evaluate_smoother
Too many input arguments.

Error in ==> final_model at 586
[oo_,M_,options_,bayestopt_]=evaluate_smoother('calibration',var_list_,M_,oo_,options_,bayestopt_,estim_params_);

Error in ==> dynare at 180
evalin('base',fname) ;


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

thanks for your attention

Re: kalman filter estimate

PostPosted: Mon Jul 10, 2017 2:14 pm
by jpfeifer
The mode-file is missing. But from the error message I infer that you are not using Dynare 4.5

Re: kalman filter estimate

PostPosted: Tue Jul 11, 2017 10:26 am
by marco_dp
Thanks for the help, the problem was the dynare version

Thanks again for your kindness