Keeping getting error when doing bayesian estimation in Dynare

Hi,

I am using Bayesian estimation in Dynare. However, I keep getting the error in the following. I double checked the mod file and data file (dataS1), the variable names are the same.
I am confusing what is the problem now.
It is highly appreciated that anyone could help me to figure out the problem.

Thanks
Kevin

Reference to non-existent field ‘c’.

Error in read_variables (line 84)
dyn_tmp_01 = s.(deblank(var_names_01(dyn_i_01,:)));

Error in initialize_dataset (line 32)
rawdata = read_variables(datafile,varobs,[],xls.sheet,xls.range);

Error in dynare_estimation_init (line 475)
dataset_ =
initialize_dataset(options_.datafile,options_.varobs,options_.first_obs,options_.nobs,transformation,options_.prefilter,xls);

Error in dynare_estimation_1 (line 81)
[dataset_,xparam1, hh, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list_,
dname, [], M_, options_, oo_, estim_params_, bayestopt_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in sme_estimation (line 399)
dynare_estimation(var_list_);

Error in dynare (line 180)
evalin(‘base’,fname) ;

dataS1.xlsx (14.4 KB)
sme_estimation.mod (5.0 KB)

I get no error except that Dynare says it cannot read dates in the spreadsheet. So, the estimation runs when I remove the dates column. Can you make sure that you still get the same error?

Given that the dates can not be recognized and there is column header for the dates column, you need to specify the xls_range-option:
xls_range=B1:E97
Note that your linear model does not work correctly. The equation

rd = 0.8 * (rl - 1) + 1;

has a residual given initial values of 0, resulting in a strange steady state. Also, you seem to not handle parameter dependence correctly and the data treatment is wrong. You cannot match trending data to a stationary model. See Pfeifer(2013):“A Guide to Specifying Observation Equations for the Estimation of DSGE Models”

Hi,

I removed both dates and variable names in the spreadsheet since it still couldn’t work when I removed the dates only. Then I used a separate m file to define variables accordingly, then it works fine.

Thanks for the reply.

Hi Pfeifer,

Thanks for raising the issues. It is highly appreciated.
I used a separate m file to define variables and detrended the data. However, I got another error,

Error using chol
Matrix must be positive definite.

Error in metropolis_hastings_initialization (line 68)
d = chol(vv);

Error in random_walk_metropolis_hastings (line 63)
metropolis_hastings_initialization(TargetFun, xparam1, vv,
mh_bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation_1 (line 782)
feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in sme_estimation (line 398)
dynare_estimation(var_list_);

Error in dynare (line 180)
evalin(‘base’,fname) ;

In terms of the linear equation, I attached a document to explain it, it simply implies the relationship between deposit rate and borrowing rate. I checked the steady states I got, indeed it is very strange. However, I am not sure what is the problem that caused this issue, is it just because of this linear equation?

For the parameter dependency, I read the document you suggested, and added model-block symbol in front of the dependent parameters. However, it shows
ERROR: sme_estimation.mod: line 65, cols 1-23: RL has wrong type, you cannot use it within as left-hand side of a pound (’#’) expression. I do type the dependent parameters below model block rather than in the parameter block. However, it still shows the same error.

Many thanks
prepare_data.m (404 Bytes)rd and rl.pdf (49.5 KB)
sme_estimation.mod (5.1 KB)

Hi,

I managed to run your codes, however with the end result that dynare reports:

STEADY: numerical initial values or parameters incompatible with the following equations
10 11 20 24
Check whether your model is truly linear. Put “resid(1);” before “steady;” to see the problematic equations.

Basically, you have to rename the steady state expressions declared with “#”. Also, you didn’t declare “Net_QK” as a parameter. After you do the these changes the model runs and ends with the above error message.

Also, in your codes you write:

#RL = R/0.95

Is 0.95 = \rho? If yes I would rather write:

#RL = R/rho;

and the same for:

#RK = RL + 0.05;

Treat my changes with caution as wouldn’t consider myself an expert.

Best

Rob

Hi Robert,

Thanks for replying me! Really appreciated.

The numbers in both #RL = R/0.95 and #RK = RL + 0.05 are just numbers, they are not parameters in the model. But thanks for reminding me.

By the way, please accept my apology for my stupid question, when you say rename the parameters, do you mean rename all of them in the entire mod file with # operator? I am not quite sure how did you modify it. Could you please post the file here that I can directly have a look?

Many many thanks

Sorry, I forgot to upload the mod file.

sme_estimation_updated.mod (5.1 KB)

Thanks for the prompt reply!

I ran the code you uploaded just now. The reason we got the error is the renamed parameters are not renamed in the following equations, i.e. 10 11 20 24. So I renamed them all with ‘zz’. Then it ran successfully. However, again I got the error,

Log data density [Laplace approximation] is -1053619455.033597.

Error using chol
Matrix must be positive definite.

Error in metropolis_hastings_initialization (line 68)
d = chol(vv);

Error in random_walk_metropolis_hastings (line 63)
metropolis_hastings_initialization(TargetFun, xparam1, vv,
mh_bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation_1 (line 782)
feval(options_.posterior_sampling_method,objective_function,options_.proposal_distribution,xparam1,invhess,bounds,dataset_,options_,M_,estim_params_,bayestopt_,oo_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in sme_estimation_updated (line 388)
dynare_estimation(var_list_);

Error in dynare (line 180)
evalin(‘base’,fname) ;

Notice that the Log data density is extremely strange. I got another version of my code (with different values of parameters), and that one produce -444 which is still seems incorrect.

Many thanks again!

The size of the likelihood indicates an inconsistency between the model variables and the empirical data treatment. Did you follow the descriptions in Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”?

Hi Professor Pheifer,

Thanks for your reply.

I am learning it now. It is really helpful. The parameter dependence should be fixed now by adding the # operator. And I detrended the data before simulate the model. Then I managed to run the code and got the estimation results.
In terms of the linear model does not work correctly, I still cannot figure out what is the problem with the model. The equation you mentioned in your first post is a necessary condition between deposit rate and lending, so I am not sure how do I modify it.
Please have a look at the mod file again.sme_estimation.mod (5.0 KB)

Many thanks

You need to fix your equations before doing estimation. The condition you describe seems to not be properly linearized.