I have been trying (with unstable version) to use the Kalman smoother to extract the shocks for a calibrated model. However, depending on different specifications of kalman filter( diffuse versus non-diffuse, sims svd decomposition versus not, etc ) I get drastically different smoothed states and shocks. Is there a way of disciplining the extraction of states?

For illustration, I am attaching the Smets Wouters code, kindly provided by Johannes Pfeifer. The main_run_sw runs the smets wouters code, performs the calib_smoother to extract the states. Then it uses Alejandro Justiniano’s kfilter_full to do the smae, and finally uses Iskander Karibzhanov’s kalcvf and kalcvs routine (also used in the FRBNY github codes).

Finally compare: compare etahat(1,:), etamat(:,1) and oo_.SmoothedShocks.ea (28.8 KB)

I didn’t have the time to check exactly where things go wrong, but I don’t think your Kalman smoothing outside of Dynare is correct. If you check

you will see the shocks are rather like white noise, fluctuating around 0. The output from your other two smoothers show significant trends, suggesting that there is still something wrong, potentially with the way you feed in the respective matrices.