I was thinking to quickly compare the IRFs produced by dynare with the ones of the state space retrieved from the ABCD test (to make sure everything is correct). For the latter I used the integrated IRF MATLAB function for state spaces. For the IRF comparison I just used an older model of mine. As you will see there’s a big difference between dynare’s and the “my computation”.

If you just run the “compare_irfs.m” file you get the relevant plot. Most probably I can’t just use the ABCD structure to construct the irfs. Do you know where I am going wrong or should this be feasible given dynare’s state space representation? Many thanks for your help.

Matlab’s state space uses y_t=\tilde Cx_t+\tilde D\varepsilon_t, but Dynare’s ABCD form reports y_t=Cx_{t-1}+D\varepsilon_t. With x_t=Ax_{t-1}+B\varepsilon_t you get y_t=(\tilde CA) x_{t-1}+(\tilde CB+\tilde D)\varepsilon_t. Comparing coefficients, you should get \tilde C=CA^{-1} \tilde D=D-\tilde C B
However, that requires A to be invertible, which it is often not.

Many thanks for the illustration, my hunch was that the two state space representations are slightly different. Also, I checked and as you said for the provided model the matrix A is not invertible. I have two follow up questions below:

Given that A is not invertible, this means if I would go ahead with Kalman filtering the ABCD representation myself, the resulting likelihood between dynare and my own computations would be different. Is this correct? Or is it only a necessary condition?

I know that you advise against computing the Kalman routine and MCMC ourselves. However, thought I would give it a go, as I am planning to change the resulting state space. Could you guide me where I can find dynare’s state space (A,B,C,D) representation? Correct me if I am wrong, but I remember that in some post I read that this is not easily retrievable.

as I am currently trying to apply the Kalman filter to the ABCD representation. So reading your responses the job will be to somehow match dynare’s state representation to the one from MATLAB, i.e. \tilde{C} = C A^{-1}, correct?

The former is what I am trying to do, to compute the Kalman filter myself for which I would need dynare’s state space. Sorry Johannes for the cryptic messages.

Thanks a lot Johannes! I played around with the pseudo-invers yesterday but didn’t take into account the transformation of the dynare matrices. One final questions, have you changed any other files apart from the ‘compare_irfs.m’?

I added the lines of code you posted above to my file, but when I run it I still get a difference between both IRFs, whereas when I run the files you shared with me I get the desired result (i.e. no difference between both IRFs) .