I’m a novice at Bayesian estimation in Dynare, and I thought as a simple first step I would try to replicate the model from Chapter 1 of the Herbst and Schorfheide book, “Bayesian Estimation of DSGE Models”. I wrote up the mod file of the linearized model, and the impulse response functions seem to match very well the IRFs in the book. This is just a simple 3 equation model, with an Euler equation, Phillips curve, and monetary policy rule.

The problem starts when it comes to the estimation. As a simple first step, before trying to estimate the model on actual data, I generate simulations from the solved model and do a Bayesian estimation of the simulated data.

Unfortunately, the estimation does not seem to run – or when I make changes to get it to run, the results look weird. In my initial estimation attempt, I get the following error message:

“Error using chol Matrix must be positive definite.”

Searching the forum, people suggested using the option “mode_compute=6,prior_trunc=0”. When I used this option the simulation did run, but the posteriors looked way off.

My questions are thus as follows:

(1) Can anyone see if there is an error in the way I have set up the model or estimation? Because the IRFs seem to match the book it would seem that the model is set up correctly. Perhaps the error is with the way the observation equations are set up? Or with the priors?

(2) Can anyone point me to some code for a simple estimation of the NK model? In this way I could work from this to try and find my error.

I have attached the mod file that performs the estimation here. Please let me know if you have any questions, and thank you.

Thank you so much for your help. The code that you added works well.

My question remains, however, why the original code did not run. It turns out the code runs fine with my original IS equation. The crux of the matter is the code breaks down once I insert the measurement equations. These are the exact equations seen on page 19 of the Herbst and Schorheide book. Does anyone know why these measurement equations make the code break down? See attached the non-working code.

What do you mean with “breaks down”. First of all, there is an identification problem in the model:

Testing prior mean
WARNING !!!
The rank of H (model) is deficient!
[psi2,psi1] are PAIRWISE collinear (with tol = 1.e-10) !
WARNING !!!
The rank of J (moments) is deficient!
[psi2,psi1] are PAIRWISE collinear (with tol = 1.e-10) !

Moreover, the prior may be problematic, because it is quite tight for the mean, pushing the model to have a unit root to explain the different mean in the observables.

By “breaks down” I should have said “gives strange results”. In particular, the code as written gives very strange posterior results, which are not similar to the results from the original book.

Hi. As far as I understand you tried to simulate the model. I want to do Bayesian estimation. I have questions why steady state equations that define gammaq, piea and ra are not present in the model file. Here is the picture of the equations that I am talking about.

As far as I understand this is a simulation. I tried to estimate this model by changing this model file but I failed. How would you estimate this model?