Page 1 of 1

deterministic simulation - Newton direction not finite

PostPosted: Thu Jan 29, 2015 5:54 pm
by zsm
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!

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 7:10 am
by jpfeifer
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?

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 9:46 am
by zsm
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 9:49 am
by jpfeifer
Did you try computing the steady state in the stochastic model for the lower entry cost and entering it as the terminal condition?

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 10:09 am
by zsm
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 10:40 am
by jpfeifer
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 10:50 am
by zsm
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 11:09 am
by jpfeifer
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 11:16 am
by zsm
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 11:23 am
by zsm
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 12:37 pm
by jpfeifer
Now you lost me again. Exogenous states must be exogenous. Equations like
Code: Select all
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.

Re: deterministic simulation - Newton direction not finite

PostPosted: Fri Jan 30, 2015 1:01 pm
by zsm
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.

2. 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'.

3. periods=2000

4. 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?

Re: deterministic simulation - Newton direction not finite

PostPosted: Tue Feb 03, 2015 12:11 pm
by zsm
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!