The steady state contains NaN or Inf

Dear professor Pfeifer,

I built a simple real business cycle model. I’m trying to use Dynare to estimate the parameters for my model. However, I got “The steady state contains NaN or Inf” error all the time. I took several days to solve it, but couldn’t fix it. Because this is my first time to use dynare, I read the instructions and examples from dynare website. I borrowed the dynare code from the website, and modified its code. (I think this is an efficient way for a beginner.) But even the code I downloaded from dynare website has the same issue. (The code is written for F. Schorfheide (2000). It is named as fs2000ns.mod on dynare, and contained in model.zip file on dynare website.)
I would be obliged if you can help me solve this issue.

Basically, in my model, I already manually linearized all my first order conditions. So for example, the consumption c in my model is actually defined as ln(c(t)/c_bar), where c_bar is the steady state of consumption c(t). Based on this design, in my code, the steady state of consumption c is equal to 0 as guided in dynare user instruction. By doing so, all endogenous variables in my code have 0 steady state values. When I wrote down all my linearized first order conditions, it seems dynare couldn’t read those euqations, and might recognize them as nonlinear. Most of equations generate NaN rediduals. For example, the output function, y=ak^alphah^(1-alpha). After I linearized it, it becomes y=a+alpha*k+(1-alpha)*h. alpha as a parameter has been assigned a value which is 0.5519. But dynare couldn’t read this equation, and generate NaN residual. However, if I simply tested it out by writing the equation as y=a+k+h. It works. Why is that? How am I supposed to write my equations? I feel really confused and struggling.

I already attached my codes and data. Could you please help me find the reason? Thank you very much!!

Eric
rbc_model_work_folder.rar (10 KB)

As Dynare says:

Warning: Some of the parameters have no value (w, gamma, alpha, eta, phi, beta, psi_1, delta, N, z, rho_a, rho_g, rho_v, rho_u, rho_s, rho_r, tb_y, s_y, k_h, r_bar, g_bar, h_bar, k_bar, c_bar, y_bar, d_bar, s_bar, i_bar, tb_bar) when using steady. If these parameters are not initialized in a steadystate file or a steady_state_model-block, Dynare may not be able to solve the model...
You did never set alpha in the mod-file. That explains why

does not work while

does.

Related to this, you seem to be trying to set alpha in the _steadystate.m-file. But that file will not be used at all, if you provide a steady_state_model-block. Either use a steady state-file or this block, but not both.

1 Like

Hi Professor,

Thank you for the quick response. Following your advice, I think I fixed the steady-state issue. There is another question I hope you can help me to understand. When I assign values to all my parameters. Most of their values are either from literatures or by calibrations. There are only few parameters I would like to estimate. I saw some of examples, they assigned values for those parameters in parameters block first, and estimated those parameters in estimation block. So my understanding is we need to assign value for those parameters as starting points first, and then let dynare to estimate their best values. In my case, I need assign values to eta, phi, psi_1 and all rhos, even I need to estimate their value in estimation block. Is my understanding correct? Thank you very much!

Eric

You should always have a fully calibrated model. See Remark 2 (Using stoch_simul before Estimation) in Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models”.

Hi Professor,

Thanks for the response. I’ll fully calibrate my model first. Do you mind I ask you another question about variable timing? I’m reading the dynare instruction, and feel it is necessary to make it clear. In instruction, it seems that dynare doesn’t like forward timing. For example, if the real equation is k(t+1)=i(t)+(1-delta)*k(t), dynare prefers k=i+(1-delta)*k(-1).

Based on this, I suppose I have the following the equation in my model:
y(t+2)=F[y(t+1),y(t)];

Should I write:
var y;
predetermined_variables k;
y(+1)=F[y,y(-1)];
or
var y;
y=F[y(-1),y(-2)];
or
var y;
predetermined_variables k;
y(+2)=F[y(+1),y];

Which one is the correct way? Thank you very much for your great help!!

Eric

Professor,

My question might be confusing. The real question is if k is predetermined by k(t+1)=i(t)+(1-delta)*k(t), when I have a first order condition involves k(t+2), k(t+1), and k(t). How to write it?

k(t+1)=i(t)+(1-delta)*k(t);
y(t+2)=F[y(t+1),y(t)];

Should I write this way:
var y;
predetermined_variables k;
k(+1)=i+(1-delta)*k;
y(+2)=F[y(+1),y];

Thank you very much!

Eric

Hi,
it is still confusing. You talk about k(+2), but then there is only a y(+2). Is y in your example a predetermined variable? If not, then what you wrote down in your last post seems ok.

