# Questions in the replication of Fernandez-Villaverde (2006)

**URL:** <https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004>\
**Category:** Dynare help (legacy posts)\
**Created:** [4 July 2014 03:37 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004 "2014-07-04T03:37:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Econbee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@Econbee](https://forum.dynare.org/u/Econbee)\
**Post date:** [4 July 2014 03:37 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/1 "2014-07-04T03:37:08Z")

</div>

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](https://forum.dynare.org/uploads/default/original/2X/3/30b027e8cdd1ed3277ad4903795cacd3831c95e8.mod) (12.6 KB)  
[myexample\_steadystate.m](https://forum.dynare.org/uploads/default/original/2X/b/bece258cf7a79882735bad5a6e131b6c6d327935.m) (5.13 KB)

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [4 July 2014 08:54 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/2 "2014-07-04T08:54:12Z")

</div>

1. You cannot start your mod-file with

```auto

```

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](https://sites.google.com/site/pfeiferecon/Pfeifer_2013_Observation_Equations.pdf).

---

<div class="post-metadata">

**Author:** ![Econbee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@Econbee](https://forum.dynare.org/u/Econbee)\
**Post date:** [4 July 2014 15:35 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/3 "2014-07-04T15:35:01Z")

</div>

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](https://forum.dynare.org/t/external-matlab-function-in-dynare/2502/1)). 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](https://forum.dynare.org/uploads/default/original/2X/0/01b834d662f700198679b47e3bcf7fac910b0f0c.m) (4.87 KB)  
[SOE.mod](https://forum.dynare.org/uploads/default/original/2X/d/dd796631cfb40c4bc0297f7d3fcffd006664ead6.mod) (7.19 KB)  
[myexample.xls](https://forum.dynare.org/uploads/default/original/2X/5/559e7b8498342675cd05527b9283e127943c9fc4.xls) (14.2 KB)  
[myexample\_steadystate.m](https://forum.dynare.org/uploads/default/original/2X/0/042da86463deba5eb791c6655b8f2682f58e6dc4.m) (5.96 KB)  
[myexample.mod](https://forum.dynare.org/uploads/default/original/2X/9/9bf753707133d3a803f1603b7b8f9c89eb1f2d94.mod) (15.1 KB)

---

<div class="post-metadata">

**Author:** ![Econbee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@Econbee](https://forum.dynare.org/u/Econbee)\
**Post date:** [5 July 2014 07:41 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/4 "2014-07-05T07:41:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [7 July 2014 08:28 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/5 "2014-07-07T08:28:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Econbee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@Econbee](https://forum.dynare.org/u/Econbee)\
**Post date:** [7 July 2014 10:01 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/6 "2014-07-07T10:01:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://forum.dynare.org/user_avatar/forum.dynare.org/jpfeifer/32/5044_2.png) [@jpfeifer](https://forum.dynare.org/u/jpfeifer)\
**Post date:** [7 July 2014 13:37 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/7 "2014-07-07T13:37:13Z")

</div>

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;']);
`

---

<div class="post-metadata">

**Author:** ![Econbee](https://forum.dynare.org/letter_avatar_proxy/v4/letter/e/c57346/32.png) [@Econbee](https://forum.dynare.org/u/Econbee)\
**Post date:** [8 July 2014 09:34 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/8 "2014-07-08T09:34:14Z")

</div>

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

Best,

Bing

---

<div class="post-metadata">

**Author:** ![J.Hoffler](https://forum.dynare.org/letter_avatar_proxy/v4/letter/j/e495f1/32.png) [@J.Hoffler](https://forum.dynare.org/u/J.Hoffler)\
**Post date:** [2 August 2014 03:34 UTC](https://forum.dynare.org/t/questions-in-the-replication-of-fernandez-villaverde-2006/4004/9 "2014-08-02T03:34:55Z")

</div>

If you are interested in replications this might be of interest to you: [ReplicationWiki](https://forum.dynare.org/t/replicationwiki/4070/1)
