Solving DSGE Models Using Dynare
Solving DSGE Models Using Dynare
1 Preliminaries
Look over this chapter as well as the homework so you know what to pay
specific attention to during the lecture. I will be going in depth in the
advanced topics during that time.
Watch the following Dynare Videos (you can play them in fast mode if
you prefer):
1
1.2 Introduction
1.3 Installation
(d) Save
2
2 Using DYNARE
Dynare model files should be saved as .mod files. The command to run a
model file in MATLAB (after having set the correct path) is: dynare file-
name. The output corresponds to three main structures as well as output
in the command window. These structures include M which contains var-
ious information about your model, options which contains values of the
various options used by Dynare during the computation, and oo which con-
tains the various results of the computations (this is the most interesting and
important structure of the three).
A model file contains a list of command and blocks. Each command
and each element of a block is terminated by a semicolon. Each block is
terminated by the command end; on a separate line. Double backslash //
comments out a line of code, /**/ is able to comment out several lines of
code when these symbols figure as bookends to those comments.
The main blocks of a model file are the following:
i. Preamble
v. Computation
3
Figure 1 below shows a basic template for a model file that has been set
up for a stochastic simulation.
2.2 Output
3 Advanced Topics
1 Ct 1−σ
Ut = 1−σ Ztγ
(3.1)
4
ences the future habit reference level in next periods and all future periods
utility. γ indexes the importance of habit formation in the utility function. If
γ = 0, then the standard model applies; γ = 1 implies that only consumption
relative to previous consumption matters (hence the parameter is between 0
and 1). An increase in current consumption lowers the marginal utility of
consumption in the current period and increases it in the next period (the
more you eat today, the hungrier you are tomorrow). The parameter indexes
the persistence or memory in the habit formation reference level. If ρ = 0,
then only last periods consumption matters, for 0 ≤ ρ ≤ 1, the larger it is
the further back in time is the reference level determined.
Using (??) and (??) we can derive the overall utility function as a function
of present and discounted future utility. We get the following expression of
the derivative of total utility with respect to consumption in period t.
∞
X β i ρi−1 Ut+i
∂U 1−σ
= Ut − γ(1 − σ)(1 − ρ) (3.3)
∂Ct Ct i=1
Zt+i
5
period.
∞
X Ct+i
Yt = C t + Qi (3.5)
i=1 j=1 (1 + rt+j )
hence todays wealth equals the discounted value of all future consumption.
As above this can also represented as Yt = Ct + Dt , where Dt can be
represented in a recursive form.
Presented in Class.
A good source for a Bayesian Estimation Tutorial is Dynare 3 by Bryan
Perry on YouTube (despite it being an hour long, it is very instructive).
http://www.youtube.com/watch?v=RtGW-ZogMqg.
Also, look through last year’s notes on “Bayesian Inference and Com-
putation”, which can be downloaded from the 2013 BYUMCL Bootcamp
repository where you got these notes.
6
Exercises
Homework 1
Using the methods discussed in section 3.1.1, write a recursive form of the
infinite sum, St .
Derive the Euler equation.
Homework 2
Using the methods discussed in section 3.1.2, write a recursive form of the
infinite sum, Dt .
Homework 3
Using the same setup as Problem 14 from the Week 3 DSGE homework,
let’s tweak the utility function a little bit by including a preference shock to
consumption Lester, Pries, and Sims (2013).
ct1−γ (1 − `t )1−γ
u(ct , `t ) = νt +a
1−γ 1−γ
7
Rewrite the two characterizing equations as they should now appear with
this preference shock to consumption.
Write the Dynare code to perform a stochastic simulation of this model for
2100 periods, use the second-order Taylor-series approximation, and generate
IRFs of all the variables to each shock for 100 periods. Provide the output,
graphs and code as part of your homework submission. Comment on the IRF
graphs; intuitively describe the responses of output and consumption each of
the shocks.
Homework 4
Modify the Dynare code used above, eliminating the stochastic simulation,
and gearing it toward a Bayesian estimation of the following parameters:
γ, a, β, ρz , ρν , σ z and σν . You will need to include new variables in your
model that are more suited toward Bayesian estimation:
dc = ct − ct−1
dy = yt − yt−1
These will be the variables you will be observing in the code. I will provide
the data file for you. Start your estimation according to the table below.1
Do this estimation for 20000 replications, 3 Metropolis Hastings blocks,
drop the first 15% of the replications (burn in of 15%), start mh jscale at 0.5
and ADJUST the mh jscale as you monitor the acceptance rate so that you
get an acceptance rate as close to 25% as possible once the replications within
1
Prior distributions inspired by the in class example and Del Negro, Schorfheide, Smets
and Wouters, 2005
8
Table 1: Bayesian Estimation Setup
the block seem to stabilize around a particular rate. Report the posterior
mode for each of the parameters. This is the most important information.
Also report the posterior mean and confidence intervals for each parameter
from the provided output. Provide the graphs from the output.
If you were to redo the Bayesian estimation, for which parameters would
you re-specify the prior distribution or how would you modify the replication
procedure? Use the graphs as support for your answer. If you feel the priors
were reasonably specified, provide support (again from the graphs) toward
the legitimacy of the priors specified.
9
References
Adjemian, S., H. Bastani, M. Juillard, F. Karame, F. Mihoubi,
G. Perendia, J. Pfeifer, M. Ratto, and S. Villemot (2011):
“Dynare: Reference Manual, Version 4,” Dynare Working Papers, 1,
CEPREMAP.
Carlin, B. P., and T. a. Louis (2009): Bayesian Methods for Data Anal-
ysis, 3rd Ed. Chapman and Hall/CRC.
10
Figure 1: Sample Dynare Model File
11