I am estimating a small open economy model. I keep getting the following error message after the estimation:

Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 6.665321e-019.

In DiffuseKalmanSmoother3 at 289
In DsgeSmoother at 272
In prior_posterior_statistics at 152
In dynare_estimation_1 at 1084
In dynare_estimation at 62
In conglin2010 at 519
In dynare at 132

I am not sure where the problem comes from. When I do simulations using the model, the results are ok. So I guess the problem may come from the data. I demeaned and detrended the data (the data series are also seasonally adjusted.)

Attached is my mod and data file. By the way, I am using 4.1.2.

Actually, it does not look like an error, but rather like a warning. I guess, Dynare does not crash, does it? This warning may indicate a real problem, but sometimes matrices become ill-conditioned even in well-specified problems. Moreover, this problem only occurs in the smoother routines, where you try to recover the shock series. Hence, you could check if the previous estimation results make sense to see if there is a problem.
Finally, from a quick look at your data, I wonder how you detrended the data. An ADF-test still indicates the presence of a unit root. So there may really be a problem with the data and the corresponding model specification.

Hi jpfeifer, thanks very much! You are right, Dynare doesn’t crash. After all these warnings, it continues to finish its simulation job.

I demeaned and detrended (linear detrend) the data using the command “detrend” of matlab. I will check the data again.

Also, I am wondering, assume that there is no problem in data and the model but only the ill-conditioned matrice, could I rely on the estimation results especially when the results look good?

I would answer your last question with yes. However, your data is almost surely the problem. To stationarize your data, you might want to consider HP-filtering it or use first differences and specify an observation equation. Or when using a linear trend, you should at least log the data to make the exponential trend linear.