I have a question to the following code (attached). It is a SIR model with perfect foresight. With the Newton method I get the warning “Matrix is close to singular or badly scaled. Results may be inaccurate.” or “Matrix is singular to working precision” and after the maximum of iterations Dynare is switching to a homotopy method. The results that I obtain seem to make sense, though.
I am now wondering if I can trust the results and whether there is a possibility to avoid these warnings and to make the Newton method work.

Would be great if you could help me. SIR.mod (1.8 KB)

I am now trying to set up a version of the same SIR model as the one above (with a different utility function though) with a Ramsey planner. Here, the homotopy method is not working and the perfect foresight model cannot be solved. When I run model_diagnostics(M_,options_,oo_), I get the message “MODEL_DIAGNOSTICS: The steady state cannot be computed”.

However, when I use the same model with the same initval and endval block (except for the instrument) without the Ramsey planner (and now having the instrument as part of the parameter block), the model can be solved, so there it seems that there is no issue with the steady state.

Do you know what the problem could be?

Any help would be much appreciated! SIR_Ramsey.mod (1.9 KB)

Are you sure there is a well-defined solution with the expected transition to a new steady state in the expected time? What if the Ramsey planner sets theta=0? Then the transition will take forever.

Thanks a lot for your answer!
I think with theta=0 there shouldn’t be a problem. In the steady state, theta should be equal to 0.
But it’s true that with theta=1, there would be a problem since then, there would be log(0) in the utility functions.
I tried the same code with a different utility function (quadratic instead of log utility), and it works (see attached). So maybe the problem comes from the log utility and the planner choosing a theta=1 (although this would lead to an extremely low utility (which is part of the planner’s objective) in one period, so I’m not so sure if this is actually the case).
Do you have any idea how to circumvent this problem having a log utility function? SIR_Ramsey_diffU.mod (1.9 KB)

Did you plot your solution? There is a big jump in the last period, suggesting you did not come close to the steady state. For example, R after 500 periods is just 0.0027.

Yes, with the Ramsey planner it’s pretty extreme. In the baseline model, there’s also a jump, but smaller. But since I’m only interested in the transition dynamics, I thought it doesn’t really matter (and it’s basically what Krueger, Uhlig and Xie do in their Covid paper). And the results seem to make sense, also when I play around with different paramters etc.

You are using a two-boundary problem. Having initial conditions for the backward-looking variables and terminal conditions for the forward-looking ones, you can solve the intermediate values. That approach will generally not be valid if you force the model to be back in steady state in the last period if you are still far away from it in the second to last period.

Thanks a lot for your reply! That makes sense. I will try to find a way so that the model converges to the steady state without the jump from second to last period.
But I think my problem with the Ramsey planner and the log utility is an additional one. Is there a possibility to somehow restrict the instrument, so that in my case theta cannot be 1?

May I ask again for your advice?
I changed the parameters of the model so that there is no large jump in the end anymore and S, I, and R are converging to their steady state values (0,0,1).

I also used ramsey constraints to avoid having an instrument outside (0,1). Unfortunately, the model still can’t be solved. Do you have any idea whay this is the case?
Please find attached the mod file. SIR_Ramsey.mod (2.0 KB)

Do you mean using the stoch_simul command instead of perfect foresight? Then I get this error message “Ramsey: The solution to the static first order conditions for optimal policy could not be found. Either the model doesn’t have a steady state, there are an
infinity of steady states, or the guess values are too far from the solution”

I think the problem is related to the steady state for the log utility version. When I use a quadratic utility function, it works. But I don’t see why the log utility function is creating these problems, when in steady state, theta=0.