# Deterministic simulation - Newton direction not finite

Hello,

please find attached a code of deterministic simulation.

The same model is running when (*):

• not deterministic simulation is considered, but stochastic
• when I Bayesian estimate the model.

The error message I get during deterministic simulation is the following:
“Some element of Newton direction isn’t finite. Jacobian maybe singular or there is a problem with initial values”

In more detail:
“An infinite element was encountered when trying to solve equation(s) 54 with respect to the variable(s): iff.”

Please give me some advice, I am completely lost. Because of (*), but especially because equation 54 does not contain variable iff.

Thank you very much in advance!
SA_det_new.mod (12.9 KB)

Ignore the message for now. It is very often helpful in detecting issues, but not always 100% spot on. The problem arises when computing the terminal steady state. You provide final values for the states and then try to compute the steady state. That operation fails. You can see that the equations with residuals are equation 54 and 69. Try to find out why there is trouble with these equations. For starters try e.g. using a terminal steady state that is closer to the original one and see whether Dynare is able to solve it. Apart from that: What is the underlying change in states that you try to simulate? Could it be that your model only has one unique steady state given the parameters?

Thank you for the quick feedback, I really appreciate it!

I tried another terminal SS, one very close to the original one, but I still get the same error message (ie. I multiplied the original SS value of ENTRNY by 0.99).

I am simulating deregulation policies. So e.g. ENTRYNF is an entry cost a firm must pay in sector F, and I decrease it by 1% when I multiply it by 0.99.

The original SS was calculated by Matlab as well (in a separate file though), and it seems to be robust for me.

Did you try computing the steady state in the stochastic model for the lower entry cost and entering it as the terminal condition?

Unfortunately it is not possible.

The reason is that ENTRYNF variable is an outcome of the steady state file, and the way it is calibrated is not that I only change one parameter, but its value depends on all the SS parameters.

Then I don’t understand what you are doing. If ENTRYNF in steady state is uniquely determined by the parameters of the model, then you cannot exogenously change it. Say the model in steady state determines that:
ENTRYNF=f(alpha,beta)

Changing ENTRYNF, i.e. the left hand side means that something on the right hand side needs to give. If this is not the case, no steady state exists, because ENTRYNF will not be equal to the function of parameters that determines it.

ENTRNYNF is also a function of other variables of the model, e.g. the profit of the firm. My model is quite rich because there are two sectors, so the SS is not solved by paper and pencil, but numerically. ENTRNYNF is a function of structural parameters plus other variables, like all variables in the model. So if in the new SS ENTRYNF is different from its value in the original SS, then the structural parameters are still the same of course, but other avriables of the model must also change to have an equilibrium.

I am just wondering if that is possible in your model. Consider the standard RBC model. There, all steady state values are a function of deep parameters only and the steady state value of TFP, the exogenous state. Given TFP, the steady state is unique. You could not assume a different steady state for capital, because there is only one unique steady state. If you want a different steady state for capital, either the steady state of exogenous TFP needs to adjust or one of the parameters. If there is a unique steady state given these objects, you cannot say other endogenous variables adjust, because they have unique steady state values and can not take any other value.

I will think about this, you might be right. However, with a similar model I did a similar simulation before, and then it was working, so I am not sure whether this is the problem. But thanks, I will check my steady state calculation file, too.

I have a question related to what you have just said.

Please have a look at lines 22-23 of the uploaded code file. Are you saying that when I change ENTRYNF in the new SS compared to the original SS, the values of all other shock values in these two lines must be fixed at their original SS value?! Because you are right, this a different approach I have been doping so far.

Now you lost me again. Exogenous states must be exogenous. Equations like

```ENTRYNF = (1-deltaNF)*PROFITF + (beta*CS(+1)/CS*(C-h*C(-1))/(C(+1)-h*C))*(1-deltaNF)*ENTRYNF(+1); ```
make it look like ENTRYNF is endogenous, i.e. evolves over time depending on endogenous objects. You can specify exogenous states, but not endogenous ones.
In my RBC example, TFP is an exogenous state. It evolves given an exogenous law of motion or according to values you specify. In contrast, capital is an endogenous state. It evolves according to the optimal decisions of agents. You cannot provide an arbitrary steady state value for capital without making TFP adjust, i.e. without switching the roles of the endogenous and exogenous states.

I see. I misunderstood you then.

But actually what I was thinking that you were saying was also a mistake, even if you did not say that. So I changed it, and now I do not get that error message as before, no problem with eq-s 54 or 69 or variable iff. Also, the code does not say that the endval SS is not a SS. I uploaded the updated file.

There is a new problem though, namely that the path between the 2 SS-s is still not okay, matrix is singular. I tried to change simulation options (periods, stack_solve_algo and maxit) as follows, but it did not help:

"1. stack_solve_algo=0 or 6
0:
Warning: Matrix is singular to working precision.

In sim1 at 128
In simul at 126
In SA_det_new_3 at 758
In dynare at 180
Simulation terminated with NaN or Inf in the residuals or endogenous variables. There is most likely something wrong with your
model.
6:
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
In sim1_lbj at 85
In simul at 128
In SA_det_new_3 at 758
In dynare at 180
I terminated it, as it was running for a long time, so this is the only error message I see.

1. block, stack_solve_algo=1 or 2 or 3 or 4 or 5 or 6
1, 2, 3, 4, 5, 6:
Undefined function ‘T3’ for input arguments of type ‘double’.

2. periods=2000

3. maxit=10000"

Regarding your point, I see what you mean. But, that equation is not a mistake. Entry is endogenous in my model. It means that there is a fixed entry cost which is equal to the discounted value of future profits by definition. This equation works perfectly fine when I consider stochastic simulation or Bayesian estimation (when ENTRYNF is a stochastic shock, ie. an exogenous state which is still related to an endogenous variable, PROFITF). So should I get rid of this equation? Then I have 2 more variables than equations…

What do you think?
SA_det_new_3.mod (11.8 KB)

This is just to let you know that there was a mistake in the equation you referred to (and 2 others related to that one).
As a result, the stochastic simulation code and the Bayesian estimation code were still running and gave sensible results, but the deterministic simulation code broke down. The latter is much more sensitive as it seems, fortunately.
Thank you for your hints to solve this issue!