Hi Professor,
Sorry for the confusion. The two conditions are:
k(t+1)=i(t)+(1-delta)*k(t);
F[k(t+2),k(t+1),k(t),c(t),c(t+1)]=0;
where k is the capital, i is the investment, and c is the consumption.
Only k is predetermined variable (the first equation). But there is another first order condition (the second equation) involved with k(t+2), k(t+1), and k(t). In this case, how to write those two equations in dynare?

My understanding is: since only k is predetermined, I only need to take care of k. So there might be two ways to write:
1.
*var k c i;
model;
k=i+(1-delta)k(-1);
F[k(+1), k, k(-1), c, c(+1)]=0;
end;

2.
*var k c i;
predetermined_variables k;
k(+1)=i+(1-delta)k;
F[k(+2), k(+1), k, c, c(+1)]=0;
end;

Because c is not predetermined, I can still use c and c(+1). Is my understanding correct? Thank you very much!

Eric

Exactly. The two versions you wrote down are the two different timing conventions (stock at the end vs beginning of period). They are equivalent and should both work.

Thank you very much! Professor, :slight_smile:

Eric

Hi Professor,

Sorry for bothering you again. I’m facing an issue, and am hoping you can help me understand.

The first time I ran my dynare code, it gives me the error: the dynare gives me this notice:“
ESTIMATION_CHECKS: There was an error in computing the likelihood for initial parameter values.
ESTIMATION_CHECKS: You should try using the calibrated version of the model as starting values. To do
ESTIMATION_CHECKS: this, add an empty estimated_params_init-block with use_calibration option immediately before the estimation
ESTIMATION_CHECKS: command (and after the estimated_params-block so that it does not get overwritten)”

Following the notice, I wrote the code below:
**estimated_params;

	rho_a, uniform_pdf, , , -0.99, 0.99;
	stderr e_a, uniform_pdf, , , 0, 0.2;

end;
estimated_params_init (use_calibration);
rho_a, 0.9071144;
stderr e_a, 0.110610197;
end;
**

Is this correct way to write it? I thought I followed the instruction, but it seems something wrong. The dynare can successfully runs my code without error this time. However, when I set mh_replic=1000, it generates error “Matrix must be positive definite.” What does this mean? Thank you very much!!

Eric

This suggests there is something still wrong. Have a look at the mode_check plots. Regarding the error message, you are missing the actual message in your post. You only provided the suggestion to potentially fix the issue. Regarding your question: if you explictly provide starting values for all parameters, there is no point in using the

Hi Professor,

Thanks for the response. Basically, I have difficulty to understand dynare process for estimation. Let me use the following example to explain my questions:

**parameters bet;
bet=0.253;
rho=0.90253;

model;

sig = 1/bet;

c = sigc(+1)+f…];
a = rho
a(-1)+e_a;

end;

steady_state_model;
a=0;
c=0;

end;
steady;

estimated_params;
bet, normal_pdf, 1, 0.05;
rho, uniform_pdf, , , -0.99, 0.99;
stderr e_a, uniform_pdf, , , 0, 0.2;
end;**
estimated_params_init;
bet, 0.253;
rho, 0.90253;
end;

In this example, I declare the parameters bet and rho in the parameter block. I also give them values which are from my own calibration. Although both bet and rho are my estimation target, I have to give them values. Based on my observation, if I dont give them values, dynare can not go through the steady state. It will give me the error: the steady_state has NaN or inf. In my new code, after I give all my parameters calibrated values, dynare goes through the steady_state without trggering any error message.
**1. Here comes my first question: I have to give all my parameters reasonable values, even I want to estimate them. Correct? If I dont give them values, just provide their distribution with the prior mean, will this work? **
Since I already manually loglinearized the all my first order conditions in model block, all the steady state values should be set as 0 in steady_state block. Based on the instruction, when I put steady after steady_state_model block, dynare will use the steady state values I provide in the block as merely approximation and calculate the true steady state values through a nonlinear Newton-type solver.
2. Is my understanding correct?
In the estimated_params block, I tell dynare all parameters’ distributions. My understanding is that dynare will use the value I provide in parameter block as initial values, and follow the distribution I provide here to estimate the parameters. Since both bet and rho have initial values being different from the prior mean, I need to declare in the estimated_params_init block.
**3. Here comes my third question. When dynare estimate my parameters, will it update the values automatically? **
4. The 4th question is that I have difficulty to understand the use_calibration. Based on what you said, if I use this option, I dont need to declare bet and rho’s values in the estimated_params_init block. Should I just write the following:
estimated_params_init(use_calibration);
end;
I read the instruction about this option, but still feel really confused about how it works.

