Residuals of static equations have NaN

Dear all,

I’m trying to find the steady state of my model, using an external _steadystate.m file. I’ve tried to solve the steady-state values analytically, but there is one non-linear equation for labor (n), so I have to resort to the m. file to call fzero function. However, the residuals of the static equations have a lot of NaN’s like this:

Equation number 1 : NaN : 1. Euler equation
Equation number 2 : NaN : 2. Labor supply
Equation number 3 : 0 : 3. UIP
Equation number 4 : NaN : 4. Household budget constraint
Equation number 5 : -0.25 : 5. Domestic price dispersion
Equation number 6 : -0.25 : 6. Import price dispersion
Equation number 7 : NaN : 7. External debt interest rate
Equation number 8 : NaN : 8. FOC labor input
Equation number 9 : NaN : 9. FOC investment
Equation number 10 : NaN : 10. FOC capital
Equation number 11 : 0 : 11. Production function
Equation number 12 : 0 : 12. Law of motion for capital of domestic producers
Equation number 13 : NaN : 13. Domestic reoptimized price
Equation number 14 : NaN : 14. Aux var x1
Equation number 15 : NaN : 15. Aux var x2
Equation number 16 : 0 : 16. Domestic goods inflation
Equation number 17 : NaN : 17. Imported reoptimized price
Equation number 18 : NaN : 18. Aux var g1
Equation number 19 : NaN : 19. Aux var g2
Equation number 20 : 0 : 20. Imported good inflation
Equation number 21 : NaN : 21. Wholesale Bank interest rates
Equation number 22 : -0.00725 : 22. Retail Bank interest rates
Equation number 23 : 0 : 23. Bank balance sheet
Equation number 24 : 0 : 24. Law of motion for capital of banks
Equation number 25 : NaN : 25. Bank profits
Equation number 26 : 0 : 26. Goods market clearing
Equation number 27 : 0 : 27. Local demand for domestic goods
Equation number 28 : 0 : 28. Local demand for imported goods
Equation number 29 : 0 : 29. Foreign demand for domestic goods
Equation number 30 : 0 : 30. Total consumption
Equation number 31 : 0 : 31. credit market clearing
Equation number 32 : 0 : 32. CPI based inflation
Equation number 33 : 0 : 33. P_h to P
Equation number 34 : 0 : 34. P_f to P
Equation number 35 : 0.97972 : 35. Taylor Rule
Equation number 36 : NaN : 36. Technology Shock
Equation number 37 : NaN : 37. Foreign output Shock
Equation number 38 : NaN : 38. Monetary shock

I don’t really understand what happened or how Dynare works.

For example, in the case of the Euler equation, I set the steady-state value of interest rate as dependent on beta & the target inflation, according to the relationship 1=beta*(1+r)/(1+pi). Beta and target inflation have already been set as parameters. So, as I understand, if I set r=(1+pi)/beta-1, then it automatically satisfies the Euler equation, and the residual of that equation should be zero. However, Dynare returns NaN residual for that equation.

Similarly, in the 3 equations for the shocks, they also show NaN residuals even though I set the shocks equal to 1 in the steady state.

Or in the case of the Taylor rule, I set the steady-state values of interest rate and inflation equal to the target, it should give me zero residual instead of a non-zero residual as it turns out in my case.

One more thing, Dynare gives me a warning that “Some of the parameters have no value (d_bar) when using steady.”, but I have set the parameter d_bar=d, the value which is computed in the _steadystate.m file. So, I guess this is not the problem.

Can someone please look at my codes and tell me why I got NaN residuals? Many thanks in advance.
TS_nln_nexp.mod (11.3 KB)
TS_nln_nexp_steadystate.m (4.8 KB)

1 Like

You have the condition

if d_bar<0 % parameter violates restriction; Preventing this cannot be implemented via prior restriction as it is a composite of different parameters and the valid prior region has unknown form
    check=1; %set failure indicator
    return; %return without updating steady states
end

that is triggered, so the remaining variables are not set at all.

Thank you Prof Pfeifer.

I’ve removed that condition and the codes worked, and I’ll need to fix some equations with non-zero residuals. However, I do need that condition to be satisfied in my model. I guess I’ll have to change some parameters then.

By the way, I have one question regarding the use of exp() substitution. There are some variables in my model that I would like to just linearize instead of log-linearize. So, can I leave those variables alone and just substitute exp() for the other variables that I’d like to log-linearize?

Yes, as long as you stay consistent, there is no problem with substituting just a few variables.

Hello!
I am doing a simulation with a NK model with external sector. I’ve written the equation, set value for the parameters and initial values for the endogenous. However, the model cannot solve because it can’t find steady state value. I tried to set some initial values at their static values using steady state solutions. However no success. I don’t know how to write a Matlab code to find the steady state value. Could anyone help me on that isssueessai1.zip (1.7 KB)
Please see the mod file enclosed

I a not sure what you are doing. Your model will have a unit root, meaning there are infinitely many steady states so that the steady state cannot be endogenously computed. But your model is already linearized. Simply delete the `initva -block or set all values to 0. Unfortunately, this will only reveal an indeterminacy problem, most likely due to a timing error.

1 Like

Dear Prof Pfeifer,

I have a follow-up question regarding the steady state. I have fixed the setup of my model, and now the steady state can be computed. The error about the residuals does not show up anymore. But there is another error saying that there is 1 colinear relationship between the variables and the equations. Does this mean that the equations in my model are correct as the steady state can be computed? And should I proceed to fix the problem of colinear equations, or is it still the problem of the steady state?
Here are my files
TS_nln_nexp.mod (11.2 KB)
TS_nln_nexp_steadystate.m (4.9 KB)

That is hard to tell. The error you get about

One of the eigenvalues is close to 0/0 

must be fixed. So there still must be something wrong. It could simply be a timing problem or something more fundamental like having a redundant equation in there, while a different one is missing.

Thank you for your reply. I’ll try to figure out what the problem is.