Bayesian estimation has a problem

I’ve been unable to run it using bayesian estimation, and I’ve been having the following problem, which is my run interface problem.
Residuals of the static equations:

Equation number 1 : NaN
Equation number 2 : NaN
Equation number 3 : NaN
Equation number 4 : NaN
Equation number 5 : NaN
Equation number 6 : NaN
Equation number 7 : NaN
Equation number 8 : NaN
Equation number 9 : NaN
Equation number 10 : NaN
Equation number 11 : NaN
Equation number 12 : NaN
Equation number 13 : NaN
Equation number 14 : NaN
Equation number 15 : NaN
Equation number 16 : NaN
Equation number 17 : NaN
Equation number 18 : NaN
Equation number 19 : NaN
Equation number 20 : NaN
Equation number 21 : NaN

错误使用 print_info (line 90)
The steady state contains NaN or Inf

出错 steady (line 104)
print_info(info,options_.noprint, options_);

出错 bys (line 339)
steady;

出错 dynare (line 235)
evalin(‘base’,fname) ;

Here’s my code

var y r pi mg eg chi mc ec a z phi xi upsilon mug y_obs pi_obs mc_obs mg_obs r_obs chi_obs phi_obs;
varexo epsilon_a epsilon_eg epsilon_ec epsilon_z epsilon_xi epsilon_upsilon epsilon_r;
parameters omega_1 beta theta omega_2 omega_3 gamma_1 gamma_2 gamma_3 gamma_4 
gamma_5 gamma_6 gamma_7 gamma_8 rho xi_phi rho_r rho_y rho_pi rho_mug rho_a rho_eg rho_ec rho_z rho_xi rho_upsilon;
omega_1=1;
theta=0.8;
beta=0.98;
omega_2=0.195;
omega_3=0.035;
gamma_1=0.021;
gamma_2=0.14;
gamma_3=0.664;
gamma_4=0.554;
gamma_5=0.013;
gamma_6=0.155;
gamma_7=1.034;
gamma_8=1.011;
rho=0.777;
xi_phi=0.572;
rho_r=0.808;
rho_y=0.153;
rho_pi=1.980;
rho_mug=0.459;
rho_a=0.668;
rho_eg=0.623;
rho_ec=0.622;
rho_z=0.996;
rho_xi=0.679;
rho_upsilon=0.703;

model;
y_obs=ln(y);
pi_obs=pi;
mc_obs=mc;
mg_obs=ln(mg);
r_obs=r;
chi_obs=chi;
phi_obs=phi;
y=y(+1)-omega_1*(r-pi(+1))+omega_2*((mg-eg)-(mg(+1)-eg(+1)))+omega_3*((chi+mc-ec)-(chi(+1)+mc(+1)-ec(+1)))+omega_1*(a-a(+1));
mg=gamma_1*y-gamma_2*r+gamma_3*eg-gamma_4*chi-gamma_4*mc+gamma_4*ec;
mc=gamma_5*y-gamma_6*r+gamma_7*ec-gamma_8*chi-gamma_8*mg+gamma_8*eg;
pi=beta*pi(+1)+(1-theta)*(1-beta*theta)/theta*((1/omega_1)*y-(omega_2/omega_1)*(mg-eg)-(omega_3/omega_1)*(chi+mc-ec)-z);
chi=-rho*phi;
phi=xi_phi*xi+(1-xi_phi)*upsilon;
r=rho_r*r(-1)+(1-rho_r)*rho_y*y+(1-rho_r)*rho_pi*pi+(1-rho_r)*rho_mug*mug+epsilon_r;
mug=mg-mg(-1);
a=rho_a*a(-1)+epsilon_a;
eg=rho_eg*eg(-1)+epsilon_eg;
ec=rho_ec*ec(-1)+epsilon_ec;
xi=rho_xi*xi(-1)+epsilon_xi;
upsilon=rho_upsilon*upsilon(-1)+epsilon_upsilon;
z=rho_z*z(-1)+epsilon_z;
end;

varobs y_obs pi_obs mc_obs mg_obs r_obs chi_obs phi_obs;

initval;
y=0;
r=0;
pi=0;
mg=0;
eg=0;
chi=0;
mc=0;
ec=0;
a=0;
z=0;
phi=0;
xi=0;
upsilon=0;
mug=0;
end;

steady;

