Bayesian estimation: Log data density [Laplace approximation] is NaN

Dear Professor:
I am using Bayesian estimation to estimate the parameters of DSGE model shocks, when directly assigning values to shock parameters, the program works fine; but when estimating shock parameters with Bayesian estimation, the following error message appears

Log data density [Laplace approximation] is NaN.

wrong using chol
he matrix must be positive definite with real diagonals.

wrong posterior_sampler_initialization (line 84)
d = chol(vv);

wrong posterior_sampler (line 60)
    posterior_sampler_initialization(TargetFun, xparam1, vv, mh_bounds,dataset_,dataset_info,options_,M_,estim_params_,bayestopt_,oo_);

wrong dynare_estimation_1 (line 471)
wrong dynare_estimation (line 118)

I don’t know where is the problem? Hope to get advice from professors, thank you very much!
In addition, the observed variable data estimated by Bayesian is the data obtained by the actual data after X12 seasonal adjustment and HP filtering. The procedure and data for Bayesian estimation are as follows
paper_estimate.mod (6.2 KB)
paper_data.mat (4.5 KB)

Identification tells you

    phi_p is not identified!
    SE_e_x1 is collinear w.r.t. all other parameters!
    rho_x1 is collinear w.r.t. all other parameters!

Thanks for your advices, Professor Jpfeifer.
But where can I see the identification? There is no error message you gave in my matlab running result

Add an identification-command to your mod-file.

  1. phi_p is clearly not identified at first order as it is always multiplied by a qudratic term that is 0 in steady state and therefore drops out. Why is there no FOC containing

as is usual?
2. See Estimation of parameters - #2 by jpfeifer
3. The correctness of the observation equations is hard to judge. You are not supposed to use the two-sided HP-filter. Also, it’s unclear whether the frequency of the interest rates in the data and the model matches.

  1. This may be because my model has some errors, my price adjustment cost should be changed from (C_t^P)/P_t ϕ_p/2 ((P_t (i))/(P_(t-1) (i) )-1)^2 Y_t (i) to (C_t^P)/P_t ϕ_p/2 ((P_t (i))/(P_(t-1) (i) )-1)^2 Y_t;also the FOC condition about price is missing
    2、Thanks for the suggestion, I will have a try
    3、ye,I do use the two-sided HP-filter,I will try one-sided HP-filter
    Thanks for your help again,Professor.

hello professor
My operational results go back to the original question ‘’Log data density [Laplace approximation] is NaN."; the identification-command also doesn’t show that there is an identification problem. I have been unsuccessful in finding the problem by removing one observed variable at a time and mode_check-plots.
My data processing process is as follows:
The raw data RAT has not been processed, and is used as the observation data of the benchmark interest rate. The observation equation is vr_obs = vr*4;
The raw data GDP, social retail product consumption, M2-M0 have all been processed by X12-ARIMA, logarithm, one-sided HP filter, and the processed data are used as time series of vy_obs, vc_obs, and vd_obs respectively. The observation equation takes vy as an example, as follows:
vy_obs = log(vy)-log(vy_ss);
I hope the professor can help me solve this problem, thank you very much!

You are not handling parameter dependence correctly. In e.g.

vy_obs =log(vy)-log(vy_ss);

the value of vy_ss is fixed before estimation and will not be updated when the parameters change.
See e.g.

good day ! Prof.Pfeifer
So how should I solve this problem?
If I change the way of assigning initial values to variables in my mod file from initval-block to steady_state_model-block (just like listing6 in Pfeifer(2013):“…”), then change the variable steady state in the observation equation The value is obtained using the steady_state()-operator (as in listing7 in Pfeifer(2013):“…”), e.g.

vy_obs = log(vy)-log(steady_state(vy));

Can it solve the problem?

Yes, that would solve the problem.

Happy day! Prof.Pfeifer
Sorry to bother you again.I have two questions aboutsteady_state_model-block to ask you
In steady_state_model-block, the steady-state values of all exogenous variables can only be calculated with structural parameters, or with exogenous variables and structural parameters that have been calculated.
If I only consider an economic model with zero inflation, can I set vpi (level variable via inflation) = 1directly in steady_state_model-block?
Or can I only set the initial value of the inflation rate to 1 in the initval-block?
The foc conditions of my model includevpi(vpi-1) and (vpi-1)^2, and it is relatively difficult to solve the specific expression of vpi; my previous choice was to assign an initial value of 1 to vpi and an initial value to labor is 1/3, then the parameters omega and psi are solved by expressions; but in the case of steady_state_model-block, the parameters omega and psi are not feasible by expressions, what should I do?
In this case, isn’t it just a matter of changing the model to log-linear form?

  1. If you only allow vpi=1, then that’s the steady state.
  2. Clearly, with vpi=1 the terms you mention reduce to 0.
  3. I don’t get the second point about expressions. You can assign parameter values in steady_state_model-blocks.
  4. Linearization will not help. See
  1. yes, I mean set the steady state of the vpi to 1
    2.The second point about expressions means in my steady_state_model -blocks parameters psi and omega is computed by other parameters and variables. Following is my steady_state_model -blocks:
psi =vlambda*vw/vn^phi_n; %parameter psi 
vd = (1-afa_0)*vc;
omega = beta*(vr_h-vr_dc)*vd;  %parameter omega

vy_obs = 0;
vc_obs = 0;
vd_obs = 0;
vr_obs = vr;
  1. I assign parameter values in steady_state_model -blocks like above,but my mod file can not run successfully, i don’t know why.Following is “error message”:
Wrong use print_info (line 32)
The steadystate file did not compute the steady state

Wrong dynare_estimation_init (line 619)
    print_info(info, 0, options_);

Prof.Pfeifer , I have solved the above problem according to Remark 5 in your guide book, but the old problem comes back again!

Log data density [Laplace approximation] is NaN.

wrong using chol
he matrix must be positive definite with real diagonals.

wrong posterior_sampler_initialization (line 84)
d = chol(vv);

  1. Your prior is strange. You put an extremely high mass on very low shock volatilities.
  2. All your data is demeaned, but vr_obs still contains the non-zero steady state.
  3. You did not correctly set prior_trunc.

Prof. Pfeifer:
I have made some changes for my prior, and correct the data treatment of vr_obs (according to 4.3.3 Interest Rate in your book), and use mode_compute=6

Now the code runs successfully, thank you very much for your help these days.
Have fun every day!!!