How do I debug my code?..and make sense of this error msg

Does anyone know the best way to decipher error messages in dynare? Currently I am getting the message below and it’s been tough to identify the problem.


NOTE:
The problem materializes in the “__static.m” file.

Through debugging in Matlab I have determined that the variable T166 is empty and being multiplied by y(24) which is a vector of zeros which gives an empty vector lhs. rhs is [1X1] NAN. Thus the error.

lhs =y(24)T166;
rhs =T56
T159*y(30)*params(3);

Most residuals are NAN because a majority of “T” variables are NAN, Inf, zero or 1.

Does anyone know what this might mean?


ACTUAL ERROR MESSAGE

??? In an assignment A(I) = B, the number of elements in B and
I must be the same.

Error in ==> Full4_static at 97
residual(14)= lhs-rhs;

Error in ==> dynare_solve at 83
[fvec,fjac] = feval(func,x,varargin{:});

Error in ==> evaluate_steady_state at 66
[ys,check] = dynare_solve([M.fname ‘_static’],…

Error in ==> dynare_estimation_init at 341
oo_.steady_state =
evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag);

Error in ==> dynare_estimation_1 at 59
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] =
dynare_estimation_init(var_list_, dname, ], M_, options_, oo_,
estim_params_, bayestopt_);

Error in ==> dynare_estimation at 70
dynare_estimation_1(var_list,dname);

Error in ==> Full4 at 859
dynare_estimation(var_list_);

Error in ==> dynare at 120
evalin(‘base’,fname) ;

Also, I have been getting error messages that tell me that my numerical initial values are incompatible with equation #'s … but I don’t know how to make sense of the equation numbers in the steady state file. I can find the equations but they have some T and Y variables that I can’t make sense of? How do I track down what y(#) is pointing toward?

The equation numbers refer to the equations in the model-block. Usually it means that in this equation you are dividing by 0. Are you using 4.3.1? If yes, please post the mod-file.

Hi there,

I am using the current version of dynare. The files attached are written written for the paper Schmitt-Grohe and Uribe Econometrica 2012 “Whats News in Business Cycles”.

Any help is greatly appreciated. Thanks again for reaching out.
Economet.xls (45 KB)
Full4.mod (6.86 KB)

I have made some changes and have attached current files.

What is the best systematic way for evaluating the mod file?

So far I have

  1. Used the Matlab variable editor to discover NAN values in the bayestopt_

Then I looked up the names corresponding to the parameter number in order to identify problem parameters by name, which allowed me to find the line in the mod file which contained the error.

  1. I repeated this process for M.params and noticed that estimated variables have NAN (I’m not sure if this is a problem?)

  2. I noticed that J-scale has a full vector of NAN

Current unresolved questions:

  1. estim_params_ contains two matrices that have scattered values of NAN and real numbers. I can’t make a correspondence with this matrix and my model?

  2. How can I fix this error, “Prior distribution for parameter RHOz has two modes!”

  3. I don’t understand how to resolve the problems listed in the error below. A systematic strategy would be greatly appreciated.

Thanks for helping me debug my first program.

The current error message that I am getting is the following


STEADY: numerical initial values incompatible with the following equations
1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 25 43
Please check for example
i) if all parameters occurring in these equations are defined
ii) that no division by an endogenous variable initialized to 0 occurs
??? Error using ==> dynare_solve at 98
exiting …

Error in ==> evaluate_steady_state at 66
[ys,check] = dynare_solve([M.fname ‘_static’],…

Error in ==> dynare_estimation_init at 366
[oo_.steady_state, params] = evaluate_steady_state(oo_.steady_state,M,options_,oo_,steadystate_check_flag);

Error in ==> dynare_estimation_1 at 59
[dataset_,xparam1, M_, options_, oo_, estim_params_,bayestopt_] = dynare_estimation_init(var_list_, dname, ], M_, options_, oo_, estim_params_,
bayestopt_);

Error in ==> dynare_estimation at 70
dynare_estimation_1(var_list,dname);

Error in ==> Full4 at 858
dynare_estimation(var_list_);

Error in ==> dynare at 120
evalin(‘base’,fname) ;
Full4.mod (7.91 KB)

Before estimating, make sure, you can simulate your model. That means in particular: define all(!) parameters properly before the model-block. That includes the autoregressive parameters!

Thanks for the direction.

My simulation didn’t run. The error takes place in the cond.m file. Specifically, the scalar value A takes on a fraction between zero and one, before being bounced back and forth between cond.m and dynare_solve.m where after several loops, fjac suddenly blows up to inf causing A to go to inf.

The Jacobian is poorly conditioned from the begining (bad_cond_flag=1). I’m not sure if this is because of poor starting values or from something more structural?

The .mod file for the simulation is attached and the error code that it produces is pasted below.


Error code:

STEADY: numerical initial values incompatible with the following equations
10
??? Error using ==> svd
Input to SVD must not contain NaN or Inf.

Error in ==> cond at 39
s = svd(A);

Error in ==> solve1 at 118
elseif bad_cond_flag && cond(fjac) > 1/sqrt(eps)

Error in ==> dynare_solve at 128
[x,info]=solve1(func,x,j1(r(i):r(i+1)-1),j2(r(i):r(i+1)-1),jacobian_flag,
bad_cond_flag, varargin{:});

Error in ==> evaluate_steady_state at 66
[ys,check] = dynare_solve([M.fname ‘_static’],…

Error in ==> resol at 108
[dr.ys,M.params,info] =
evaluate_steady_state(oo.steady_state,M,options,oo,0);

Error in ==> stoch_simul at 76
[oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);

Error in ==> sim1 at 1013
info = stoch_simul(var_list_);

Error in ==> dynare at 120
evalin(‘base’,fname) ;
sim1.MOD (7.45 KB)

This might be a bug. Could you try 4.2.5?

I uninstalled the current version and installed 4.2.5. The error message is virtually the same. Any suggestions on what I should do next? Thanks again for giving me direction.

I have only one suggestion: Compute the steady state with pen and paper. Also, put resid(1) before steady to see that your starting values are poor. You must get closer to the true values.

The problem is that mua and mux are defined as zero mean autocorrelated processes, but then enter directly the non-linear equations where zero is not an acceptable value. You probably want exp(mua) and exp(mux) in the non-linear equations, but check carefully.

Best

Michel

Thank you for the thoughtful responses. I am taking a moment to pause and consider this model more carefully.

It is inspirational to be the beneficiary in this benevolent forum. Hopefully, I will be in a position in the future to contribute more than questions!