estimated_params;
theta,beta_pdf,0.8,0.05;
omega_2,gamma_pdf,0.2,0.05;
omega_3,gamma_pdf,0.05,0.01;
gamma_1,gamma_pdf,0.015,0.005;
gamma_2,gamma_pdf,0.15,0.05;
gamma_3,gamma_pdf,0.9,0.1;
gamma_4,gamma_pdf,0.5,0.05;
gamma_5,gamma_pdf,0.015,0.005;
gamma_6,gamma_pdf,0.15,0.05;
gamma_7,gamma_pdf,0.8,0.1;
gamma_8,gamma_pdf,0.6,0.1;
rho,gamma_pdf,0.9,0.1;
xi_phi,gamma_pdf,0.5,0.05;
rho_r,beta_pdf,0.8,0.05;
rho_y,beta_pdf,0.2,0.01;
rho_pi,gamma_pdf,1.8,0.05;
rho_mug,beta_pdf,0.2,0.05;
rho_a,beta_pdf,0.7,0.05;
rho_eg,beta_pdf,0.65,0.05;
rho_ec,beta_pdf,0.55,0.05;
rho_z,beta_pdf,0.9,0.05;
rho_xi,beta_pdf,0.6,0.05;
rho_upsilon,beta_pdf,0.6,0.05;
stderr epsilon_a,inv_gamma_pdf,0.01,inf;
stderr epsilon_eg,inv_gamma_pdf,0.01,inf;
stderr epsilon_ec,inv_gamma_pdf,0.01,inf;
stderr epsilon_z,inv_gamma_pdf,0.01,inf;
stderr epsilon_xi,inv_gamma_pdf,0.01,inf;
stderr epsilon_upsilon,inv_gamma_pdf,0.01,inf;
stderr epsilon_r,inv_gamma_pdf,0.01,inf;
end;

estimation(datafile=sysj2,mode_compute=6,mh_replic=2000,mh_jscale=0.8,mode_check,bayesian_irf);

Check your observation equations and add a steady_state_model-block for the non-zero variables. Also not that y has steady state 0. So taking the log of it will not work.

Dear professor, thank you for your answer.But I also have a question, in the above code base I modified the code.But there’s a problem. Here’s my error message.

initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became singular.
initial_estimation_checks:: This is often a sign of stochastic singularity, but can also sometimes happen by chance
initial_estimation_checks:: for a particular combination of parameters and data realizations.
initial_estimation_checks:: If you think the latter is the case, you should try with different initial values for the estimated parameters.

ESTIMATION_CHECKS: There was an error in computing the likelihood for initial parameter values.
ESTIMATION_CHECKS: If this is not a problem with the setting of options (check the error message below),
ESTIMATION_CHECKS: you should try using the calibrated version of the model as starting values. To do
ESTIMATION_CHECKS: this, add an empty estimated_params_init-block with use_calibration option immediately before the estimation
ESTIMATION_CHECKS: command (and after the estimated_params-block so that it does not get overwritten):

错误使用 initial_estimation_checks (line 143)
initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became singular.

出错 initial_estimation_checks (line 143)
error(‘initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became
singular.’)

出错 dynare_estimation_1 (line 165)
oo_ =
initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,bounds,oo_);

出错 dynare_estimation (line 105)
dynare_estimation_1(var_list,dname);

出错 bys2 (line 355)
oo_recursive_=dynare_estimation(var_list_);

出错 dynare (line 235)
evalin(‘base’,fname) ;

The number of observation variables I used and the number of shocks are the same, but there are still problems, so I would like to ask professor.Here’s my code

var y r pi mg eg chi mc ec a z phi xi upsilon mug;
varexo epsilon_a epsilon_eg epsilon_ec epsilon_z epsilon_xi epsilon_upsilon epsilon_r;
parameters omega_1 beta theta omega_2 omega_3 gamma_1 gamma_2 gamma_3 gamma_4
gamma_5 gamma_6 gamma_7 gamma_8 rho xi_phi rho_r rho_y rho_pi rho_mug rho_a rho_eg rho_ec rho_z rho_xi rho_upsilon;
omega_1=1;
theta=0.8;
beta=0.98;
omega_2=0.195;
omega_3=0.035;
gamma_1=0.021;
gamma_2=0.14;
gamma_3=0.664;
gamma_4=0.554;
gamma_5=0.013;
gamma_6=0.155;
gamma_7=1.034;
gamma_8=1.011;
rho=0.777;
xi_phi=0.572;
rho_r=0.808;
rho_y=0.153;
rho_pi=1.980;
rho_mug=0.459;
rho_a=0.668;
rho_eg=0.623;
rho_ec=0.622;
rho_z=0.996;
rho_xi=0.679;
rho_upsilon=0.703;

model;
y=y(+1)-omega_1*(r-pi(+1))+omega_2*((mg-eg)-(mg(+1)-eg(+1)))+omega_3*((chi+mc-ec)-(chi(+1)+mc(+1)-ec(+1)))+omega_1*(a-a(+1));
mg=gamma_1 *y-gamma_2* r+gamma_3 *eg-gamma_4* chi-gamma_4 *mc+gamma_4* ec;
mc=gamma_5 *y-gamma_6* r+gamma_7 *ec-gamma_8* chi-gamma_8 *mg+gamma_8* eg;
pi=beta *pi(+1)+(1-theta)* (1-beta *theta)/theta* ((1/omega_1) *y-(omega_2/omega_1)* (mg-eg)-(omega_3/omega_1) <em>(chi+mc-ec)-z);
chi=-rho</em> phi;
phi=xi_phi <em>xi+(1-xi_phi) <em>upsilon;
r=rho_r</em> r(-1)+(1-rho_r) *rho_y* y+(1-rho_r) *rho_pi* pi+(1-rho_r) *rho_mug* mug+epsilon_r;
mug=mg-mg(-1);
a=rho_a</em> a(-1)+epsilon_a;
eg=rho_eg <em>eg(-1)+epsilon_eg;
ec=rho_ec</em> ec(-1)+epsilon_ec;
xi=rho_xi <em>xi(-1)+epsilon_xi;
upsilon=rho_upsilon</em> upsilon(-1)+epsilon_upsilon;
z=rho_z*z(-1)+epsilon_z;
end;