**5. The last question: Yes, you are absolutely right. When I first time to run my code, dynare does not only provide the potential fix which suggests me to add estimated_params_init with use_calibration option, but also give me the error which is B-K conditions are not satisfied: indeterminacy. I read other posts in the forums, saying that it could be due to the case where I included unnecessary equations in the model block. I carefully reviewed all my equations. All necessary equations should be correctly included. There are 18 equations for 18 endogenous variables. Then I followed the potential fix to add:
estimated_params_init(use_calibration);
bet, 0.253;
rho, 0.90253;
end;
My code is successfully ran through by dynare without any error. By now, I set mh_replic=0 to estimate parameter values. But once I change 0 to any positive integer, dyanre gives me the error message: “Matrix must be positive definite”.
I guess this is still due to this indeterminacy error. Is there any other reason could trigger this error? **

Thank you very much for your great help!!

Eric

You should always fully calibrate your model to see whether it runs. See Remark 2 (Using stoch_simul before Estimation) in Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models” sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf. Whenever you want to run command like steady, check, or stoch_simul before estimation, the parameters need to be set. If you only want to run estimation without any other commands before it, you do not need to set the parameters. Dynare will then use the prior mean by default. As you saw in your model, nothing guarantees that the prior mean is a feasible parameter set. In your case, the BK conditions were not satisfied. In contrast, if you already ran stoch_simul with a sensible parameterization and it worked, you now know that this is a problem with the parameters, not with the model setup itself. That is why we recommend calibrating the model and then trying the calibration as a starting value.

With the

estimated_params_init; bet, 0.253; rho, 0.90253; end;
block, you tell Dynare to use the given values for the specified parameters as starting values. For all others, it uses the prior mean (the default). If you use

estimated_params_init(use_calibration); bet, 0.253; rho, 0.90253; end;
Dynare will use the calibrated parameter values instead of the prior mean for all parameters not explicitly specified in the block.

Regarding updating: all estimated parameters will be updated during mode-finding/estimation.

The last problem is that for Bayesian estimation, one requires being at a mode. That does not seem to be the case as you are getting a non-positive definite Hessian. Thus, have a look at the mode_check plots. They often give you an indication of what is wrong. Most of the time, there still a mismatch between data and the model. See Pfeifer(2013): “A Guide to Specifying Observation Equations for the Estimation of DSGE Models” sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.

Hi Professor,

Thank you for your response. It is very helpful. Basically, there are 3 potential issues which might cause the error based on my understanding. It is worthy to tell you here, and get your helpful feedback.

  1. Although I already log-linearized all my FOCs. Supposing I include all necessary equations, it is still possible that some of those FOCs are not in their easiest forms. If that’s true, I need further resolve my FOCs to easiest forms. I read the instructions and posts in the forums, and both mentioned that dynare sometimes will generate error message when FOCs are not in the easiest forms;
  2. Although I calibrated my models, there are 2 parameters that I couldn’t get the initial values. Those 2 parameters are involved with friction functions. Since in steady states, those friction terms go to 0, so far I’m not able to calculate the value. Thus, I simply assign them the prior mean. I’m not sure whether this cause the error. But when I set mh_replic=0, my code actually ran, and I did get the estimated values for all my parameters. This is the place where I get confused;
  3. I might missed some components in my code for observation equation. I read the document you sent to me. It is mentioned that for output growth rate, we can use the equation: y_obs=y-y(-1)+g+g_bar, where g_bar is the constant average growth rate. I followed this equation. But when I checked the log, I noticed that the residual for this equation is non-zero. I didn’t put intival block in my code, because after log-linearizing all FOCs, all the endogenous variables should have 0 steady states. Without initval block, dynare could also assign 0 value to y_obs. That possibly caused the non-zero residual. Should I put inival block back just mention: y_obs=g_bar?

Thank you very much!
Eric

  1. I don’t understand this point. If there is a singularity caused by a missing equation, it usually does not go away for other parameter sets.
  2. To start the MCMC, you usually need a positive definite Hessian. A positive definite Hessian indicates that you are at a maximum of the objective function. If that is not the case, estimation will crash at this stage. That’s why I said you should look at the

plots.
3. Yes, in steady state

Thus, you should indicate this in the initval block (or even better, a steady_state_model-block)

Hi Professor,

With current parameter initial values, I’m able to run stoch_simul code successfully. So based on your suggestion, I guess my model setup should be correct. I also closely look at the matlab error message. It mentions that the parameters have wrong initial values. So I’m wondering if the inappropriate parameter initial values could cause non-positive hessian matrix. Thank you very much!

Eric

I keep repeating myself: what do the mode_check plots say?

Hi Professor,

Do you mind taking a look at my code? I checked the mode_check. It mentioned some parameters have negative variance. I’m not sure this is due to my initial values or my model setup. Thanks a lot!

Eric
model_code_v8.rar (9.72 KB)

Please use Dynare 4.5. It will tell you

ERROR: If the model is declared linear the second derivatives must be equal to zero. The following equations had non-zero second derivatives: * Eq # 18
Please fix this