Questions in the replication of Fernandez-Villaverde (2006)

Dear all,

I am new in Dynare and currently trying to replicate Fernandez-Villaverde (2006): “A Baseline DSGE Model”. I got some problems when running Dynare. The mod file and the associated steady state file are attached.

I have the following questions:

  1. The error message I got is:
    Attempt to reference field of non-structure array.

Error in make_ex_ (line 34)
if isempty(oo_.exo_steady_state)

Error in CN_P1_std (line 409)
make_ex_;

Error in dynare (line 180)
evalin(‘base’,fname) ;

I know this model has an example in the fold for unstable version of Dynare and it is named NK_baseline.mod. But since I am using the log-linearized model, while in the example file the model is nonlinear, I modify the steady state file slightly. I am not sure if the above error is due to the steady state file.

  1. I have a question on the steady state file. Since the model is log-linear, the endogenous variables declared in the mod file have zero steady state values except for the observable variables showing up in the measurement equation sfor estimation. Do I need to take care of these variables in the steady state file? In the current steady state file, I just put the equations to solve for the endogenous variables appearing in the original nonlinear model, which are parameters in the model block. By the way, I have declared these variables as parameters in the mod file.

  2. In the mod file, I define “# betta = 1/(beta_new/100+1);” in the model block. Is this betta updated for every draw in the estimation? Do I need to declare betta in the parameters block as well? Previously, instead of defining betta in the model block with a # sign, I put “betta = 1/(beta_new/100+1);” after declaring the parameters but before the model block. I am not sure which way is correct!

I hope anyone who knows the answers could give me some hints! I greatly appreciate it!

Best,

Bing
myexample.mod (12.6 KB)
myexample_steadystate.m (5.13 KB)

  1. You cannot start your mod-file with

