Simulation working but estimation not

Hello everyone!
I am trying to estimate a NK DSGE model with Bayesian methods but having trouble with it. I checked all threads on this topic and made several adjustments to the model,estimation settings, the data etc. but the problem persists. The priors are taken from the literature. There must be something related with the nonstationarity of the variables in the model as the optimization already shows some warnings on it. Simulating the model with calibrated parameter values is working fine though.

I attached the mod file and the data, so if anyone with some more experience could have a look I would appreciate it a lot!

Thanks in advance!

NK.mod (21.4 KB) Onesidedhp.xlsx (24.7 KB)

What exactly is the error message you are experiencing?

Here’s the error message:

Log data density [Laplace approximation] is NaN.

Error using chol
Matrix must be positive definite with real diagonal.

Error in posterior_sampler_initialization (line 84)
d = chol(vv);

Error in posterior_sampler (line 60)
posterior_sampler_initialization(TargetFun, xparam1, vv,

Error in dynare_estimation_1 (line 465)

Error in dynare_estimation (line 105)

Error in NK_euro_v2.driver (line 1444)

Error in dynare (line 293)
evalin(‘base’,[fname ‘.driver’]) ;

The message comes after quite a time of optimizing the posterior, hence before the MH algorithm. Thanks in advance for your help!

Did you have a look at the mode_check-plots.

Yes I did, it seems that the algorithm does not find the maximum. Often the plots look pathological, the posterior is not defined (red dots) and has kinks in the graph.

Could you provide the _mode.mat-file?

Here it is:

NK_mode.mat (21.2 KB)

This is clearly not the global mode. If I load your mode-file and continue with mode_compute=5, there is still significant improvement.

Thank you!

Still, the mode_check plots look quite weird and with a lot of non-defined points. In addition, the MH algorithm does not start. Instead, I get a similar error message like the one posted above, saying that the covariance matrix is not positive definite. Do you have an explanation for this?

Please provide the new mode-file.

NK_mode.mat (4.1 KB)

  1. Did you check identification? Some of the mode-check plots seem to be horizontal.
  2. Most of the red dots come from the

Warning: univariate_diffuse_kalman_filter:: There isn’t enough information to estimate the initial conditions of the nonstationary variables

warning in which case the likelihood is NaN.
3. With respect to the previous point: are you sure your model is correct? Almost all of your variables have a unit root, even inflation rates (implying the price level would be I(2))

Actually I am quite confident that the code is correct, but I will check it again and report.

  1. You can usually identify affected variables by having NaN-moments. Alternatively, use periods=1000 for IRFs and check which variables do not return to steady state.
  2. When you say

how do you conceptualize “working”? Are unit roots in real variables an expected outcome?

Good morning! By “working” I mean that there are no unit roots in the model and the estimation yields sensible results. In the model versions with >2 countries there is at least one unit root and the estimation breaks down after the optimization, partly because the log data density cannot be computed or the VCV matrix is singular.

I don’t understand where the unit root comes from, actually there shouldn’t be one. I suspect it to be related to the net foreign asset position or the ToT, which are now with respect to more than one country.

Then you should focus on that part of closing the model. Unit roots in the NFA position are common small open economy models if not closed properly.