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

**URL:** <https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789>\
**Category:** Dynare help (legacy posts)\
**Created:** [24 October 2012 01:59 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789 "2012-10-24T01:59:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [24 October 2012 01:59 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/1 "2012-10-24T01:59:12Z")

</div>

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) ;

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [24 October 2012 06:28 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/2 "2012-10-24T06:28:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [24 October 2012 18:27 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/3 "2012-10-24T18:27:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [25 October 2012 02:38 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/4 "2012-10-25T02:38:07Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/d/db38056ab18c05525b8ebb242ebe8db63a8a7446.xls) (45 KB)  
[Full4.mod](https://forum.dynare.org/uploads/default/original/2X/d/dc7146a97486eb3abc98e23ac0a0491227130347.mod) (6.86 KB)

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [25 October 2012 23:20 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/5 "2012-10-25T23:20:56Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/d/d0352fee4a3aee54969ab258f0c5513e5d326c15.mod) (7.91 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [26 October 2012 06:54 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/6 "2012-10-26T06:54:45Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [26 October 2012 22:26 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/7 "2012-10-26T22:26:06Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/e/e117b32f3f446dac1d00dd43a9df03c42fd7e3ba.MOD) (7.45 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [29 October 2012 08:16 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/8 "2012-10-29T08:16:53Z")

</div>

This might be a bug. Could you try 4.2.5?

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [29 October 2012 21:45 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/9 "2012-10-29T21:45:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [30 October 2012 07:43 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/10 "2012-10-30T07:43:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichelJuillard](https://forum.dynare.org/user_avatar/forum.dynare.org/micheljuillard/32/5318_2.png) [@MichelJuillard](https://forum.dynare.org/u/MichelJuillard)\
**Post date:** [30 October 2012 16:57 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/11 "2012-10-30T16:57:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mknomics](https://forum.dynare.org/letter_avatar_proxy/v4/letter/m/a9adbd/32.png) [@mknomics](https://forum.dynare.org/u/mknomics)\
**Post date:** [1 November 2012 19:15 UTC](https://forum.dynare.org/t/how-do-i-debug-my-code-and-make-sense-of-this-error-msg/2789/12 "2012-11-01T19:15:51Z")

</div>

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!