It will delete all variables Dynare creates
2. You must set those variables as Dynare will try to write their values into ys in the steady state file. If you do not set them, Dynare will crash. Specifying the steady state of the nonlinear equations as parameters is correct.
3. If you define betta as a model local variables (with the #) it will be updated in each iteration. But if it is a model local variable, it is not a parameter and you must not declare it as one. For more on this, see Remark 4 (Parameter dependence and the use of model-local variables) 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.

Dear Johannes,

Thank you very much for the reply. My original error disappeared. Now two new problems concerning the steady state file arise.

  1. When I run my code using the unstable version of Dynare (2014-07-03), I got the following error:

Error using print_info (line 80)
The steady state contains NaN or Inf

Error in print_info (line 80)
error(‘The steady state contains NaN or Inf’)

Error in initial_estimation_checks (line 98)
print_info(info, DynareOptions.noprint, DynareOptions)

Error in dynare_estimation_1 (line 170)
oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,oo_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in CN_P1_std (line 508)
dynare_estimation(var_list_);

Error in dynare (line 185)
evalin(‘base’,fname) ;

When I change to the stable version (Dynare 4.4.2), I got the following error:

Error using print_info (line 72)
The steadystate file did not compute the steady state

Error in print_info (line 72)
error(‘The steadystate file did not compute the steady state’)

Error in initial_estimation_checks (line 69)
print_info(info, DynareOptions.noprint, DynareOptions)

Error in dynare_estimation_1 (line 179)
oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,M_,estim_params_,options_,bayestopt_,oo_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in CN_P1_std (line 504)
dynare_estimation(var_list_);

Error in dynare (line 180)
evalin(‘base’,fname) ;

I am not sure if this a bug or there are still problems in my code. The files are attached for your reference. By the way, I have tried stoch_simul using the same code, it worked. When I change to estimation, the error arises.

  1. I previously wrote the ending block of the steady state file following NK_baseline_steadystate in the example folder of unstable Dynare. But it did not work. Then I searched the forum and found a file you provided in an earlier post, called SOE_steadystate. I modified mine accoring to this one and it worked (at least for my stoch_simul). As I have a linear model, the same as the case in this post (External MATLAB function in Dynare). So I think it is helpful. I am just curious if there is a complete and formal guideline for writing the beginning and ending blocks of the steady state file. Or if you may provide a few example files containing different scenarios (linear versus nonlinear models), that will be very helpful and will reduce people’s potential confusion in the future. For your reference, I also attached the SOE.mod and SOE_steadystate.m.

Thank you again for your kind help!

Best,

Bing
SOE_steadystate.m (4.87 KB)
SOE.mod (7.19 KB)
myexample.xls (14.2 KB)
myexample_steadystate.m (5.96 KB)
myexample.mod (15.1 KB)

Dear Johannes,

  1. I solved the 1st problem in my previous post. The reason may be that I did not specify initial values for the estimated parameters. Now I add estimated_params_init(use_calibration) and it works. I know this block should be before the estimation command. My question is that should this block be before or after the estimated_params block? Does it matter? Also, it seems that calibrating to a set of parameters would work, but calibrating to other values may not work and the following error arises:

Error using print_info (line 80)
The steady state contains NaN or Inf

Error in print_info (line 80)
error(‘The steady state contains NaN or Inf’)

Error in initial_estimation_checks (line 98)
print_info(info, DynareOptions.noprint, DynareOptions)

Error in dynare_estimation_1 (line 170)
oo_ = initial_estimation_checks(objective_function,xparam1,dataset_,dataset_info,M_,estim_params_,options_,bayestopt_,oo_);

Error in dynare_estimation (line 89)
dynare_estimation_1(var_list,dname);

Error in CN_P1_std (line 508)
dynare_estimation(var_list_);

Error in dynare (line 185)
evalin(‘base’,fname) ;

  1. Could you please provide some comments on my 2nd question in the previous post?

  2. If I want to use the results from one mode_compute finder as the initial values for another finder, how should I do it? To change the calibrated parameter values right after the declaration of parameters? Or in the estimated_params block after the parameter name and before the density name (beta_new, gamma_pdf, 0.25, 0.1)? Or estimated_params_init block (if this is the case, the use_calibration option should be shut down, right?)? Which way is better? Do I need to do it by hand anyway?

Thank you very much!

Bing

  1. You need a functioning calibration to begin estimation with. When having a formally calibrated model, this is typically assured when using the use_calibration option. If you don’t provide explicit starting values, Dynare will take the prior mean. But people usually don’t check whether the prior mean is consistent with a steady state. In your case, it seems that it isn’t. Thus the error message. The estimated_params_init block must be after the estimated_params-block.

  2. There have been some changes over Dynare version. The steady state file provided in the example folder of the recent Dynare versions should provide the correct header and footer. You cannot use old version for the new Dynare and vice versa. Regarding linear and nonlinear: for nonlinear models, you need the steady state file to actually compute model variables. For linear models, you can use it to set the parameters. In both cases the header and footer are the same. In between, you must set all variables (usually to 0 for linear models) and the parameters you want to change, taking into account all dependencies that might arise.

  3. Use the mode_file option to load the previous results automatically.

Dear Johannes,

Thank you so much for the clarifications! I took a look at the most recent version of the unstable Dynare (2014-7-6), the header and footer of the steady state file in the example fold are still the old ones. Do you mean you are planning to update the header and footer in the future versions? or they have been updated but I did not see the correct examples?

Best,

Bing

The current steady state file is correct. If it did not work, you did not follow my advice to initialize ALL variables to 0 in the steady state file. A shortcut to do this would be

NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically for ii = 1:NumberOfEndogenousVariables varname = deblank(M_.endo_names(ii,:)); eval([varname '=0;']); end
If your linear model includes no constants, this should work. Alternatively, you can change the eval in the footer of the current file to read

eval('ys(' int2str(ii) ') = 0;']);

Thanks for your clarifications, Johannes! Your responses have always been very helpful!

Best,

Bing

If you are interested in replications this might be of interest to you: ReplicationWiki