Questions in the replication of Fernandez-Villaverde (2006)

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Questions in the replication of Fernandez-Villaverde (2006)

Postby Econbee » Fri Jul 04, 2014 3:37 am

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.

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

3. 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
Attachments
myexample.mod
(12.64 KiB) Downloaded 101 times
myexample_steadystate.m
(5.13 KiB) Downloaded 113 times
Last edited by Econbee on Fri Jul 04, 2014 8:54 am, edited 1 time in total.
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Questions in the replication of Fernandez-Villaverde (20

Postby jpfeifer » Fri Jul 04, 2014 8:54 am

1. You cannot start your mod-file with
Code: Select all
clear all

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" https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Questions in the replication of Fernandez-Villaverde (20

Postby Econbee » Fri Jul 04, 2014 3:35 pm

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.

2. 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 (viewtopic.php?f=1&t=3762). 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
Attachments
SOE_steadystate.m
(4.87 KiB) Downloaded 103 times
SOE.mod
(7.19 KiB) Downloaded 96 times
myexample.xls
(14.23 KiB) Downloaded 86 times
myexample_steadystate.m
(5.96 KiB) Downloaded 91 times
myexample.mod
(15.08 KiB) Downloaded 99 times
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Questions in the replication of Fernandez-Villaverde (20

Postby Econbee » Sat Jul 05, 2014 7:41 am

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) ;

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

3. 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
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Questions in the replication of Fernandez-Villaverde (20

Postby jpfeifer » Mon Jul 07, 2014 8:28 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Questions in the replication of Fernandez-Villaverde (20

Postby Econbee » Mon Jul 07, 2014 10:01 am

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
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Questions in the replication of Fernandez-Villaverde (20

Postby jpfeifer » Mon Jul 07, 2014 1:37 pm

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

Code: Select all
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
Code: Select all
  eval(['ys(' int2str(ii) ') = 0;']);
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Questions in the replication of Fernandez-Villaverde (20

Postby Econbee » Tue Jul 08, 2014 9:34 am

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

Best,

Bing
Econbee
 
Posts: 74
Joined: Fri Nov 08, 2013 8:14 am

Re: Questions in the replication of Fernandez-Villaverde (20

Postby J.Höffler » Sat Aug 02, 2014 3:34 am

If you are interested in replications this might be of interest to you: viewtopic.php?f=2&t=5926&p=16185&hilit=replication#p16185
J.Höffler
 
Posts: 15
Joined: Fri Aug 01, 2014 3:14 pm


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 5 guests