varobs y r chi phi mg mc pi;

initval;
y=0;
r=0;
pi=0;
mg=0;
eg=0;
chi=0;
mc=0;
ec=0;
a=0;
z=0;
phi=0;
xi=0;
upsilon=0;
mug=0;
end;

steady;

estimated_params;
theta,beta_pdf,0.8,0.05;
omega_2,gamma_pdf,0.2,0.05;
omega_3,gamma_pdf,0.05,0.01;
gamma_1,gamma_pdf,0.015,0.005;
gamma_2,gamma_pdf,0.15,0.05;
gamma_3,gamma_pdf,0.9,0.1;
gamma_4,gamma_pdf,0.5,0.05;
gamma_5,gamma_pdf,0.015,0.005;
gamma_6,gamma_pdf,0.15,0.05;
gamma_7,gamma_pdf,0.8,0.1;
gamma_8,gamma_pdf,0.6,0.1;
rho,gamma_pdf,0.9,0.1;
xi_phi,gamma_pdf,0.5,0.05;
rho_r,beta_pdf,0.8,0.05;
rho_y,beta_pdf,0.2,0.01;
rho_pi,gamma_pdf,1.8,0.05;
rho_mug,beta_pdf,0.2,0.05;
rho_a,beta_pdf,0.7,0.05;
rho_eg,beta_pdf,0.65,0.05;
rho_ec,beta_pdf,0.55,0.05;
rho_z,beta_pdf,0.9,0.05;
rho_xi,beta_pdf,0.6,0.05;
rho_upsilon,beta_pdf,0.6,0.05;
stderr epsilon_a,inv_gamma_pdf,0.01,inf;
stderr epsilon_eg,inv_gamma_pdf,0.01,inf;
stderr epsilon_ec,inv_gamma_pdf,0.01,inf;
stderr epsilon_z,inv_gamma_pdf,0.01,inf;
stderr epsilon_xi,inv_gamma_pdf,0.01,inf;
stderr epsilon_upsilon,inv_gamma_pdf,0.01,inf;
stderr epsilon_r,inv_gamma_pdf,0.01,inf;
end;

estimation(datafile=sysj2,mode_compute=6,mh_replic=2000,mh_jscale=0.8,mode_check,bayesian_irf);

I cannot run your code due to strange characters in the code. Please upload both the mod-file and the data file

those are my mod-file and the data file.sysj2.xlsx (15.8 KB) bys2.mod (2.6 KB)

You are working with trending data. That cannot work.

Thank you very much for your answer. According to your answer, I have read relevant articles. I took the logarithm of the data and used HP filter to remove the trend.The observation equation was reset.But the ones that are running are still not working.Here’s my question.
Residuals of the static equations:

Equation number 1 : NaN
Equation number 2 : NaN
Equation number 3 : NaN
Equation number 4 : NaN
Equation number 5 : NaN
Equation number 6 : NaN
Equation number 7 : NaN
Equation number 8 : NaN
Equation number 9 : NaN
Equation number 10 : NaN
Equation number 11 : NaN
Equation number 12 : NaN
Equation number 13 : NaN
Equation number 14 : NaN
Equation number 15 : NaN
Equation number 16 : NaN
Equation number 17 : NaN
Equation number 18 : NaN
Equation number 19 : NaN
Equation number 20 : NaN
Equation number 21 : NaN

错误使用 print_info (line 90)
The steady state contains NaN or Inf

出错 steady (line 104)
print_info(info,options_.noprint, options_);

出错 bys (line 339)
steady;

出错 dynare (line 235)
evalin(‘base’,fname) ;
I was very confused.Hope to get your answer.Here are my code and data files.
sysj.xlsx (14.7 KB) bys.mod (2.8 KB)

When I run your code, I get

Error using initial_estimation_checks (line 145)
initial_estimation_checks:: The forecast error variance in the multivariate Kalman filter became singular.

I will upload my file again. Could you please run it in the same way?I’m running the results that I did abovebys.mod (2.8 KB) sysj.xlsx (14.7 KB)

You are still having the equation

mg_obs=ln(mg);

where you are trying to take the log of a variable that is 0 in steady state.

Thank you very much for your help. My program has been running.But my program came up with a warning.I am very confused, so I would like to ask you the reason for this warning and how to adjust it…Here’s my warning.

warning: estimation:: MCMC convergence diagnostics are not computed because the total number of iterations is not
bigger than 2000!

In McMCDiagnostics (line 126)
In dynare_estimation_1 (line 465)
In dynare_estimation (line 105)
In bys (line 388)
In dynare (line 235)
sysj.xlsx (14.7 KB) bys.mod (2.9 KB)
Looking forward to your reply. Thank you.

As the message says, your mh_replic is not bigger than 2000.