This action might not be possible to undo. Are you sure you want to continue?
User Guide
Tommaso Mancini Griffoli, 20072008
An introduction to
the solution & estimation of DSGE models
Dynare v4  User Guide
Public beta version
Tommaso Mancini Griﬀoli
tommaso.mancini@stanfordalumni.org
This draft: June 2010
iii
Copyright c 20072010 Tommaso Mancini Griﬀoli
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or any
later version published by the Free Software Foundation; with no Invariant
Sections, no FrontCover Texts, and no BackCover Texts.
A copy of the license can be found at: http://www.gnu.org/licenses/
fdl.txt
Contents
Contents iv
List of Figures vii
1 Introduction 1
1.1 About this Guide  approach and structure . . . . . . . . . . . 1
1.2 What is Dynare? . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Additional sources of help . . . . . . . . . . . . . . . . . . . . . 4
1.4 Nomenclature . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.5 v4, what’s new and backward compatibility . . . . . . . . . . . 5
2 Installing Dynare 7
2.1 Dynare versions . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 System requirements . . . . . . . . . . . . . . . . . . . . . . . . 7
2.3 Installing Dynare . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 MATLAB particularities . . . . . . . . . . . . . . . . . . . . . . 8
3 Solving DSGE models  basics 9
3.1 A fundamental distinction . . . . . . . . . . . . . . . . . . . . . 9
3.1.1 NOTE! Deterministic vs stochastic models . . . . . . . . 10
3.2 Introducing an example . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Dynare .mod ﬁle structure . . . . . . . . . . . . . . . . . . . . . 15
3.4 Filling out the preamble . . . . . . . . . . . . . . . . . . . . . . 15
3.4.1 The deterministic case . . . . . . . . . . . . . . . . . . . 16
3.4.2 The stochastic case . . . . . . . . . . . . . . . . . . . . . 16
3.4.3 Comments on your ﬁrst lines of Dynare code . . . . . . 17
3.5 Specifying the model . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5.1 Model in Dynare notation . . . . . . . . . . . . . . . . . 18
3.5.2 General conventions . . . . . . . . . . . . . . . . . . . . 19
3.5.3 Notational conventions . . . . . . . . . . . . . . . . . . . 19
3.5.4 Timing conventions . . . . . . . . . . . . . . . . . . . . 19
3.5.5 Conventions specifying nonpredetermined variables . . 20
3.5.6 Linear and loglinearized models . . . . . . . . . . . . . 20
3.6 Specifying steady states and/or initial values . . . . . . . . . . 21
iv
CONTENTS v
3.6.1 Stochastic models and steady states . . . . . . . . . . . 21
3.6.2 Deterministic models and initial values . . . . . . . . . . 23
3.6.3 Finding a steady state . . . . . . . . . . . . . . . . . . . 23
3.6.4 Checking system stability . . . . . . . . . . . . . . . . . 24
3.7 Adding shocks . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.7.1 Deterministic models  temporary shocks . . . . . . . . 25
3.7.2 Deterministic models  permanent shocks . . . . . . . . 25
3.7.3 Stochastic models . . . . . . . . . . . . . . . . . . . . . 27
3.8 Selecting a computation . . . . . . . . . . . . . . . . . . . . . . 27
3.8.1 For deterministic models . . . . . . . . . . . . . . . . . . 28
3.8.2 For stochastic models . . . . . . . . . . . . . . . . . . . 28
3.9 The complete .mod ﬁle . . . . . . . . . . . . . . . . . . . . . . . 31
3.9.1 The stochastic model . . . . . . . . . . . . . . . . . . . . 31
3.9.2 The deterministic model (case of temporary shock) . . . 32
3.10 File execution and results . . . . . . . . . . . . . . . . . . . . . 33
3.10.1 Results  stochastic models . . . . . . . . . . . . . . . . 33
3.10.2 Results  deterministic models . . . . . . . . . . . . . . 34
4 Solving DSGE models  advanced topics 37
4.1 Dynare features and functionality . . . . . . . . . . . . . . . . . 37
4.1.1 Other examples . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.2 Alternative, complete example . . . . . . . . . . . . . . 38
4.1.3 Finding, saving and viewing your output . . . . . . . . . 41
4.1.4 Referring to external ﬁles . . . . . . . . . . . . . . . . . 42
4.1.5 Inﬁnite eigenvalues . . . . . . . . . . . . . . . . . . . . . 43
4.2 Files created by Dynare . . . . . . . . . . . . . . . . . . . . . . 43
4.3 Modeling tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3.1 Stationarizing your model . . . . . . . . . . . . . . . . . 44
4.3.2 Expectations taken in the past . . . . . . . . . . . . . . 44
4.3.3 Inﬁnite sums . . . . . . . . . . . . . . . . . . . . . . . . 44
4.3.4 Inﬁnite sums with changing timing of expectations . . . 46
5 Estimating DSGE models  basics 47
5.1 Introducing an example . . . . . . . . . . . . . . . . . . . . . . 47
5.2 Declaring variables and parameters . . . . . . . . . . . . . . . . 48
5.3 Declaring the model . . . . . . . . . . . . . . . . . . . . . . . . 48
5.4 Declaring observable variables . . . . . . . . . . . . . . . . . . . 49
5.5 Specifying the steady state . . . . . . . . . . . . . . . . . . . . 49
5.6 Declaring priors . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
5.7 Launching the estimation . . . . . . . . . . . . . . . . . . . . . 52
5.8 The complete .mod ﬁle . . . . . . . . . . . . . . . . . . . . . . . 55
5.9 Interpreting output . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.9.1 Tabular results . . . . . . . . . . . . . . . . . . . . . . . 57
5.9.2 Graphical results . . . . . . . . . . . . . . . . . . . . . . 57
6 Estimating DSGE models  advanced topics 61
6.1 Alternative and nonstationary example . . . . . . . . . . . . . 61
6.1.1 Introducing the example . . . . . . . . . . . . . . . . . . 61
6.1.2 Declaring variables and parameters . . . . . . . . . . . . 66
6.1.3 The origin of nonstationarity . . . . . . . . . . . . . . . 66
6.1.4 Stationarizing variables . . . . . . . . . . . . . . . . . . 67
6.1.5 Linking stationary variables to the data . . . . . . . . . 68
6.1.6 The resulting model block of the .mod ﬁle . . . . . . . . 68
6.1.7 Declaring observable variables . . . . . . . . . . . . . . . 69
6.1.8 Declaring trends in observable variables . . . . . . . . . 69
6.1.9 Declaring unit roots in observable variables . . . . . . . 70
6.1.10 Specifying the steady state . . . . . . . . . . . . . . . . 71
6.1.11 Declaring priors . . . . . . . . . . . . . . . . . . . . . . 71
6.1.12 Launching the estimation . . . . . . . . . . . . . . . . . 71
6.1.13 The complete .mod ﬁle . . . . . . . . . . . . . . . . . . . 72
6.1.14 Summing it up . . . . . . . . . . . . . . . . . . . . . . . 74
6.2 Comparing models based on their posterior distributions . . . . 74
6.3 Where is your output stored? . . . . . . . . . . . . . . . . . . . 75
7 Solving DSGE models  Behind the scenes of Dynare 77
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
7.2 What is the advantage of a second order approximation? . . . . 77
7.3 How does dynare solve stochastic DSGE models? . . . . . . . . 78
8 Estimating DSGE models  Behind the scenes of Dynare 81
8.1 Advantages of Bayesian estimation . . . . . . . . . . . . . . . . 81
8.2 The basic mechanics of Bayesian estimation . . . . . . . . . . . 82
8.2.1 Bayesian estimation: somewhere between calibration and
maximum likelihood estimation  an example . . . . . . 84
8.3 DSGE models and Bayesian estimation . . . . . . . . . . . . . . 85
8.3.1 Rewriting the solution to the DSGE model . . . . . . . 85
8.3.2 Estimating the likelihood function of the DSGE model . 86
8.3.3 Finding the mode of the posterior distribution . . . . . 87
8.3.4 Estimating the posterior distribution . . . . . . . . . . . 87
8.4 Comparing models using posterior distributions . . . . . . . . . 90
9 Optimal policy under commitment 93
10 Troubleshooting 95
vi
List of Figures vii
Bibliography 97
List of Figures
1.1 Dynare, a bird’s eyeview . . . . . . . . . . . . . . . . . . . . . . . . 3
3.1 Structure of the .mod ﬁle . . . . . . . . . . . . . . . . . . . . . . . 16
6.1 CIA model illustration . . . . . . . . . . . . . . . . . . . . . . . . . 62
6.2 Steps of model estimation . . . . . . . . . . . . . . . . . . . . . . . 74
8.1 Illustration of the MetropolisHastings algorithm . . . . . . . . . . 89
Work in Progress!
This is the second version of the Dynare User Guide which is still work in
progress! This means two things. First, please read this with a critical eye
and send me comments! Are some areas unclear? Is anything plain wrong?
Are some sections too wordy, are there enough examples, are these clear? On
the contrary, are there certain parts that just click particularly well? How can
others be improved? I’m very interested to get your feedback.
The second thing that a work in progress manuscript comes with is a few
internal notes. These are mostly placeholders for future work, notes to myself
or others of the Dynare development team, or at times notes to you  our read
ers  to highlight a feature not yet fully stable. Any such notes are marked
with two stars (**).
Thanks very much for your patience and good ideas. Please write either
direclty to myself: tommaso.mancini@stanfordalumni.org, or preferably on
the Dynare Documentation Forum available in the Dynare Forums.
ix
Contacts and Credits
Dynare was originally developed by Michel Juillard in Paris, France. Cur
rently, the development team of Dynare is composed of
• St´ephane Adjemian (stephane.adjemian“AT”ens.fr)
• Houtan Bastani (houtan.bastani“AT”ens.fr)
• Michel Juillard (michel.juillard“AT”mjui.fr)
• Ferhat Mihoubi (ferhat.mihoubi“AT”univevry.fr)
• George Perendia (george“AT”perendia.orangehome.co.uk)
• Marco Ratto (marco.ratto“AT”jrc.ec.europa.eu)
• S´ebastien Villemot (sebastien.villemot“AT”ens.fr)
Several parts of Dynare use or have strongly beneﬁted from publicly avail
able programs by G. Anderson, F. Collard, L. Ingber, O. Kamenik, P. Klein,
S. Sakata, F. Schorfheide, C. Sims, P. Soederlind and R. Wouters.
Finally, the development of Dynare could not have come such a long ways
withough an active community of users who continually pose questions, re
port bugs and suggest new features. The help of this community is gratefully
acknowledged.
The email addresses above are provided in case you wish to contact any
one of the authors of Dynare directly. We nonetheless encourage you to ﬁrst
use the Dynare forums to ask your questions so that other users can beneﬁt
from them as well; remember, almost no question is speciﬁc enough to interest
just one person, and yours is not the exception!
xi
Chapter 1
Introduction
Welcome to Dynare!
1.1 About this Guide  approach and structure
This User Guide aims to help you master Dynare’s main functionalities,
from getting started to implementing advanced features. To do so, this Guide
is structured around examples and oﬀers practical advice. To root this un
derstanding more deeply, though, this Guide also gives some background on
Dynare’s algorithms, methodologies and underlying theory. Thus, a secondary
function of this Guide is to serve as a basic primer on DSGE model solving
and Bayesian estimation.
This Guide will focus on the most common or useful features of the pro
gram, thus emphasizing depth over breadth. The idea is to get you to
use 90% of the program well and then tell you where else to look if you’re
interested in ﬁne tuning or advanced customization.
This Guide is written mainly for an advanced economist  like a pro
fessor, graduate student or central banker  needing a powerful and ﬂexible
program to support and facilitate his or her research activities in a variety
of ﬁelds. The sophisticated computer programmer, on the one hand, or the
specialist of computational economics, on the other, may not ﬁnd this Guide
suﬃciently detailed.
We recognize that the “advanced economist” may be either a beginning
or intermediate user of Dynare. This Guide is written to accommodate both.
If you’re new to Dynare, we recommend starting with chapters 3 and 5,
which introduce the program’s basic features to solve (including running im
pulse response functions) and estimate DSGE models, respectively. To do
1
2 CHAPTER 1. INTRODUCTION
so, these chapters lead you through a complete handson example, which we
recommend following from A to Z, in order to “learn by doing”. Once you
have read these two chapters, you will know the crux of Dynare’s functionality
and (hopefully!) feel comfortable using Dynare for your own work. At that
point, though, you will probably ﬁnd yourself coming back to the User Guide
to skim over some of the content in the advanced chapters to iron out details
and potential complications you may run into.
If you’re instead an intermediate user of Dynare, you will most likely
ﬁnd the advanced chapters, 4 and 6, more appropriate. These chapters cover
more advanced features of Dynare and more complicated usage scenarios. The
presumption is that you would skip around these chapters to focus on the top
ics most applicable to your needs and curiosity. Examples are therefore more
concise and speciﬁc to each feature; these chapters read a bit more like a ref
erence manual.
We also recognize that you probably have had repeated if not active ex
posure to programming and are likely to have a strong economic background.
Thus, a black box solution to your needs is inadequate. To hopefully address
this issue, the User Guide goes into some depth in covering the theoreti
cal underpinnings and methodologies that Dynare follows to solve
and estimate DSGE models. These are available in the “behind the scenes of
Dynare” chapters 7 and 8. These chapters can also serve as a basic primer
if you are new to the practice of DSGE model solving and Bayesian estimation.
Finally, besides breaking up content into short chapters, we’ve introduced
two diﬀerent markers throughout the Guide to help streamline your reading.
• TIP! introduces advice to help you work more eﬃciently with Dynare
or solve common problems.
• NOTE! is used to draw your attention to particularly important infor
mation you should keep in mind when using Dynare.
1.2 What is Dynare?
Before we dive into the thick of the “trees”, let’s have a look at the “forest”
from the top . . . just what is Dynare?
Dynare is a powerful and highly customizable engine, with an
intuitive frontend interface, to solve, simulate and estimate DSGE
models.
1.2. WHAT IS DYNARE? 3
Figure 1.1: The .mod ﬁle being read by the Dynare preprocessor, which then
calls the relevant Matlab routines to carry out the desired operations and
display the results.
In slightly less ﬂowery words, it is a preprocessor and a collection of Mat
lab routines that has the great advantages of reading DSGE model equations
written almost as in an academic paper. This not only facilitates the inputting
of a model, but also enables you to easily share your code as it is straightfor
ward to read by anyone.
Figure 1.2 gives you an overview of the way Dynare works. Basically, the
model and its related attributes, like a shock structure for instance, is writ
ten equation by equation in an editor of your choice. The resulting ﬁle will
be called the .mod ﬁle. That ﬁle is then called from Matlab. This initiates
the Dynare preprocessor which translates the .mod ﬁle into a suitable input
for the Matlab routines (more precisely, it creates intermediary Matlab or C
ﬁles which are then used by Matlab code) used to either solve or estimate the
model. Finally, results are presented in Matlab. Some more details on the
internal ﬁles generated by Dynare is given in section 4.2 in chapter 4.
Each of these steps will become clear as you read through the User Guide,
but for now it may be helpful to summarize what Dynare is able to do:
4 CHAPTER 1. INTRODUCTION
• compute the steady state of a model
• compute the solution of deterministic models
• compute the ﬁrst and second order approximation to solutions of stochas
tic models
• estimate parameters of DSGE models using either a maximum likelihood
or a Bayesian approach
• compute optimal policies in linearquadratic models
1.3 Additional sources of help
While this User Guide tries to be as complete and thorough as possible, you
will certainly want to browse other material for help, as you learn about new
features, struggle with adapting examples to your own work, and yearn to ask
that one question whose answer seems to exist nowhere. At your disposal,
you have the following additional sources of help:
• Reference Manual: this manual covers all Dynare commands, giving
a clear deﬁnition and explanation of usage for each. The User Guide
will often introduce you to a command in a rather loose manner (mainly
through examples); so reading corresponding command descriptions in
the Reference Manual is a good idea to cover all relevant details.
• Oﬃcial online examples: the Dynare website includes other examples
 usually well documented  of .mod ﬁles covering models and method
ologies introduced in recent papers.
• Dynare forums: this lively online discussion forum allows you to ask
your questions openly and read threads from others who might have run
into similar diﬃculties.
• Frequently Asked Questions (FAQ): this section of the Dynare site
emphasizes a few of the most popular questions in the forums.
• DSGE.net: this website, run my members of the Dynare team, is a
resource for all scholars working in the ﬁeld of DSGE modeling. Besides
allowing you to stay up to date with the most recent papers and possi
bly make new contacts, it conveniently lists conferences, workshops and
seminars that may be of interest.
1.4. NOMENCLATURE 5
1.4 Nomenclature
To end this introduction and avoid confusion in what follows, it is worthwhile
to agree on a few deﬁnitions of terms. Many of these are shared with the
Reference Manual.
• Integer indicates an integer number.
• Double indicates a double precision number. The following syntaxes
are valid: 1.1e3, 1.1E3, 1.1E3, 1.1d3, 1.1D3
• Expression indicates a mathematical expression valid in the underlying
language (e.g. Matlab).
• Variable name indicates a variable name. NOTE! These must start
with an alphabetical character and can only contain other alphabetical
characters and digits, as well as underscores ( ). All other characters,
including accents, and spaces, are forbidden.
• Parameter name indicates a parameter name which must follow the
same naming conventions as above.
• Filename indicates a ﬁle name valid in your operating system. Note
that Matlab requires that names of ﬁles or functions start with alpha
betical characters; this concerns your Dynare .mod ﬁles.
• Command is an instruction to Dynare or other program when speciﬁed.
• Options or optional arguments for a command are listed in square
brackets [ ] unless otherwise noted. If, for instance, the option must
be speciﬁed in parenthesis in Dynare, it will show up in the Guide as
[(option)].
• Typewritten text indicates text as it should appear in Dynare code.
1.5 v4, what’s new and backward compatibility
The current version of Dynare  for which this guide is written  is version
4. With respect to version 3, this new version introduces several important
features, as well as improvements, optimizations of routines and bug ﬁxes.
The major new features are the following:
• Analytical derivatives are now used everywhere (for instance, in the
Newton algorithm for deterministic models and in the linearizations nec
essary to solve stochastic models). This increases computational speed
signiﬁcantly. The drawback is that Dynare can now handle only a lim
ited set of functions, although in nearly all economic applications this
should not be a constraint.
6 CHAPTER 1. INTRODUCTION
• Variables and parameters are now kept in the order in which they are
declared whenever displayed and when used internally by Dynare. Recall
that in version 3, variables and parameters where at times in their order
of declaration and at times in alphabetical order. NOTE! This may
cause some problems of backward compatibility if you wrote programs
to run oﬀ Dynare v3 output.
• The names of many internal variables and the organization of output
variables has changed. These are enumerated in details in the relevant
chapters. The names of the ﬁles internally generated by Dynare have
also changed. (** more on this when explaining internal ﬁle structure 
TBD)
• The syntax for the external steady state ﬁle has changed. This is cov
ered in more details in chapter 3, in section 3.6.3. NOTE! You will
unfortunately have to slightly amend any old steady state ﬁles you may
have written.
• Speed. Several largescale improvements have been implemented to
speed up Dynare. This should be most noticeable when solving de
terministic models, but also apparent in other functionality.
Chapter 2
Installing Dynare
2.1 Dynare versions
The current version of Dynare (4.1) runs on both MATLAB and GNU
Octave.
There used to be versions of Dynare for Scilab and Gauss. Development
of the Scilab version stopped after Dynare version 3.02 and that for Gauss
after Dynare version 1.2.
This User Guide will exclusively focus on Dynare version 4.0 and
later.
You may also be interested by another program, Dynare++, which is
a standalone C++ program specialized in computing korder approximations
of dynamic stochastic general equilibrium models. Note that Dynare++ is
distributed along with Dynare since version 4.1. See the Dynare++ webpage
for more information.
2.2 System requirements
Dynare can run on Microsoft Windows, as well as Unixlike operating systems,
in particular GNU/Linux and Mac OS X. If you have questions about the
support of a particular platform, please ask your question on Dynare forums.
To run Dynare, it is recommended to allocate at least 256MB of RAM
to the platform running Dynare, although 512MB is preferred. Depending on
the type of computations required, like the very processor intensive Metropolis
Hastings algorithm, you may need up to 1GB of RAM to obtain acceptable
computational times.
2.3 Installing Dynare
Please refer to the section entitled “Installation and conﬁguration” in the
Dynare reference manual.
7
8 CHAPTER 2. INSTALLING DYNARE
2.4 MATLAB particularities
A question often comes up: what special MATLAB toolboxes are necessary
to run Dynare? In fact, no additional toolbox is necessary for running most of
Dynare, except maybe for optimal simple rules (see chapter 9), but even then
remedies exist (see the Dynare forums for discussions on this, or to ask your
particular question). But if you do have the ‘optimization toolbox’ installed,
you will have additional options for solving for the steady state (solve algo
option) and for searching for the posterior mode (mode compute option), both
of which are deﬁned later.
Chapter 3
Solving DSGE models  basics
This chapter covers everything that leads to, and stems from, the solution
of DSGE models; a vast terrain. That is to say that the term “solution”
in the title of the chapter is used rather broadly. You may be interested in
simply ﬁnding the solution functions to a set of ﬁrst order conditions stemming
from your model, but you may also want to go a bit further. Typically, you
may be interested in how this system behaves in response to shocks, whether
temporary or permanent. Likewise, you may want to explore how the system
comes back to its steady state or moves to a new one. This chapter covers all
these topics. But instead of skipping to the topic closest to your needs, we
recommend that you read this chapter chronologically, to learn basic Dynare
commands and the process of writing a proper .mod ﬁle  this will serve as a
base to carry out any of the above computations.
3.1 A fundamental distinction
Before speaking of Dynare, it is important to recognize a distinction in model
types. This distinction will appear throughout the chapter; in fact, it is so
fundamental, that we considered writing separate chapters altogether. But
the amount of common material  Dynare commands and syntax  is notable
and writing two chapters would have been overly repetitive. Enough suspense;
here is the important question: is your model stochastic or determinis
tic?
The distinction hinges on whether future shocks are known. In de
terministic models, the occurrence of all future shocks is known exactly at
the time of computing the model’s solution. In stochastic models, instead,
only the distribution of future shocks is known. Let’s consider a shock to a
model’s innovation only in period 1. In a deterministic context, agents will
take their decisions knowing that future values of the innovations will be zero
in all periods to come. In a stochastic context, agents will take their decisions
9
10 CHAPTER 3. SOLVING DSGE MODELS  BASICS
knowing that the future value of innovations are random but will have zero
mean. This isn’t the same thing because of Jensen’s inequality. Of course, if
you consider only a ﬁrst order linear approximation of the stochastic model,
or a linear model, the two cases become practically the same, due to certainty
equivalence. A second order approximation will instead lead to very diﬀerent
results, as the variance of shocks will matter.
The solution method for each of these model types diﬀers signiﬁcantly. In
deterministic models, a highly accurate solution can be found by numerical
methods. The solution is nothing more than a series of numbers that match
a given set of equations. Intuitively, if an agent has perfect foresight, she can
specify today  at the time of making her decision  what each of her precise
actions will be in the future. In a stochastic environment, instead, the best
the agent can do is specify a decision, policy or feedback rule for the future:
what will her optimal actions be contingent on each possible realization of
shocks. In this case, we therefore search for a function satisfying the model’s
ﬁrst order conditions. To complicate things, this function may be nonlinear
and thus needs to be approximated. In control theory, solutions to determin
istic models are usually called “closed loop” solutions, and those to stochastic
models are referred to as “open loop”.
Because this distinction will resurface again and again throughout the
chapter, but also because it has been a source of signiﬁcant confusion in the
past, the following gives some additional details.
3.1.1 NOTE! Deterministic vs stochastic models
Deterministic models have the following characteristics:
1. As the DSGE (read, “stochastic”, i.e. not deterministic!) literature
has gained attention in economics, deterministic models have become
somewhat rare. Examples include OLG models without aggregate un
certainty.
2. These models are usually introduced to study the impact of a change in
regime, as in the introduction of a new tax, for instance.
3. Models assume full information, perfect foresight and no uncertainty
around shocks.
4. Shocks can hit the economy today or at any time in the future, in which
case they would be expected with perfect foresight. They can also last
one or several periods.
5. Most often, though, models introduce a positive shock today and zero
shocks thereafter (with certainty).
3.2. INTRODUCING AN EXAMPLE 11
6. The solution does not require linearization, in fact, it doesn’t even really
need a steady state. Instead, it involves numerical simulation to ﬁnd the
exact paths of endogenous variables that meet the model’s ﬁrst order
conditions and shock structure.
7. This solution method can therefore be useful when the economy is far
away from steady state (when linearization oﬀers a poor approximation).
Stochastic models, instead, have the following characteristics:
1. These types of models tend to be more popular in the literature. Exam
ples include most RBC models, or new keynesian monetary models.
2. In these models, shocks hit today (with a surprise), but thereafter their
expected value is zero. Expected future shocks, or permanent changes
in the exogenous variables cannot be handled due to the use of Taylor
approximations around a steady state.
3. Note that when these models are linearized to the ﬁrst order, agents
behave as if future shocks where equal to zero (since their expectation is
null), which is the certainty equivalence property. This is an often
overlooked point in the literature which misleads readers in supposing
their models may be deterministic.
3.2 Introducing an example
The goal of this ﬁrst section is to introduce a simple example. Future sections
will aim to code this example into Dynare and analyze its salient features
under the inﬂuence of shocks  both in a stochastic and a deterministic envi
ronment. Note that as a general rule, the examples in the basic chapters, 3
and 5, are kept as bare as possible, with just enough features to help illustrate
Dynare commands and functionalities. More complex examples are instead
presented in the advanced chapters.
The model introduced here is a basic RBC model with monopolistic com
petition, used widely in the literature. Its particular notation adopted below
is drawn mostly from notes available on Jesus FernandezVillaverde’s very
instructive website; this is a good place to look for additional information
on any of the following model setup and discussion. Note throughout this
model description that the use of expectation signs is really only relevant
in a stochastic setting, as per the earlier discussion. We will nonetheless
illustrate both the stochastic and the deterministic settings on the basis of
this example. Thus, when thinking of the latter, you’ll have to use a bit of
imagination (on top of that needed to think you have perfect foresight!) to
12 CHAPTER 3. SOLVING DSGE MODELS  BASICS
ignore the expectation signs.
Households maximize utility over consumption, c
t
and leisure, 1−l
t
, where
l
t
is labor input, according to the following utility function
E
t
∞
t=0
β [log c
t
+ψ log(1 −l
t
)]
and subject to the following budget constraint
c
t
+k
t+1
= w
t
l
t
+r
t
k
t
+ (1 −δ)k
t
, ∀t > 0
where k
t
is capital stock, w
t
real wages, r
t
real interest rates or cost of capital
and δ the depreciation rate.
The above equation can be seen as an accounting identity, with total ex
penditures on the left hand side and revenues  including the liquidation value
of the capital stock  on the right hand side. Alternatively, with a little more
imagination, the equation can also be interpreted as a capital accumulation
equation after bringing c
t
to the right hand side and noticing that w
t
l
t
+r
t
k
t
,
total payments to factors, equals y
t
, or aggregate output, by the zero proﬁt
condition. As a consequence, if we deﬁne investment as i
t
= y
t
−c
t
, we obtain
the intuitive result that i
t
= k
t+1
− (1 − δ)k
t
, or that investment replenishes
the capital stock thereby countering the eﬀects of depreciation. In any given
period, the consumer therefore faces a tradeoﬀ between consuming and in
vesting in order to increase the capital stock and consuming more in following
periods (as we will see later, production depends on capital).
Maximization of the household problem with respect to consumption,
leisure and capital stock, yields the Euler equation in consumption, capturing
the intertemporal tradeoﬀ mentioned above, and the labor supply equation
linking labor positively to wages and negatively to consumption (the wealth
ier, the more leisure due to the decreasing marginal utility of consumption).
These equation are
1
c
t
= βE
t
_
1
c
t+1
(1 +r
t+1
−δ)
_
and
ψ
c
t
1 −l
t
= w
t
The ﬁrm side of the problem is slightly more involved, due to monopolistic
competition, but is presented below in the simplest possible terms, with a
little handwaiving involved, as the derivations are relatively standard.
3.2. INTRODUCING AN EXAMPLE 13
There are two ways to introduce monopolistic competition. We can ei
ther assume that ﬁrms sell diﬀerentiated varieties of a good to consumers who
aggregate these according to a CES index. Or we can postulate that there
is a continuum of intermediate producers with market power who each sell
a diﬀerent variety to a competitive ﬁnal goods producer whose production
function is a CES aggregate of intermediate varieties.
If we follow the second route, the ﬁnal goods producer chooses his or her
optimal demand for each variety, yielding the DixitStiglitz downward sloping
demand curve. Intermediate producers, instead, face a two pronged decision:
how much labor and capital to employ given these factors’ perfectly competi
tive prices and how to price the variety they produce.
Production of intermediate goods follows a CRS production function de
ﬁned as
y
it
= k
α
it
(e
z
t
l
it
)
1−α
where the i subscript stands for ﬁrm i of a continuum of ﬁrms between zero
and one and where α is the capital elasticity in the production function, with
0 < α < 1. Also, z
t
captures technology which evolves according to
z
t
= ρz
t−1
+e
t
where ρ is a parameter capturing the persistence of technological progress and
e
t
∼ N(0, σ).
The solution to the sourcing problem yields an optimal capital to labor
ratio, or relationship between payments to factors:
k
it
r
t
=
α
1 −α
w
t
l
it
The solution to the pricing problem, instead, yields the wellknown con
stant markup pricing condition of monopolistic competition:
p
it
=
−1
mc
t
p
t
where p
it
is ﬁrm i’s speciﬁc price, mc
t
is real marginal cost and p
t
is the aggre
gate CES price or average price. An additional step simpliﬁes this expression:
symmetric ﬁrms implies that all ﬁrms charge the same price and thus p
it
= p
t
;
we therefore have: mc
t
= ( −1)/
But what are marginal costs equal to? To ﬁnd the answer, we combine the
optimal capital to labor ratio into the production function and take advantage
of its CRS property to solve for the amount of labor or capital required to
produce one unit of output. The real cost of using this amount of any one
14 CHAPTER 3. SOLVING DSGE MODELS  BASICS
factor is given by w
t
l
it
+ r
t
k
it
where we substitute out the payments to the
other factor using again the optimal capital to labor ratio. When solving for
labor, for instance, we obtain
mc
t
=
_
1
1 −α
_
1−α
_
1
α
_
α
1
A
t
w
1−α
t
r
α
t
which does not depend on i; it is thus the same for all ﬁrms.
Interestingly, the above can be worked out, by using the optimal capital
to labor ratio, to yield w
t
[(1 − α)y
it
/l
it
]
−1
, or w
t
∂l
it
∂y
it
, which is the deﬁnition
of marginal cost: the cost in terms of labor input of producing an additional
unit of output. This should not be a surprise since the optimal capital to
labor ratio follows from the maximization of the production function (minus
real costs) with respect to its factors.
Combining this result for marginal cost, as well as its counterpart in terms
of capital, with the optimal pricing condition yields the ﬁnal two important
equations of our model
w
t
= (1 −α)
y
it
l
it
( −1)
and
r
t
= α
y
it
k
it
( −1)
To end, we aggregate the production of each individual ﬁrm to ﬁnd an
aggregate production function. On the supply side, we factor out the capital
to labor ratio, k
t
/l
t
, which is the same for all ﬁrms and thus does not depend
on i. On the other side, we have the DixitStiglitz demand for each variety. By
equating the two and integrating both side, and noting that price dispersion
is null  or that, as hinted earlier, p
it
= p
t
 we obtain aggregate production
y
t
= A
t
k
α
t
l
1−α
t
which can be shown is equal to the aggregate amount of varieties bought by
the ﬁnal good producer (according to a CES aggregation index) and, in turn,
equal to the aggregate output of ﬁnal good, itself equal to household con
sumption. Note, to close, that because the ratio of output to each factor is
the same for each intermediate ﬁrm and that ﬁrm speciﬁc as well as aggre
gate production is CRS, we can rewrite the above two equations for w
t
and r
t
without the i subscripts on the right hand side.
This ends the exposition of the example. Now, let’s roll up our sleeves and
see how we can input the model into Dynare and actually test how the model
will respond to shocks.
3.3. DYNARE .MOD FILE STRUCTURE 15
3.3 Dynare .mod ﬁle structure
Input into Dynare involves the .mod ﬁle, as mentioned loosely in the intro
duction of this Guide. The .mod ﬁle can be written in any editor, external or
internal to Matlab. It will then be read by Matlab by ﬁrst navigating within
Matlab to the directory where the .mod ﬁle is stored and then by typing in
the Matlab command line Dynare filename.mod; (although actually typing
the extension .mod is not necessary). But before we get into executing a .mod
ﬁle, let’s start by writing one!
It is convenient to think of the .mod ﬁle as containing four distinct blocks,
illustrated in ﬁgure 3.3:
• preamble: lists variables and parameters
• model: spells out the model
• steady state or initial value: gives indications to ﬁnd the steady state
of a model, or the starting point for simulations or impulse response
functions based on the model’s solution.
• shocks: deﬁnes the shocks to the system
• computation: instructs Dynare to undertake speciﬁc operations (e.g.
forecasting, estimating impulse response functions)
Our exposition below will structured according to each of these blocks.
3.4 Filling out the preamble
The preamble generally involves three commands that tell Dynare what are
the model’s variables, which are endogenous and what are the parameters.
The commands are:
• var starts the list of endogenous variables, to be separated by commas.
• varexo starts the list of exogenous variables that will be shocked.
• parameters starts the list of parameters and assigns values to each.
In the case of our example, let’s diﬀerentiate between the stochastic and de
terministic cases. First, we lay these out, then we discuss them.
16 CHAPTER 3. SOLVING DSGE MODELS  BASICS
Figure 3.1: The .mod ﬁle contains ﬁve logically distinct parts.
3.4.1 The deterministic case
The model is inherited exactly as speciﬁed in the earlier description, except
that we no longer need the e
t
variable, as we can make z
t
directly exogenous.
Thus, the preamble would look like:
var y c k i l y l w r;
varexo z;
parameters beta psi delta alpha sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
sigma = (0.007/(1alpha));
epsilon = 10;
3.4.2 The stochastic case
In this case, we go back to considering the law of motion for technology, con
sisting of an exogenous shock, e
t
. With respect to the above, we therefore
3.4. FILLING OUT THE PREAMBLE 17
adjust the list of endogenous and exogenous variables, and add the parameter
ρ. Here’s what the preamble would look like:
var y c k i l y l w r z;
varexo e;
parameters beta psi delta alpha rho sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
sigma = (0.007/(1alpha));
epsilon = 10;
3.4.3 Comments on your ﬁrst lines of Dynare code
As you can tell, writing a .mod ﬁle is really quite straightforward. Two quick
comments:
NOTE! Remember that each instruction of the .mod ﬁle must be termi
nated by a semicolon (;), although a single instruction can span two lines if
you need extra space (just don’t put a semicolon at the end of the ﬁrst line).
TIP! You can also comment out any line by starting the line with two
forward slashes (//), or comment out an entire section by starting the section
with /* and ending with */. For example:
var y c k i l y l w r z;
varexo e;
parameters beta psi delta
alpha rho sigma epsilon;
// the above instruction reads over two lines
/*
the following section lists
several parameters which were
calibrated by my coauthor. Ask
her all the difficult questions!
*/
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
18 CHAPTER 3. SOLVING DSGE MODELS  BASICS
sigma = (0.007/(1alpha));
epsilon = 10;
3.5 Specifying the model
3.5.1 Model in Dynare notation
One of the beauties of Dynare is that you can input your model’s equa
tions naturally, almost as if you were writing them in an academic paper.
This greatly facilitates the sharing of your Dynare ﬁles, as your colleagues will
be able to understand your code in notime. There are just a few conventions
to follow. Let’s ﬁrst have a look at our model in Dynare notation, and
then go through the various Dynare input conventions. What you can already
try to do is glance at the model block below and see if you can recognize the
equations from the earlier example. See how easy it is to read Dynare code?
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)delta);
psi*c/(1l) = w;
c+i = y;
y = (k(1)^alpha)*(exp(z)*l)^(1alpha);
w = y*((epsilon1)/epsilon)*(1alpha)/l;
r = y*((epsilon1)/epsilon)*alpha/k(1);
i = k(1delta)*k(1);
y l = y/l;
z = rho*z(1)+e;
end;
Just in case you need a hint or two to recognize these equations, here’s
a brief description: the ﬁrst equation is the Euler equation in consumption.
The second the labor supply function. The third the accounting identity. The
fourth is the production function. The ﬁfth and sixth are the marginal cost
equal to markup equations. The seventh is the investment equality. The
eighth an identity that may be useful and the last the equation of motion of
technology.
NOTE! that the above model speciﬁcation corresponds to the stochastic
case; indeed, notice that the law of motion for technology is included, as per
our discussion of the preamble. The corresponding model for the determin
istic casce would simply loose the last equation.
3.5. SPECIFYING THE MODEL 19
3.5.2 General conventions
The above example illustrates the use of a few important commands and
conventions to translate a model into a Dynarereadable .mod ﬁle.
• The ﬁrst thing to notice, is that the model block of the .mod ﬁle begins
with the command model and ends with the command end.
• Second, in between, there need to be as many equations as you declared
endogenous variables (this is actually one of the ﬁrst things that Dynare
checks; it will immediately let you know if there are any problems).
• Third, as in the preamble and everywhere along the .mod ﬁle, each line
of instruction ends with a semicolon (except when a line is too long and
you want to break it across two lines. This is unlike Matlab where if you
break a line you need to add . . . ).
• Fourth, equations are entered one after the other; no matrix representa
tion is necessary. Note that variable and parameter names used in the
model block must be the same as those declared in the preamble; TIP!
remember that variable and parameter names are case sensitive.
3.5.3 Notational conventions
• Variables entering the system with a time t subscript are written plainly.
For example, x
t
would be written x.
• Variables entering the system with a time t − n subscript are written
with (−n) following them. For example, x
t−2
would be written x(−2)
(incidentally, this would count as two backward looking variables).
• In the same way, variables entering the system with a time t+n subscript
are written with (+n) following them. For example, x
t+2
would be
written x(+2). Writing x(2) is also allowed, but this notation makes it
slightly harder to count by hand the number of forward looking variables
(a useful measure to check); more on this below . . .
3.5.4 Timing conventions
• In Dynare, the timing of each variable reﬂects when that variable is de
cided. For instance, our capital stock is not decided today, but yesterday
(recall that it is a function of yesterday’s investment and capital stock);
it is what we call in the jargon a predetermined variable. Thus, even
though in the example presented above we wrote k
t+1
= i
t
+ (1 − δ)k
t
,
as in many papers, we would translate this equation into Dynare as
k=i+(1delta)*k(1).
20 CHAPTER 3. SOLVING DSGE MODELS  BASICS
• As another example, consider that in some wage negociation models,
wages used during a period are set the period before. Thus, in the
equation for wages, you can write wage in period t (when they are set),
but in the labor demand equation, wages should appear with a one
period lag.
• A slightly more roundabout way to explain the same thing is that for
stock variables, you must use a “stock at the end of the period” concept.
It is investment during period t that sets stock at the end of period t.
Be careful, a lot of papers use the “stock at the beginning of the period”
convention, as we did (on purpose to highlight this distinction!) in the
setup of the example model above.
3.5.5 Conventions specifying nonpredetermined variables
• A (+1) next to a variable tells Dynare to count the occurrence of that
variable as a jumper or forwardlooking or nonpredetermined variable.
• BlanchardKahn conditions are met only if the number of nonpredetermined
variables equals the number of eigenvalues greater than one. If this con
dition is not met, Dynare will put up a warning.
• Note that a variable may occur both as predetermined and nonpredetermined.
For instance, consumption could appear with a lead in the Euler equa
tion, but also with a lag in a habit formation equation, if you had one.
In this case, the second order diﬀerence equation would have two eigen
values, one needing to be greater and the other smaller than one for
stability.
3.5.6 Linear and loglinearized models
There are two other variants of the system’s equations which Dynare accom
modates. First, the linear model and second, the model in explogs. In
the ﬁrst case, all that is necessary is to write the term (linear) next to the
command model. Our example, with just the equation for y
l
for illustration,
would look like:
model (linear);
yy l=yy  ll;
end;
where repeating a letter for a variable means diﬀerence from steady state.
Otherwise, you may be interested to have Dynare take Taylor series ex
pansions in logs rather than in levels; this turns out to be a very useful option
3.6. SPECIFYING STEADY STATES AND/OR INITIAL VALUES 21
when estimating models with unit roots, as we will see in chapter 5. If so,
simply rewrite your equations by taking the exponential and logarithm of each
variable. The Dynare input convention makes this very easy to do. Our ex
ample would need to be rewritten as follows (just shown for the ﬁrst two
equations)
model;
(1/exp(cc)) = beta*(1/exp(cc(+1)))*(1+exp(rr(+1))delta);
psi*exp(cc)/(1exp(ll)) = exp(ww);
end;
where, this time, repeating a letter for a variable means log of that variable,
so that the level of a variable is given by exp(repeatedvariable).
3.6 Specifying steady states and/or initial values
Material in this section has created much confusion in the past. But with
some attention to the explanations below, you should get through unscathed.
Let’s start by emphasizing the uses of this section of the .mod ﬁle. First, recall
that stochastic models need to be linearized. Thus, they need to have a steady
state. One of the functions of this section is indeed to provide these steady
state values, or approximations of values. Second, irrespective of whether
you’re working with a stochastic or deterministic model, you may be inter
ested to start your simulations or impulse response functions from either a
steady state, or another given point. This section is also useful to specify this
starting value. Let’s see in more details how all this works.
In passing, though, note that the relevant commands in this section are
initval, endval or, more rarely, histval which is covered only in the Ref
erence Manual. The ﬁrst two are instead covered in what follows.
3.6.1 Stochastic models and steady states
In a stochastic setting, your model will need to be linearized before it is solved.
To do so, Dynare needs to know your model’s steady state (more details on
ﬁnding a steady state, as well as tips to do so more eﬃciently, are provided in
section 3.6.3 below). You can either enter exact steady state values into your
.mod ﬁle, or just approximations and let Dynare ﬁnd the exact steady state
(which it will do using numerical methods based on your approximations). In
either case, these values are entered in the initval block, as in the following
fashion:
initval;
22 CHAPTER 3. SOLVING DSGE MODELS  BASICS
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0;
e = 0;
end;
Then, by using the command steady, you can control whether you want to
start your simulations or impulse response functions from the steady state, or
from the exact values you speciﬁed in the initval block. Adding steady just
after your initval block will instruct Dynare to consider your initial values
as mere approximations and start simulations or impulse response functions
from the exact steady state. On the contrary, if you don’t add the command
steady, your simulations or impulse response functions will start from your
initial values, even if Dynare will have calculated your model’s exact steady
state for the purpose of linearization.
For the case in which you would like simulations and impulse response
functions to begin at the steady state, the above block would be expanded to
yield:
initval;
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0;
e = 0;
end;
steady;
TIP! If you’re dealing with a stochastic model, remember that its lin
ear approximation is good only in the vicinity of the steady state, thus it is
strongly recommended that you start your simulations from a steady state;
this means either using the command steady or entering exact steady state
values.
3.6. SPECIFYING STEADY STATES AND/OR INITIAL VALUES 23
3.6.2 Deterministic models and initial values
Deterministic models do not need to be linearized in order to be solved. Thus,
technically, you do not need to provide a steady state for these model. But
practically, most researchers are still interested to see how a model reacts to
shocks when originally in steady state. In the deterministic case, the initval
block serves very similar functions as described above. If you wanted to shock
your model starting from a steady state value, you would enter approximate
(or exact) steady state values in the initval block, followed by the command
steady. Otherwise, if you wanted to begin your solution path from an arbi
trary point, you would enter those values in your initval block and not use
the steady command. An illustration of the initval block in the determin
istic case appears further below.
3.6.3 Finding a steady state
The diﬃculty in the above, of course, is calculating actual steady state val
ues. Doing so borders on a form of art, and luck is unfortunately part of the
equation. Yet, the following TIPS! may help.
As mentioned above, Dynare can help in ﬁnding your model’s steady state
by calling the appropriate Matlab functions. But it is usually only successful
if the initial values you entered are close to the true steady state. If you have
trouble ﬁnding the steady state of your model, you can begin by playing with
the options following the steady command. These are:
• solve algo = 0: uses Matlab Optimization Toolbox FSOLVE
• solve algo = 1: uses Dynare’s own nonlinear equation solver
• solve algo = 2: splits the model into recursive blocks and solves each
block in turn.
• solve algo = 3: uses the Sims solver. This is the default option if none
are speciﬁed.
For complicated models, ﬁnding suitable initial values for the endogenous
variables is the trickiest part of ﬁnding the equilibrium of that model. Often,
it is better to start with a smaller model and add new variables one by one.
But even for simpler models, you may still run into diﬃculties in ﬁnding
your steady state. If so, another option is to enter your model in linear
terms. In this case, variables would be expressed in percent deviations from
steady state. Thus, their initial values would all be zero. Unfortunately, if
any of your original (nonlinear) equations involve sums (a likely fact), your
24 CHAPTER 3. SOLVING DSGE MODELS  BASICS
linearized equations will include ratios of steady state values, which you would
still need to calculate. Yet, you may be left needing to calculate fewer steady
state values than in the original, nonlinear, model.
Alternatively, you could also use an external program to calculate ex
act steady state values. For instance, you could write an external Maple
ﬁle and then enter the steady state solution by hand in Dynare. But of
course, this procedure could be time consuming and bothersome, especially
if you want to alter parameter values (and thus steady states) to undertake
robustness checks.
The alternative is to write a Matlab program to ﬁnd your model’s steady
state. Doing so has the clear advantages of being able to incorporate your
Matlab program directly into your .mod ﬁle so that running loops with diﬀer
ent parameter values, for instance, becomes seamless. NOTE! When doing so,
your matlab (.m) ﬁle should have the same name as your .mod ﬁle, followed
by steadystate For instance, if your .mod ﬁle is called example.mod, your
Matlab ﬁle should be called example steadystate.m and should be saved in
the same directory as your .mod ﬁle. Dynare will automatically check the di
rectory where you’ve saved your .mod ﬁle to see if such a Matlab ﬁle exists. If
so, it will use that ﬁle to ﬁnd steady state values regardless of whether you’ve
provided initial values in your .mod ﬁle.
Because Matlab does not work with analytical expressions, though (unless
you’re working with a particular toolbox), you need to do a little work to write
your steady state program. It is not enough to simply input the equations
as you’ve written them in your .mod ﬁle and ask Matlab to solve the system.
You will instead need to write your steady state program as if you were solv
ing for the steady state by hand. That is, you need to input your expressions
sequentially, whereby each lefthand side variable is written in terms of known
parameters or variables already solved in the lines above. For example, the
steady state ﬁle corresponding to the above example, in the stochastic case,
would be: (** example ﬁle to be added shortly)
3.6.4 Checking system stability
TIP! A handy command that you can add after the initval or endval block
(following the steady command if you decide to add one) is the check com
mand. This computes and displays the eigenvalues of your system
which are used in the solution method. As mentioned earlier, a necessary con
dition for the uniqueness of a stable equilibrium in the neighborhood of the
steady state is that there are as many eigenvalues larger than one in modulus
as there are forward looking variables in the system. If this condition is not
3.7. ADDING SHOCKS 25
met, Dynare will tell you that the BlanchardKahn conditions are not satisﬁed
(whether or not you insert the check command).
3.7 Adding shocks
3.7.1 Deterministic models  temporary shocks
When working with a deterministic model, you have the choice of introducing
both temporary and permanent shocks. The distinction is that under a tem
porary shock, the model eventually comes back to steady state, while under
a permanent shock, the model reaches a new steady state. In both cases,
though, the shocks are entirely expected, as explained in our original discus
sion on stochastic and deterministic models.
To work with a temporary shock, you are free to set the duration and
level of the shock. To specify a shock that lasts 9 periods on z
t
, for instance,
you would write:
shocks;
var z;
periods 1:9;
values 0.1;
end;
Given the above instructions, Dynare would replace the value of z
t
spec
iﬁed in the initval block with the value of 0.1 entered above. If variables
were in logs, this would have corresponded to a 10% shock. Note that you
can also use the mshocks command which multiplies the initial value of an
exogenous variable by the mshocks value. Finally, note that we could have
entered future periods in the shocks block, such as periods 5:10, in order to
study the anticipatory behavior of agents in response to future shocks.
3.7.2 Deterministic models  permanent shocks
To study the eﬀects of a permanent shock hitting the economy today, such
as a structural change in your model, you would not specify actual “shocks”,
but would simply tell the system to which (steady state) values you would like
it to move and let Dynare calculate the transition path. To do so, you would
use the endval block following the usual initval block. For instance, you
may specify all values to remain common between the two blocks, except for
the value of technology which you may presume changes permanently. The
corresponding instructions would be:
26 CHAPTER 3. SOLVING DSGE MODELS  BASICS
initval;
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0;
end;
steady;
endval;
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0.1;
end;
steady;
where steady can also be added to the endval block, and serves the same
functionality as described earlier (namely, of telling Dynare to start and/ or
end at a steady state close to the values you entered. If you do not use steady
after endval, and the latter does not list exact steady state values, you may
impose on your system that it does not return to steady state. This is unusual.
In this case, your problem would become a socalled two boundary problem,
which, when solved, requires that the path of your endogenous variables pass
through the steady state closest to your endval values). In our example, we
make use of the second steady since the actual terminal steady state values
are bound to be somewhat diﬀerent from those entered above, which are noth
ing but the initial values for all variables except for technology.
In the above example, the value of technology would move to 0.1 in pe
riod 1 (tomorrow) and thereafter. But of course, the other variables  the
endogenous variables  will take longer to reach their new steady state values.
TIP! If you instead wanted to study the eﬀects of a permanent but future
shock (anticipated as usual), you would have to add a shocks block after the
endval block to “undo” the ﬁrst several periods of the permanent shock. For
instance, suppose you wanted the value of technology to move to 0.1, but only
in period 10. Then you would follow the above endval block with:
shocks;
var z;
3.8. SELECTING A COMPUTATION 27
periods 1:9;
values 0;
end;
3.7.3 Stochastic models
Recall from our earlier description of stochastic models that shocks are only
allowed to be temporary. A permanent shock cannot be accommodated due to
the need to stationarize the model around a steady state. Furthermore, shocks
can only hit the system today, as the expectation of future shocks must be
zero. With that in mind, we can however make the eﬀect of the shock propa
gate slowly throughout the economy by introducing a “latent shock variable”
such as e
t
in our example, that aﬀects the model’s true exogenous variable, z
t
in our example, which is itself an AR(1), exactly as in the model we introduced
from the outset. In that case, though, we would declare z
t
as an endogenous
variable and e
t
as an exogenous variable, as we did in the preamble of the
.mod ﬁle in section 3.4. Supposing we wanted to add a shock with variance
σ
2
, where σ is determined in the preamble block, we would write:
shocks;
var e = sigma^2;
end;
TIP! You can actually mix in deterministic shocks in stochastic models
by using the commands varexo det and listing some shocks as lasting more
than one period in the shocks block. For information on how to do so, please
see the Reference Manual. This can be particularly useful if you’re studying
the eﬀects of anticipated shocks in a stochastic model. For instance, you may
be interested in what happens to your monetary model if agents began ex
pecting higher inﬂation, or a depreciation of your currency.
3.8 Selecting a computation
So far, we have written an instructive .mod ﬁle, but what should Dynare do
with it? What are we interested in? In most cases, it will be impulse re
sponse functions (IRFs) due to the external shocks. Let’s see which are the
appropriate commands to give to Dynare. Again, we will distinguish between
deterministic and stochastic models.
28 CHAPTER 3. SOLVING DSGE MODELS  BASICS
3.8.1 For deterministic models
In the deterministic case, all you need to do is add the command simul
at the bottom of your .mod ﬁle. Note that the command takes the option
[ (periods=INTEGER) ] The command simul triggers the computation a
numerical simulation of the trajectory of the model’s solution for the number
of periods set in the option. To do so, it uses a Newton method to solve
simultaneously all the equations for every period (see Juillard (1996) for de
tails). Note that unless you use the endval command, the algorithm makes
the simplifying assumption that the system is back to equilibrium after the
speciﬁed number of periods. Thus, you must specify a large enough number
of periods such that increasing it further doesn’t change the simulation for
all practical purpose. In the case of a temporary shock, for instance, the tra
jectory will basicaly describe how the system gets back to equilibrium after
being perturbed from the shocks you entered.
3.8.2 For stochastic models
In the more common case of stochastic models, the command stoch simul is
appropriate. This command instructs Dynare to compute a Taylor approxi
mation of the decision and transition functions for the model (the equations
listing current values of the endogenous variables of the model as a func
tion of the previous state of the model and current shocks), impulse response
functions and various descriptive statistics (moments, variance decomposition,
correlation and autocorrelation coeﬃcients).
1
Impulse response functions are the expected future path of the endogenous
variables conditional on a shock in period 1 of one standard deviation.TIP!
If you linearize your model up to a ﬁrst order, impulse response functions
are simply the algebraic forward iteration of your model’s policy or decision
rule. If you instead linearize to a second order, impulse response functions
will be the result of actual Monte Carlo simulations of future shocks. This is
because in second order linear equations, you will have cross terms involving
the shocks, so that the eﬀects of the shocks depend on the state of the system
when the shocks hit. Thus, it is impossible to get algebraic average values
of all future shocks and their impact. The technique is instead to pull fu
ture shocks from their distribution and see how they impact your system, and
repeat this procedure a multitude of times in order to draw out an average
response. That said, note that future shocks will not have a signiﬁcant impact
1
For correlated shocks, the variance decomposition is computed as in the VAR literature
through a Cholesky decomposition of the covariance matrix of the exogenous variables.
When the shocks are correlated, the variance decomposition depends upon the order of the
variables in the varexo command.
3.8. SELECTING A COMPUTATION 29
on your results, since they get averaged between each Monte Carlo trial and
in the limit should sum to zero, given their mean of zero. Note that in the
case of a second order approximation, Dynare will return the actual sample
moments from the simulations. For ﬁrst order linearizations, Dynare will in
stead report theoretical moments. In both cases, the return to steady state
is asymptotic, TIP! thus you should make sure to specify suﬃcient periods
in your IRFs such that you actually see your graphs return to steady state.
Details on implementing this appear below.
If you’re interested to peer a little further into what exactly is going on
behind the scenes of Dynare’s computations, have a look at Chapter 7. Here
instead, we focus on the application of the command and reproduce below the
most common options that can be added to stoch simul. For a complete list
of options, please see the Reference Manual.
Options following the stoch simul command:
• ar = INTEGER: Order of autocorrelation coeﬃcients to compute and
to print (default = 5).
• dr algo = 0 or 1: speciﬁes the algorithm used for computing the quadratic
approximation of the decision rules: 0 uses a pure perturbation approach
as in SchmittGrohe and Uribe (2004) (default) and 1 moves the point
around which the Taylor expansion is computed toward the means of
the distribution as in Collard and Juillard (2001b).
• drop = INTEGER: number of points dropped at the beginning of sim
ulation before computing the summary statistics (default = 100).
• hp ﬁlter = INTEGER: uses HP ﬁlter with lambda = INTEGER before
computing moments (default: no ﬁlter).
• hp ngrid = INTEGER: number of points in the grid for the discreet In
verse Fast Fourier Transform used in the HP ﬁlter computation. It may
be necessary to increase it for highly autocorrelated processes (default
= 512).
• irf = INTEGER: number of periods on which to compute the IRFs
(default = 40). Setting IRF=0, suppresses the plotting of IRF’s.
• relative irf requests the computation of normalized IRFs in percentage
of the standard error of each shock.
• nocorr: doesn’t print the correlation matrix (printing is the default).
• nofunctions: doesn’t print the coeﬃcients of the approximated solution
(printing is the default).
30 CHAPTER 3. SOLVING DSGE MODELS  BASICS
• nomoments: doesn’t print moments of the endogenous variables (print
ing them is the default).
• noprint: cancel any printing; usefull for loops.
• order = 1 or 2 : order of Taylor approximation (default = 2), unless
you’re working with a linear model in which case the order is automati
cally set to 1.
• periods = INTEGER: speciﬁes the number of periods to use in simu
lations (default = 0). TIP! A simulation is similar to running impulse
response functions with a model linearized to the second order, in the
way that both sample shocks from their distribution to see how the
system reacts, but a simulation only repeats the process once, whereas
impulse response functions run a multitude of Monte Carlo trials in order
to get an average response of your system.
• qz criterium = INTEGER or DOUBLE: value used to split stable from
unstable eigenvalues in reordering the Generalized Schur decomposition
used for solving 1st order problems (default = 1.000001).
• replic = INTEGER: number of simulated series used to compute the
IRFs (default = 1 if order = 1, and 50 otherwise).
• simul seed = INTEGER or DOUBLE or (EXPRESSION): speciﬁes a
seed for the random number generator so as to obtain the same random
sample at each run of the program. Otherwise a diﬀerent sample is
used for each run (default: seed not speciﬁed). If you linearized to a
second order, Dynare will actually undertake Monte Carlo simulations
to generate moments of your variables. Because of the simulation, results
are bound to be slightly diﬀerent each time you run your program, except
if you ﬁx the seed for the random number generator. TIP! If you do
decide to ﬁx the seed, you should at least try to run your program
without using simul seed, just to check the robustness of your results.
Going back to our good old example, suppose we were interested in print
ing all the various measures of moments of our variables, want to see impulse
response functions for all variables, are basically happy with all default op
tions and want to carry out simulations over a good number of periods. We
would then end our .mod ﬁle with the following command:
stoch simul(periods=2100);
3.9. THE COMPLETE .MOD FILE 31
3.9 The complete .mod ﬁle
For completion’s sake, and for the pleasure of seeing our work bear its fruits,
here are the complete .mod ﬁles corresponding to our example for the de
terministic and stochastic case. You can ﬁnd the corresponding ﬁles in the
models folder under UserGuide in your installation of Dynare. The ﬁles are
called RBC Monop JFV.mod for stochastic models and RBC Monop Det.mod for
deterministic models.
3.9.1 The stochastic model
var y c k i l y l w r z;
varexo e;
parameters beta psi delta alpha rho gamma sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
rho = 0.95;
sigma = (0.007/(1alpha));
epsilon = 10;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)delta);
psi*c/(1l) = w;
c+i = y;
y = (k(1)^alpha)*(exp(z)*l)^(1alpha);
w = y*((epsilon1)/epsilon)*(1alpha)/l;
r = y*((epsilon1)/epsilon)*alpha/k(1);
i = k(1delta)*k(1);
y l = y/l;
z = rho*z(1)+e;
end;
initval;
k = 9;
c = 0.76;
l = 0.3;
w = 2.07;
r = 0.03;
z = 0;
e = 0;
end;
32 CHAPTER 3. SOLVING DSGE MODELS  BASICS
steady;
check;
shocks;
var e = sigma^2;
end;
stoch simul(periods=2100);
3.9.2 The deterministic model (case of temporary shock)
var y c k i l y l w r ;
varexo z;
parameters beta psi delta alpha sigma epsilon;
alpha = 0.33;
beta = 0.99;
delta = 0.023;
psi = 1.75;
sigma = (0.007/(1alpha));
epsilon = 10;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)delta);
psi*c/(1l) = w;
c+i = y;
y = (k(1)^alpha)*(exp(z)*l)^(1alpha);
w = y*((epsilon1)/epsilon)*(1alpha)/l;
r = y*((epsilon1)/epsilon)*alpha/k(1);
i = k(1delta)*k(1);
y l = y/l;
end;
initval;
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0;
end;
steady;
3.10. FILE EXECUTION AND RESULTS 33
check;
shocks;
var z;
periods 1:9;
values 0.1;
end;
simul(periods=2100);
3.10 File execution and results
To see this all come to life, let’s run our .mod ﬁle, which is conveniently
installed by default in the Dynare “examples” directory (the .mod ﬁle cor
responding to the stochastic model is called RBC Monop JFV.mod and that
corresponding to the deterministic model is called RBC Monop Det.mod). (**
note, this may not be the case when testing the beta version of Matlab version
4)
To run a .mod ﬁle, navigate within Matlab to the directory where the
example .mod ﬁles are stored. You can do this by clicking in the “current di
rectory” window of Matlab, or typing the path directly in the top white ﬁeld
of Matlab. Once there, all you need to do is place your cursor in the Matlab
command window and type, for instance, dynare ExSolStoch; to execute
your .mod ﬁle.
Running these .mod ﬁles should take at most 30 seconds. As a result, you
should get two forms of output  tabular in the Matlab command window and
graphical in one or more popup windows. Let’s review these results.
3.10.1 Results  stochastic models
The tabular results can be summarized as follows:
1. Model summary: a count of the various variable types in your model
(endogenous, jumpers, etc...).
2. Eigenvalues should be displayed, and you should see a conﬁrmation of
the BlanchardKahn conditions if you used the command check in your
.mod ﬁle.
34 CHAPTER 3. SOLVING DSGE MODELS  BASICS
3. Matrix of covariance of exogenous shocks: this should square with
the values of the shock variances and covariances you provided in the
.mod ﬁle.
4. Policy and transition functions: Solving the rational exectation
model, E
t
[f(y
t+1
, y
t
, y
t−1
, u
t
)] = 0 , means ﬁnding an unkown function,
y
t
= g(y
t−1
, u
t
) that could be plugged into the original model and satisfy
the implied restrictions (the ﬁrst order conditions). A ﬁrst order approx
imation of this function can be written as y
t
= ¯ y + g
y
ˆ y
t−1
+ g
u
u
t
, with
ˆ y
t
= y
t
− ¯ y and ¯ y being the steadystate value of y, and where g
x
is the
partial derivative of the g function with respect to variable x. In other
words, the function g is a time recursive (approximated) representation
of the model that can generate timeseries that will approximatively sat
isfy the rational expectation hypothesis contained in the original model.
In Dynare, the table “Policy and Transition function” contains the el
ements of g
y
and g
u
. Details on the policy and transition function can
be found in Chapter 6.
5. Moments of simulated variables: up to the fourth moments.
6. Correlation of simulated variables: these are the contemporaneous
correlations, presented in a table.
7. Autocorrelation of simulated variables: up to the ﬁfth lag, as spec
iﬁed in the options of stoch simul.
The graphical results, instead, show the actual impulse response func
tions for each of the endogenous variables, given that they actually moved.
These can be especially useful in visualizing the shape of the transition func
tions and the extent to which each variable is aﬀected. TIP! If some variables
do not return to their steady state, either check that you have included enough
periods in your simulations, or make sure that your model is stationary, i.e.
that your steady state actually exists and is stable. If not, you should detrend
your variables and rewrite your model in terms of those variables.
3.10.2 Results  deterministic models
Automatically displayed results are much more scarce in the case of deter
ministic models. If you entered steady, you will get a list of your steady
state results. If you entered check, eigenvalues will also be displayed and you
should receive a statement that the rank condition has been satisﬁed, if all
goes well! Finally, you will see some intermediate output: the errors at each
iteration of the Newton solver used to estimate the solution to your model.
TIP! You should see these errors decrease upon each iteration; if not, your
model will probably not converge. If so, you may want to try to increase the
periods for the transition to the new steady state (the number of simulations
3.10. FILE EXECUTION AND RESULTS 35
periods). But more often, it may be a good idea to revise your equations. Of
course, although Dynare does not display a rich set of statistics and graphs
corresponding to the simulated output, it does not mean that you cannot cre
ate these by hand from Matlab. To do so, you should start by looking at
section 4.1.3 of chapter 4 on ﬁnding, saving and viewing your output.
Chapter 4
Solving DSGE models 
advanced topics
This chapter is a collection of topics  not all related to each other  that you
will probably ﬁnd interesting or at least understandable, if you have read,
and/ or feel comfortable with, the earlier chapter 3 on the basics of solving
DSGE models. To provide at least some consistency, this chapter is divided
into three sections. The ﬁrst section deals directly with features of Dynare,
such as dealing with correlated shocks, ﬁnding and saving your output, using
loops, referring to external ﬁles and dealing with inﬁnite eigenvalues. The
second section overviews some of the inner workings of Dynare. The goal
is to provide a brief explanation of the ﬁles that are created by Dynare to
help you in troubleshooting or provide a starting point in case you actually
want to customize the way Dynare works. The third section of the chapter
focusses on modeling tips optimized for Dynare, but possibly also helpful for
other work.
4.1 Dynare features and functionality
4.1.1 Other examples
Other examples of .mod ﬁles used to generate impulse response functions are
available on the Dynare website. In particular, Jesus FernandezVillaverde
has provided a series of RBC model variants (from the most basic to some
including variable capacity utilization, indivisible labor and investment spe
ciﬁc technological change). You can ﬁnd these, along with helpful notes and
explanations, in the Oﬃcial Examples section of the Dynare website.
Also, don’t forget to check occasionally the Dynare contributions and ex
amples forum to see if any other user has posted an example that could help
37
38 CHAPTER 4. SOLVING DSGE MODELS  ADVANCED TOPICS
you in your work; or maybe you would like to post an example there yourself?
4.1.2 Alternative, complete example
The following example aims to give you an alternative example to the one in
chapter 3, to learn the workings of Dynare. It also aims to give you exposure
to dealing with several correlated shocks. Your model may have two or
more shocks, and these may be correlated to each other. The example below
illustrates how you would introduce this into Dynare. Actually, the example
provided is somewhat more complete than strictly necessary. This is to give
you an alternative, fullblown example to the one described in chapter 3.
The model
The model is a simpliﬁed standard RBC model taken from Collard and Juil
lard (2003) which served as the original User Guide for Dynare.
The economy consists of an inﬁnitely living representative agent who values
consumption c
t
and labor services h
t
according to the following utility function
E
t
∞
τ=t
β
τ−t
_
log(c
t
) −θ
h
1+ψ
t
1 +ψ
_
where, as usual, the discount factor 0 < β < 1, the disutility of labor θ > 0
and the labor supply elasticity ψ ≥ 0.
A social planner maximizes this utility function subject to the resource
constraint
c
t
+i
t
= y
t
where i
t
is investment and y
t
output. Consumers are therefore also owners
of the ﬁrms. The economy is a real economy, where part of output can be
consumed and part invested to form physical capital. As is standard, the law
of motion of capital is given by
k
t+1
= exp(b
t
)i
t
+ (1 −δ)k
t
with 0 < δ < 1, where δ is physical depreciation and b
t
a shock aﬀecting
incorporated technological progress.
We assume output is produced according to a standard constant returns
to scale technology of the form
y
t
= exp(a
t
)k
α
t
h
1−α
t
with α being the capital elasticity in the production function, with 0 < α < 1,
and where a
t
represents a stochastic technological shock (or Solow residual).
4.1. DYNARE FEATURES AND FUNCTIONALITY 39
Finally, we specify a shock structure that allows for shocks to display
persistence across time and correlation in the current period. That is
_
a
t
b
t
_
=
_
ρ τ
τ ρ
__
a
t−1
b
t−1
_
+
_
t
ν
t
_
where ρ + τ < 1 and ρ −τ < 1 to ensure stationarity (we call ρ the coeﬃ
cient of persistence and τ that of crosspersistence). Furthermore, we assume
E
t
(
t
) = 0, E
t
(ν
t
) = 0 and that the contemporaneous variancecovariance
matrix of the innovations
t
and ν
t
is given by
_
σ
2
ψσ
σ
ν
ψσ
σ
ν
σ
2
ν
_
and where corr(
t
ν
s
) = 0, corr(
t
s
) = 0 and corr(ν
t
ν
s
) = 0 for all t = s.
This system  probably quite similar to standard RBC models you have run
into  yields the following ﬁrst order conditions (which are straightforward to
reproduce in case you have doubts. . . ) and equilibrium conditions drawn from
the description above. Note that the ﬁrst equation captures the labor supply
function and the second the intertemporal consumption Euler equation.
c
t
θh
1+ψ
t
= (1 −α)y
t
1 = βE
t
__
exp(b
t
)c
t
exp(b
t+1
)c
t+1
__
exp(b
t+1
)α
y
t+1
k
t+1
+ 1 −δ
__
y
t
= exp(a
t
)k
α
t
h
1−α
t
k
t+1
= exp(b
t
)i
t
+ (1 −δ)k
t
a
t
= ρa
t−1
+τb
t−1
+
t
b
t
= τa
t−1
+ρb
t−1
+ν
t
The .mod ﬁle
To “translate” the model into a language understandable by Dynare, we would
follow the steps outlined in chapter 3. We will assume that you’re comfort
able with these and simply present the ﬁnal .mod ﬁle below. Fist, though,
note that to introduce shocks into Dynare, we have two options (this was not
discussed in the earlier chapter). Either write:
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
40 CHAPTER 4. SOLVING DSGE MODELS  ADVANCED TOPICS
where the last line speciﬁes the contemporaneous correlation between our two
exogenous variables.
Alternatively, you can also write:
shocks;
var e = 0.009^2;
var u = 0.009^2;
var e, u = phi*0.009*0.009;
end;
So that you can gain experience by manipulating the entire model, here is
the complete .mod ﬁle corresponding to the above example. You can ﬁnd the
corresponding ﬁle in the models folder under UserGuide in your installation
of Dynare. The ﬁle is called Alt Ex1.mod.
var y, c, k, a, h, b;
varexo e, u;
parameters beta, rho, alpha, delta, theta, psi, tau;
alpha = 0.36;
rho = 0.95;
tau = 0.025;
beta = 0.99;
delta = 0.025;
psi = 0;
theta = 2.95;
phi = 0.1;
model;
c*theta*h^(1+psi)=(1alpha)*y;
k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1)))
*(exp(b(+1))*alpha*y(+1)+(1delta)*k));
y = exp(a)*(k(1)^alpha)*(h^(1alpha));
k = exp(b)*(yc)+(1delta)*k(1);
a = rho*a(1)+tau*b(1) + e;
b = tau*a(1)+rho*b(1) + u;
end;
initval;
y = 1.08068253095672;
c = 0.80359242014163;
4.1. DYNARE FEATURES AND FUNCTIONALITY 41
h = 0.29175631001732;
k = 5;
a = 0;
b = 0;
e = 0;
u = 0;
end;
shocks;
var e; stderr 0.009;
var u; stderr 0.009;
var e, u = phi*0.009*0.009;
end;
stoch simul(periods=2100);
4.1.3 Finding, saving and viewing your output
Where is output stored? Most of the moments of interest are stored in global
variable oo You can easily browse this global variable in Matlab by either
calling it in the command line, or using the workspace interface. In global
variable oo you will ﬁnd the following (NOTE! variables will always appear
in the order in which you declared them in the preamble block of your .mod
ﬁle):
• steady state: the steady state of your variables
• mean: the mean of your variables
• var: the variance of your variables
• autocorr: the various autocorrelation matrices of your variables. Each
row of these matrices will correspond to a variables in time t, and
columns correspond to the variables lagged 1, for the ﬁrst matrix, then
lagged 2 for the second matrix, and so on. Thus, the matrix of auto
correlations that is automatically displayed in the results after running
stoch simul has, running down each column, the diagonal elements of
each of the various autocorrelation matrices described here.
• gamma y: the matrices of autocovariances. gamma y{1} represents vari
ances, while gamma y{2} represents autocovariances where variables on
each column are lagged by one period and so on. By default, Dynare will
return autocovariances with a lag of 5. The last matrix (gamma y{7} in
42 CHAPTER 4. SOLVING DSGE MODELS  ADVANCED TOPICS
the default case) returns the variance decomposition, where each col
umn captures the independent contribution of each shock to the variance
of each variable.
Furthermore, if you decide to run impulse response functions, you will
ﬁnd a global variable oo .irfs comprising of vectors named endogenous
variable exogenous variable, like y e, reporting the values of the endoge
nous variables corresponding to the impulse response functions, as a result of
the independent impulse of each exogenous shock.
To save your simulated variables, you can add the following command at
the end of your .mod ﬁle: dynasave (FILENAME) [variable names separated
by commas] If no variable names are speciﬁed in the optional ﬁeld, Dynare will
save all endogenous variables. In Matlab, variables saved with the dynasave
command can be retrieved by using the Matlab command load mat FILENAME.
4.1.4 Referring to external ﬁles
You may ﬁnd it convenient to refer to an external ﬁle, either to compute the
steady state of your model, or when specifying shocks in an external ﬁle. The
former is described in section 3.6 of chapter 3 when discussing steady states.
The advantage of using Matlab, say, to ﬁnd your model’s steady state was
clear with respect to Dynare version 3, as the latter resorted to numerical
approximations to ﬁnd steady state values. But Dynare version 4 now uses
the same analytical methods available in Matlab. For most usage scenarios,
you should therefore do just as well to ask Dynare to compute your model’s
steady state (except, maybe, if you want to run loops, to vary your parameter
values, for instance, in which case writing a Matlab program may be more
handy).
But you may also be interested in the second possibility described above,
namely of specifying shocks in an external ﬁle, to simulate a model based on
shocks from a prior estimation, for instance. You could then retrieve the ex
ogenous shocks from the oo ﬁle by saving them in a ﬁle called dataﬁle.mat.
Finally, you could simulate a deterministic model with the shocks saved from
the estimation by specifying the source ﬁle for the shocks, using the
shocks(shocks file = datafile.mat) command. But of course, this is a bit
of a workaround, since you could also use the builtin commands in Dynare
to generate impulse response functions from estimated shocks, as described in
chapter 5.
4.2. FILES CREATED BY DYNARE 43
4.1.5 Inﬁnite eigenvalues
If you use the command check in your .mod ﬁle, Dynare will report your sys
tem’s eigenvalues and tell you if these meet the BlanchardKahn conditions.
At that point, don’t worry if you get inﬁnite eigenvalues  these are are ﬁrmly
grounded in the theory of generalized eigenvalues. They have no detrimental
inﬂuence on the solution algorithm. As far as BlanchardKahn conditions are
concerned inﬁnite eigenvalues are counted as explosive roots of modulus larger
than one.
4.2 Files created by Dynare
At times, you may get a message that there is an error in a ﬁle with a new
name, or you may want to have a closer look at how Dynare actually solves
your model  out of curiosity or maybe to do some customization of your own.
You may therefore ﬁnd it helpful to get a brief overview of the internal ﬁles
that Dynare generates and the function of each one.
The dynare preprocessors essentially does three successive tasks: (i) pars
ing of the mod ﬁle (it checks that the mod ﬁle is syntactically correct), and its
translation into internal machine representation (in particular, model equa
tions are translated into expression trees), (ii) symbolic derivation of the model
equations, up to the needed order (depending on the computing needs), (iii)
outputting of several ﬁles, which are used from matlab. If the mod ﬁle is
“ﬁlename.mod”, then the preprocessor creates the following ﬁles:
• ﬁlename.m: a matlab ﬁle containing several instructions, notably the
parameter initializations and the matlab calls corresponding to comput
ing tasks
• ﬁlename dynamic.m: a matlab ﬁle containing the model equations
and their derivatives (ﬁrst, second and maybe third). Endogenous vari
ables (resp. exogenous variables, parameters) are contained in a “y”
(resp. “x”, “params”) vector, with an index number depending on the
declaration order. The “y” vector has as many entries as their are (vari
able, lag) pairs in the declared model. The model equations residuals
are stored in a vector named “residuals”. The model jacobian is put in
“g1” matrix. Second (resp. third) derivatives are in “g2” matrix (resp.
“g3”). If the “use dll” option has been speciﬁed in the model decla
ration, the preprocessor will output a C ﬁle (with .c extension) rather
than a matlab ﬁle. It is then compiled to create a library (DLL) ﬁle. Us
ing a compiled C ﬁle is supposed to give better computing performance
in model simulation/estimation.
44 CHAPTER 4. SOLVING DSGE MODELS  ADVANCED TOPICS
• ﬁlename static.m: a matlab ﬁle containing the stationarized version of
the model (i.e. where lagged variables are replaced by current variables),
with its jacobian. Used to compute the steady state. Same notations
than the dynamic ﬁle. Replaced by a C ﬁle when “use dll” option is
speciﬁed.
4.3 Modeling tips
4.3.1 Stationarizing your model
Models in Dynare must be stationary, such that you can linearize them around
a steady state and return to steady state after a shock. Thus, you must ﬁrst
stationarize your model, then linearize it, either by hand, or by letting Dynare
do the work. You can then reconstruct expost the nonstationary simulated
variables after running impulse response functions.
For deterministic models, the trick is to use only stationary variables in
t + 1. More generally, if y
t
is I(1), you can always write y
t+1
as y
t
+ dy
t+1
,
where dy
t
= y
t
− y
t−1
. Of course, you need to know the value of dy
t
at the
ﬁnal equilibrium.
Note that in a stationary model, it is expected that variables will eventually
go back to steady state after the initial shock. If you expect to see a growing
curve for a variable, you are thinking about a growth model. Because growth
models are nonstationary, it is easier to work with the stationarized version of
such models. Again, if you know the trend, you can always add it back after
the simulation of the stationary components of the variables.
4.3.2 Expectations taken in the past
For instance, to enter the term E
t−1
y
t
, deﬁne s
t
= E
t
[y
t+1
] and then use s(−1)
in your .mod ﬁle. Note that, because of Jensen’s inequality, you cannot do
this for terms that enter your equation in a nonlinear fashion. If you do have
nonlinear terms on which you want to take expectations in the past, you
would need to apply the above manipulation to the entire equation, as if y
t
were an equation, not just a variable.
4.3.3 Inﬁnite sums
Dealing with inﬁnite sums is tricky in general, and needs particular care when
working with Dynare. The trick is to use a recursive representation of the
sum. For example, suppose your model included:
∞
j=0
β
j
x
t+j
= 0,
4.3. MODELING TIPS 45
Note that the above can also be written by using an auxiliary variable S
t
,
deﬁned as:
S
t
≡
∞
j=0
β
j
x
t+j
,
which can also be written in the following recursive manner:
S
t
≡
∞
j=0
β
j
x
t+j
= x
t
+
∞
j=1
β
j
x
t+j
= x
t
+β
∞
j=0
β
j
x
t+1+j
≡ x
t
+S
t+1
This formulation turns out to be useful in problems of the following form:
∞
j=0
β
j
x
t+j
= p
t
∞
j=0
γ
j
y
t+j
,
which can be written as a recursive system of the form:
S1
t
= x
t
+βS1
t+1
,
S2
t
= y
t
+γS2
t+1
,
S1 = p
t
S2.
This is particularly helpful, for instance, in a Calvo type setting, as
illustrated in the following brief example. The RBC model with monopolistic
competition introduced in chapter 3 involved ﬂexible prices. The extension
with sticky prices, `a la Calvo for instance, is instead typical of the new Key
nesian monetary literature, exempliﬁed by papers such as Clarida, Gali, and
Gertler (1999).
The optimal price for a ﬁrm resetting its price in period t, given that it
will be able to reset its price only with probability 1 −θ each period, is
p
∗
t
(i) = µ + (1 −βθ)
∞
k=0
(βθ)
k
E
t
[mc
n
t+k
(i)]
where µ is the markup, β is a discount factor, i represents a ﬁrm of the contin
uum between 0 and 1, and mc
t
is marginal cost as described in the example in
chapter 3. The trouble, of course, is how to input this inﬁnite sum into
Dynare?
It turns out that the Calvo price setting implies that the aggregate price
follows the equation of motion p
t
= θp
t−1
+ (1 − θ)p
∗
t
, thus implying the
following inﬂation relationship π
t
= (1 − θ)(p
∗
t
− p
t−1
). Finally, we can also
rewrite the optimal price setting equation, after some algebraic manipulations,
as
p
∗
t
−p
t−1
= (1 −βθ)
∞
k=0
(βθ)
k
E
t
[ ´ mc
t+k
] +
∞
k=0
(βθ)
k
E
t
[π
t+k
]
46 CHAPTER 4. SOLVING DSGE MODELS  ADVANCED TOPICS
where ´ mc
t+k
= mc
t+k
+µ is the deviation of the marginal cost from its natural
rate, deﬁned as the marginal cost when prices are perfectly ﬂexible.
The trick now is to note that the above can be written recursively, by
writing the right hand side as the ﬁrst term of the sum (with k = 0) plus the
remainder of the sum, which can be written as the left hand side term scrolled
forward one period and appropriately discounted. Mathematically, this yields:
p
∗
t
−p
t−1
= (1 −βθ) ´ mc
t+k
+π
t
+β θE
t
[p
∗
t+1
−p
t
]
which has gotten rid of our inﬁnite sum! That would be enough for Dynare,
but for convenience, we can go one step further and write the above as
π
t
= βE
t
[π
t+1
] +λ´ mc
t
where λ ≡
(1−θ)(1−βθ)
θ
, which is the recognizable inﬂation equation in the new
Keynesian (or new Neoclassical) monetary literature.
4.3.4 Inﬁnite sums with changing timing of expectations
When you are not able to write an inﬁnite sum recursively, as the index of
the expectations changes with each element of the sum, as in the following
example, a diﬀerent approach than the one mentioned above is necessary.
Suppose your model included the following sum:
y
t
=
∞
j=0
E
t−j
x
t
where y
t
and x
t
are endogenous variables.
In Dynare, the best way to handle this is to write out the ﬁrst k terms
explicitly and enter each one in Dynare, such as: E
t−1
x
t
+E
t−2
x
t
+. . .+E
t−k
x
t
.
Chapter 5
Estimating DSGE models 
basics
As in the chapter 3, this chapter is structured around an example. The goal
of this chapter is to lead you through the basic functionality in Dynare to
estimate models using Bayesian techniques, so that by the end of the chapter
you should have the capacity to estimate a model of your own. This chapter
is therefore very practicallyoriented and abstracts from the underlying com
putations that Dynare undertakes to estimate a model; that subject is instead
covered in some depth in chapter 8, while more advanced topics of practical
appeal are discussed in chapter 6.
5.1 Introducing an example
The example introduced in this chapter is particularly basic. This is for two
reasons. First, we did not want to introduce yet another example in this sec
tion; there’s enough new material to keep you busy. Instead, we thought it
would be easiest to simply continue working with the example introduced in
chapter 3 with which you are probably already quite familiar. Second, the
goal of the example in this chapter is really to explain features in context,
but not necessarily to duplicate a “real life scenario” you would face when
writing a paper. Once you feel comfortable with the content of this chapter,
though, you can always move on to chapter 6 where you will ﬁnd a fullﬂedged
replication of a recent academic paper, featuring a nonstationary model.
Recall from chapter 3 that we are dealing with an RBC model with mo
nopolistic competition. Suppose we had data on business cycle variations of
output. Suppose also that we thought our little RBC model did a good job of
reproducing reality. We could then use Bayesian methods to estimate the pa
rameters of the model: α, the capital share of output, β, the discount factor,
47
48 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
δ, the depreciation rate, ψ, the weight on leisure in the utility function, ρ, the
degree of persistence in productivity, and , the markup parameter. Note that
in Bayesian estimation, the condition for undertaking estimation is that there
be at least as many shocks as there are observables (a less stringent condition
than for maximum likelihood estimation). It may be that this does not allow
you to identify all your parameters  yielding posterior distributions identical
to prior distributions  but the Bayesian estimation procedure would still run
successfully. Let’s see how to go about doing this.
5.2 Declaring variables and parameters
To input the above model into Dynare for estimation purposes, we must ﬁrst
declare the model’s variables in the preamble of the .mod ﬁle. This is done
exactly as described in chapter 3 on solving DSGE models. We thus begin the
.mod ﬁle with:
var y c k i l y l w r z;
varexo e;
parameters beta psi delta alpha rho epsilon;
5.3 Declaring the model
Suppose that the equation of motion of technology is a stationary AR(1) with
an autoregressive parameter, ρ, less than one. The model’s variables would
therefore be stationary and we can proceed without complications. The al
ternative scenario with nonstationary variables is more complicated and
dealt with in chapter 6 (in the additional example). In the stationary case,
our model block would look exactly as in chater 3:
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)delta);
psi*c/(1l) = w;
c+i = y;
y = (k(1)^alpha)*(exp(z)*l)^(1alpha);
w = y*((epsilon1)/epsilon)*(1alpha)/l;
r = y*((epsilon1)/epsilon)*alpha/k(1);
i = k(1delta)*k(1);
y l = y/l;
z = rho*z(1)+e;
5.4. DECLARING OBSERVABLE VARIABLES 49
end;
5.4 Declaring observable variables
This should not come as a surprise. Dynare must know which variables are
observable for the estimation procedure. NOTE! These variables must be
available in the data ﬁle, as explained in section 5.7 below. For the moment,
we write:
varobs y;
5.5 Specifying the steady state
Before Dynare estimates a model, it ﬁrst linearizes it around a steady state.
Thus, a steady state must exist for the model and although Dynare can calcu
late it, we must give it a hand by declaring approximate values for the steady
state. This is just as explained in details and according to the same syntax
outlined in chapter 3, covering the initval, steady and check commands.
In fact, as this chapter uses the same model as that outlined in chapter 3, the
steady state block will look exactly the same.
TIP! During estimation, in ﬁnding the posterior mode, Dynare recalcu
lates the steady state of the model at each iteration of the optimization rou
tine (more on this later), based on the newest round of parameters available.
Thus, by providing approximate initial values and relying solely on the built
in Dynare algorithm to ﬁnd the steady state (a numerical procedure), you will
signiﬁcantly slow down the computation of the posterior mode. Dynare will
end up spending 60 to 70% of the time recalculating steady states. It is much
more eﬃcient to write an external Matlab steady state ﬁle and let Dynare
use that ﬁle to ﬁnd the steady state of your model by algebraic procedure. For
more details on writing an external Matlab ﬁle to ﬁnd your model’s steady
state, please refer to section 3.6.3 of chapter 3.
5.6 Declaring priors
Priors play an important role in Bayesian estimation and consequently de
serve a central role in the speciﬁcation of the .mod ﬁle. Priors, in Bayesian
estimation, are declared as a distribution. The general syntax to introduce
priors in Dynare is the following:
50 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
estimated params;
PARAMETER NAME, PRIOR SHAPE, PRIOR MEAN, PRIOR STANDARD ERROR [, PRIOR
3
rd
PARAMETER] [,PRIOR 4
th
PARAMETER] ;
end;
where the following table deﬁnes each term more clearly
PRIOR SHAPE Corresponding distribution Range
NORMAL PDF N(µ, σ) R
GAMMA PDF G
2
(µ, σ, p
3
) [p
3
, +∞)
BETA PDF B(µ, σ, p
3
, p
4
) [p
3
, p
4
]
INV GAMMA PDF IG
1
(µ, σ) R
+
UNIFORM PDF U(p
3
, p
4
) [p
3
, p
4
]
where µ is the PRIOR MEAN, σ is the PRIOR STANDARD ERROR, p
3
is the PRIOR
3
rd
PARAMETER (whose default is 0) and p
4
is the PRIOR 4
th
PARAMETER (whose
default is 1). TIP! When specifying a uniform distribution between 0 and 1 as
a prior for a parameter, say α, you therefore have to put two empty spaces for
parameters µ and σ, and then specify parameters p3 and p4, since the uniform
distribution only takes p3 and p4 as arguments. For instance, you would write
alpha, uniform pdf, , , 0,1;
For a more complete review of all possible options for declaring priors, as
well as the syntax to declare priors for maximum likelihood estimation (not
Bayesian), see the Reference Manual. Note also that if some parameters in a
model are calibrated and are not to be estimated, you should declare them as
such, by using the parameters command and its related syntax, as explained
in chapter 3.
TIP! Choosing the appropriate prior for your parameters is a tricky, yet
very important endeavor. It is worth spending time on your choice of priors
and to test the robustness of your results to your priors. Some considerations
may prove helpful. First, think about the domain of your prior over each pa
rameter. Should it be bounded? Should it be opened on either or both sides?
Remember also that if you specify a probability of zero over a certain domain
in your prior, you will necessarily also ﬁnd a probability of zero in your pos
terior distribution. Then, think about the shape of your prior distribution.
Should it be symmetric? Skewed? If so, on which side? You may also go
one step further and build a distribution for each of your parameters in your
mind. Ask yourself, for instance, what is the probability that your parameter
is bigger than a certain value, and repeat the exercise by incrementally de
creasing that value. You can then pick the standard distribution that best ﬁts
5.6. DECLARING PRIORS 51
your perceived distribution. Finally, instead of describing here the shapes and
properties of each standard distribution available in Dynare, you are instead
encouraged to visualize these distributions yourself, either in a statistics book
or on the Web.
TIP! It may at times be desirable to estimate a transformation of a pa
rameter appearing in the model, rather than the parameter itself. In such a
case, it is possible to declare the parameter to be estimated in the parameters
statement and to deﬁne the transformation at the top of the model section,
as a Matlab expression, by adding a pound sign (#) at the beginning of the
corresponding line. For example, you may ﬁnd it easier to deﬁne a prior over
the discount factor, β, than its inverse which often shows up in Euler equa
tions. Thus you would write:
model;
# sig = 1/bet;
c = sig*c(+1)*mpk;
end;
estimated params;
bet,normal pdf,1,0.05;
end;
TIP! Finally, another useful command to use is the estimated params init
command which declares numerical initial values for the optimizer when these
are diﬀerent from the prior mean. This is especially useful when redoing an
estimation  if the optimizer got stuck the ﬁrst time around, or needing a
greater number of draws in the MetropolisHastings algorithm  and wanting
to enter the posterior mode as initial values for the parameters instead of a
prior. The Reference Manual gives more details as to the exact syntax of this
command.
Coming back to our basic example, we would write:
estimated params;
alpha, beta pdf, 0.35, 0.02;
beta, beta pdf, 0.99, 0.002;
delta, beta pdf, 0.025, 0.003;
psi, gamma pdf, 1.75, 0.02;
rho, beta pdf, 0.95, 0.05;
epsilon, gamma pdf, 10, 0.003;
stderr e, inv gamma pdf, 0.01, inf;
end;
52 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
5.7 Launching the estimation
To ask Dynare to estimate a model, all that is necessary is to add the com
mand estimation at the end of the .mod ﬁle. Easy enough. But the real
complexity comes from the options available for the command (to be entered
in parentheses and sequentially, separated by commas, after the command
estimation). Below, we list the most common and useful options, and en
courage you to view the Reference Manual for a complete list.
1. dataﬁle = FILENAME: the dataﬁle (a .m ﬁle, a .mat ﬁle, or an .xls
ﬁle). Note that observations do not need to show up in any order, but
vectors of observations need to be named with the same names as those
in var obs. In Excel ﬁles, for instance, observations could be ordered
in columns, and variable names would show up in the ﬁrst cell of each
column.
2. nobs = INTEGER: the number of observations to be used (default: all
observations in the ﬁle)
3. ﬁrst obs = INTEGER: the number of the ﬁrst observation to be used
(default = 1). This is useful when running loops, or instance, to divide
the observations into subperiods.
4. preﬁlter = 1: the estimation procedure demeans the data (default=0,
no preﬁltering). This is useful if model variables are in deviations from
steady state, for instance, and therefore have zero mean. Demeaning the
observations would also impose a zero mean on the observed variables.
5. nograph: no graphs should be plotted.
6. conf sig = {INTEGER — DOUBLE }: the level for the conﬁdence in
tervals reported in the results (default = 0.90)
7. mh replic = INTEGER: number of replication for Metropolis Hasting
algorithm. For the time being, mh replic should be larger than 1200
(default = 20000)
8. mh nblocks = INTEGER: number of parallel chains for Metropolis Hast
ing algorithm (default = 2). Despite this low default value, it is advisable
to work with a higher value, such as 5 or more. This improves the com
putation of between group variance of the parameter means, one of the
key criteria to evaluate the eﬃciency of the MetropolisHastings to eval
uate the posterior distribution. More details on this subject appear in
Chapter 6.
5.7. LAUNCHING THE ESTIMATION 53
9. mh drop = DOUBLE: the fraction of initially generated parameter vec
tors to be dropped before using posterior simulations (default = 0.5; this
means that the ﬁrst half of the draws from the MetropolisHastings are
discarded).
10. mh jscale = DOUBLE: the scale to be used for the jumping distribu
tion in MH algorithm. The default value is rarely satisfactory. This
option must be tuned to obtain, ideally, an acceptance rate of 25% in
the Metropolis Hastings algorithm (default = 0.2). The idea is not to
reject or accept too often a candidate parameter; the literature has set
tled on a value of between 0.2 and 0.4. If the acceptance rate were too
high, your MetropolisHastings iterations would never visit the tails of a
distribution, while if it were too low, the iterations would get stuck in a
subspace of the parameter range. Note that the acceptance rate drops if
you increase the scale used in the jumping distribution and vice a versa.
11. mh init scale=DOUBLE: the scale to be used for drawing the initial
value of the MetropolisHastings chain (default=2*mh jscale). The idea
here is to draw initial values from a stretched out distribution in order
to maximize the chances of these values not being too close together,
which would defeat the purpose of running several blocks of Metropolis
Hastings chains.
12. mode ﬁle=FILENAME: name of the ﬁle containing previous value for
the mode. When computing the mode, Dynare stores the mode (xparam1)
and the hessian (hh) in a ﬁle called MODEL NAME mode. This is a
particularly helpful option to speed up the estimation process if you have
already undertaken initial estimations and have values of the posterior
mode.
13. mode compute=INTEGER: speciﬁes the optimizer for the mode com
putation.
0: the mode isn’t computed. mode ﬁle must be speciﬁed
1: uses Matlab fmincon (see the Reference Manual to set options
for this command).
2: uses Lester Ingber’s Adaptive Simulated Annealing.
3: uses Matlab fminunc.
4 (default): uses Chris Sim’s csminwel.
14. mode check: when mode check is set, Dynare plots the minus of the
posterior density for values around the computed mode for each esti
mated parameter in turn. This is helpful to diagnose problems with the
optimizer. A clear indication of a problem would be that the mode is
not at the trough (bottom of the minus) of the posterior distribution.
54 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
15. load mh ﬁle: when load mh ﬁle is declared, Dynare adds to previous
MetropolisHastings simulations instead of starting from scratch. Again,
this is a useful option to speed up the process of estimation.
16. nodiagnostic: doesn’t compute the convergence diagnostics for Metropolis
Hastings (default: diagnostics are computed and displayed). Actually
seeing if the various blocks of MetropolisHastings runs converge is a
powerful and useful option to build conﬁdence in your model estima
tion. More details on these diagnostics are given in Chapter 6.
17. bayesian irf: triggers the computation of the posterior distribution of im
pulse response functions (IRFs). The length of the IRFs are controlled
by the irf option, as speciﬁed in chapter 3 when discussing the options for
stoch simul. To build the posterior distribution of the IRFs, Dynare
pulls parameter and shock values from the corresponding estimated dis
tributions and, for each set of draws, generates an IRF. Repeating this
process often enough generates a distribution of IRFs. TIP! If you stop
the estimation procedure after calculating the posterior mode, or carry
out maximum likelihood estimation, only the corresponding parameter
estimates will be used to generate the IRFs. If you instead carry out
a full MetropolisHastings estimation, on the other hand, the IRFs will
use the parameters the posterior distributions, including the variance of
the shocks.
18. All options available for stoch simul can simply be added to the above
options, separated by commas. To view a list of these options, either
see the Reference Manual or section 3.8 of chapter 3.
19. moments varendo: triggers the computation of the posterior distribution
of the theoretical moments of the endogenous variables as in stoch simul
(the posterior distribution of the variance decomposition is also in
cluded). ** will be implemented shortly  if not already  in Dynare
version 4.
20. ﬁltered vars: triggers the computation of the posterior distribution of
ﬁltered endogenous variables and shocks. See the note below on the
diﬀerence between ﬁltered and smoothed shocks. ** will be implemented
shortly  if not already  in Dynare version 4.
21. smoother: triggers the computation of the posterior distribution of smoothed
endogenous variables and shocks. Smoothed shocks are a reconstruction
of the values of unobserved shocks over the sample, using all the informa
tion contained in the sample of observations. Filtered shocks, instead,
are built only based on knowing past information. To calculate one pe
riod ahead prediction errors, for instance, you should use ﬁltered, not
smoothed variables.
5.8. THE COMPLETE .MOD FILE 55
22. forecast = INTEGER: computes the posterior distribution of a forecast
on INTEGER periods after the end of the sample used in estimation.
The corresponding graph includes one conﬁdence interval describing un
certainty due to parameters and one conﬁdence interval describing un
certainty due to parameters and future shocks. Note that Dynare cannot
forecast out of the posterior mode. You need to run MetropolisHastings
iterations before being able to run forecasts on an estimated model. Fi
nally, running a forecast is very similar to an IRF, as in bayesian irf,
except that the forecast does not begin at a steady state, but simply
at the point corresponding to the last set of observations. The goal
of undertaking a forecast is to see how the system returns to steady
state from this starting point. Of course, as observation do not exist
for all variables, those necessary are reconstructed by sampling out of
the posterior distribution of parameters. Again, repeating this step of
ten enough yields a posterior distribution of the forecast. ** will be
implemented shortly  if not already  in Dynare version 4.
TIP! Before launching estimation it is a good idea to make sure that your
model is correctly declared, that a steady state exists and that it can be sim
ulated for at least one set of parameter values. You may therefore want to
create a test version of your .mod ﬁle. In this test ﬁle, you would comment
out or erase the commands related to estimation, remove the prior estimates
for parameter values and replace them with actual parameter values in the
preamble, remove any nonstationary variables from your model, add a shocks
block, make sure you have steady and possibly check following the initval
block if you do not have exact steady state values and run a simulation using
stoch simul at the end of your .mod ﬁle. Details on model solution and sim
ulation can be found in Chapter 3.
Finally, coming back to our example, we could choose a standard option:
estimation(datafile=simuldataRBC,nobs=200,first obs=500,
mh replic=2000,mh nblocks=2,mh drop=0.45,mh jscale=0.8,
mode compute=6);
This ends our description of the .mod ﬁle.
5.8 The complete .mod ﬁle
To summarize and to get a complete perspective on our work so far, here is
the complete .mod ﬁle for the estimation of our very basic model. You can
ﬁnd the corresponding ﬁle in the models folder under UserGuide in your in
stallation of Dynare. The ﬁle is called RBC Est.mod.
56 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
var y c k i l y l w r z;
varexo e;
parameters beta psi delta alpha rho epsilon;
model;
(1/c) = beta*(1/c(+1))*(1+r(+1)delta);
psi*c/(1l) = w;
c+i = y;
y = (k(1)^alpha)*(exp(z)*l)^(1alpha);
w = y*((epsilon1)/epsilon)*(1alpha)/l;
r = y*((epsilon1)/epsilon)*alpha/k(1);
i = k(1delta)*k(1);
y l = y/l;
z = rho*z(1)+e;
end;
varobs y;
initval;
k = 9;
c = 0.7;
l = 0.3;
w = 2.0;
r = 0;
z = 0;
e = 0;
end;
steady;
check;
estimated params;
alpha, beta pdf, 0.35, 0.02;
beta, beta pdf, 0.99, 0.002;
delta, beta pdf, 0.025, 0.003;
psi, gamma pdf, 1.75, 0.02;
rho, beta pdf, 0.95, 0.05;
epsilon, gamma pdf, 10, 0.003;
stderr e, inv gamma pdf, 0.01, inf;
end;
estimation(datafile=simuldataRBC,nobs=200,first obs=500,
mh replic=2000,mh nblocks=2,mh drop=0.45,mh jscale=0.8,
mode compute=6);
5.9. INTERPRETING OUTPUT 57
5.9 Interpreting output
As in the case of model solution and simulation, Dynare returns both tabular
and graphical output. On the basis of the options entered in the example
.mod ﬁle above, Dynare will display the following results.
5.9.1 Tabular results
The ﬁrst results to be displayed (and calculated from a chronological stand
point) are the steady state results. Note the dummy values of 1 for the non
stationary variables Y obs and P obs. These results are followed by the eigen
values of the system, presented in the order in which the endogenous variables
are declared at the beginning of the .mod ﬁle. The table of eigenvalues is
completed with a statement about the BlanchardKahn condition being met
 hopefully!
The next set of results are for the numerical iterations necessary to ﬁnd
the posterior mode, as explained in more details in Chapter 6. The improve
ment from one iteration to the next reaches zero, Dynare give the value of
the objective function (the posterior Kernel) at the mode and displays two
important table summarizing results from posterior maximization.
The ﬁrst table summarizes results for parameter values. It includes: prior
means, posterior mode, standard deviation and tstat of the mode (based on
the assumption of a Normal, probably erroneous when undertaking Bayesian
estimation, as opposed to standard maximum likelihood), as well as the prior
distribution and standard deviation (pstdev). It is followed by a second table
summarizing the same results for the shocks. It may be entirely possible that
you get an inﬁnite value for a standard deviation, this is simply the limit case
of the inverse gamma distribution.
5.9.2 Graphical results
** corresponding graphs will be reproduced below.
The ﬁrst ﬁgure comes up soon after launching Dynare as little computa
tion is necessary to generate it. The ﬁgure returns a graphical representation
of the priors for each parameter of interest.
58 CHAPTER 5. ESTIMATING DSGE MODELS  BASICS
The second set of ﬁgures displays “MCMC univariate diagnostics”, where
MCMC stands for Monte Carlo Markov Chains. This is the main source
of feedback to gain conﬁdence, or spot a problem, with results. Recall that
Dynare completes several runs of MetropolisHastings simulations (as many as
determined in the option mh nblocks, each time starting from a diﬀerent ini
tial value). If the results from one chain are sensible, and the optimizer did not
get stuck in an odd area of the parameter subspace, two things should happen.
First, results within any of the however many iterations of MetropolisHastings
simulation should be similar. And second, results between the various chains
should be close. This is the idea of what the MCMC diagnostics track.
More speciﬁcally, the red and blue lines on the charts represent speciﬁc
measures of the parameter vectors both within and between chains. For the
results to be sensible, these should be relatively constant (although there
will always be some variation) and they should converge. Dynare reports
three measures: “interval”, being constructed from an 80% conﬁdence inter
val around the parameter mean, “m2”, being a measure of the variance and
“m3” based on third moments. In each case, Dynare reports both the within
and the between chains measures. The ﬁgure entitled “multivariate diagnos
tic” presents results of the same nature, except that they reﬂect an aggregate
measure based on the eigenvalues of the variancecovariance matrix of each
parameter.
In our example above, you can tell that indeed, we obtain convergence
and relative stability in all measures of the parameter moments. Note that
the horizontal axis represents the number of MetropolisHastings iterations
that have been undertaken, and the vertical axis the measure of the parame
ter moments, with the ﬁrst, corresponding to the measure at the initial value
of the MetropolisHastings iterations.
TIP! If the plotted moments are highly unstable or do not converge, you
may have a problem of poor priors. It is advisable to redo the estimation with
diﬀerent priors. If you have trouble coming up with a new prior, try starting
with a uniform and relatively wide prior and see where the data leads the
posterior distribution. Another approach is to undertake a greater number of
MetropolisHastings simulations.
The ﬁrst to last ﬁgure  ﬁgure 6 in our example  displays the most inter
esting set of results, towards which most of the computations undertaken by
Dynare are directed: the posterior distribution. In fact, the ﬁgure compares
the posterior to the prior distribution (black vs. grey lines). In addition,
on the posterior distribution, Dynare plots a green line which represents the
posterior mode. These allow you to make statements about your data other
than simply concerning the mean and variance of the parameters; you can also
5.9. INTERPRETING OUTPUT 59
discuss the probability that your parameter is larger or smaller than a certain
value.
TIP! These graphs are of course especially relevant and present key results,
but they can also serve as tools to detect problems or build additional conﬁ
dence in your results. First, the prior and the posterior distributions should
not be excessively diﬀerent. Second, the posterior distributions should be close
to normal, or at least not display a shape that is clearly nonnormal. Third,
the green mode (calculated from the numerical optimization of the posterior
kernel) should not be too far away from the mode of the posterior distribution.
If not, it is advisable to undertake a greater number of MetropolisHastings
simulations.
The last ﬁgure returns the smoothed estimated shocks in a useful illustra
tion to eyeball the plausibility of the size and frequency of the shocks. The
horizontal axis, in this case, represents the number of periods in the sample.
One thing to check is the fact that shocks should be centered around zero.
That is indeed the case for our example.
Chapter 6
Estimating DSGE models 
advanced topics
This chapter focusses on advanced topics and features of Dynare in the area of
model estimation. The chapter begins by presenting a more complex example
than the one used for illustration purposes in chapter 5. The goal is to show
how Dynare would be used in the more “realistic” setting of reproducing a
recent academic paper. The chapter then follows with sections on comparing
models to one another, and then to BVARs, and ends with a table summariz
ing where output series are stored and how these can be retrieved.
6.1 Alternative and nonstationary example
The example provided in chapter 5 is really only useful for illustration pur
poses. So we thought you would enjoy (and continue learning from!) a more
realistic example which reproduces the work in a recent  and highly regarded
 academic paper. The example shows how to use Dynare in a more realistic
setting, while emphasizing techniques to deal with nonstationary observations
and stochastic trends in dynamics.
6.1.1 Introducing the example
The example is drawn from Schorfheide (2000). This ﬁrst section introduces
the model, its basic intuitions and equations. We will then see in subsequent
sections how to estimate it using Dynare. Note that the original paper by
Schorfheide mainly focusses on estimation methodologies, diﬃculties and so
lutions, with a special interest in model comparison, while the mathematics
and economic intuitions of the model it evaluates are drawn from Nason and
Cogley (1994). That paper should serve as a helpful reference if anything is
61
62 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
Figure 6.1: Continuous lines show the circulation of nominal funds, while
dashed lines show the ﬂow of real variables.
left unclear in the description below.
In essence, the model studied by Schorfheide (2000) is one of cash in ad
vance (CIA). The goal of the paper is to estimate the model using Bayesian
techniques, while observing only output and inﬂation. In the model, there are
several markets and actors to keep track of. So to clarify things, ﬁgure 6.1.1
sketches the main dynamics of the model. You may want to refer back to the
ﬁgure as you read through the following sections.
The economy is made up of three central agents and one secondary agent:
households, ﬁrms and banks (representing the ﬁnancial sector), and a mon
etary authority which plays a minor role. Households maximize their utility
function which depends on consumption, C
t
, and hours worked, H
t
, while
deciding how much money to hold next period in cash, M
t+1
and how much
to deposit at the bank, D
t
, in order to earn R
H,t
− 1 interest. Households
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 63
therefore solve the problem
max
{C
t
,H
t
,M
t+1
,D
t
}
E
0
_
∞
t=0
β
t
[(1 −φ) ln C
t
+φln(1 −H
t
)]
¸
s.t. P
t
C
t
≤ M
t
−D
t
+W
t
H
t
0 ≤ D
t
M
t+1
= (M
t
−D
t
+W
t
H
t
−P
t
C
t
) +R
H,t
D
t
+F
t
+B
t
where the second equation spells out the cash in advance constraint including
wage revenues, the third the inability to borrow from the bank and the fourth
the intertemporal budget constraint emphasizing that households accumulate
the money that remains after bank deposits and purchases on goods are de
ducted from total inﬂows made up of the money they receive from last period’s
cash balances, wages, interests, as well as dividends from ﬁrms, F
t
, and from
banks, B
t
, which in both cases are made up of net cash inﬂows deﬁned below.
Banks, on their end, receive cash deposits from households and a cash
injection, X
t
from the central bank (which equals the net change in nominal
money balances, M
t+1
− M
t
). It uses these funds to disburse loans to ﬁrms,
L
t
, on which they make a net return of R
F,t
− 1. Of course, banks are con
strained in their loans by a credit market equilibrium condition L
t
≤ X
t
+D
t
.
Finally, bank dividends, B
t
are simply equal to D
t
+R
F,t
L
t
−R
H,t
D
t
−L
t
+X
t
.
Finally, ﬁrms maximize the net present value of future dividends (dis
counted by the marginal utility of consumption, since they are owned by
households) by choosing dividends, next period’s capital stock, K
t+1
, labor
demand, N
t
, and loans. Its problem is summarized by
max
{F
t
,K
t+1
,N
t
,L
t
}
E
0
_
∞
t=0
β
t+1 F
t
C
t+1
P
t+1
_
s.t. F
t
≤ L
t
+P
t
_
K
α
t
(A
t
N
t
)
1−α
−K
t+1
+ (1 −δ)K
t
¸
−W
t
N
t
−L
t
R
F,t
W
t
N
t
≤ L
t
where the second equation makes use of the production function Y
t
= K
α
t
(A
t
N
t
)
1−α
and the real aggregate accounting constraint (goods market equilibrium) C
t
+I
t
= Y
t
,
where I
t
= K
t+1
− (1 − δ)K
t
, and where δ is the rate of depreciation. Note
that it is the ﬁrms that engage in investment in this model, by trading oﬀ
investment for dividends to consumers. The third equation simply speciﬁes
that bank loans are used to pay for wage costs.
To close the model, we add the usual labor and money market equilib
rium equations, H
t
= N
t
and P
t
C
t
= M
t
+ X
t
, as well as the condition that
R
H,t
= R
F,t
due to the equal risk proﬁles of the loans.
64 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
More importantly, we add a stochastic elements to the model. The model
allows for two sources of perturbations, one real, aﬀecting technology and one
nominal, aﬀecting the money stock. These important equations are
ln A
t
= γ + ln A
t−1
+
A,t
,
A,t
∼ N(0, σ
2
A
)
and
ln m
t
= (1 −ρ) ln m
∗
+ρ ln m
t−1
+
M,t
,
M,t
∼ N(0, σ
2
M
)
where m
t
≡ M
T+1
/M
t
is the growth rate of the money stock. Note that theses
expressions for trends are not written in the most straightforward manner nor
very consistently. But we reproduced them nevertheless to make it easier to
compare this example to the original paper.
The ﬁrst equation is therefore a unit root with drift in the log of tech
nology, and the second an autoregressive stationary process in the growth
rate of money, but an AR(2) with a unit root in the log of the level of
money. This can be seen from the deﬁnition of m
t
which can be rewritten
as ln M
t+1
= ln M
t
+ ln m
t
.
1
When the above functions are maximized, we obtain the following set of
ﬁrst order and equilibrium conditions. We will not dwell on the derivations
here, to save space, but encourage you to browse Nason and Cogley (1994) for
additional details. We nonetheless give a brief intuitive explanation of each
1
Alternatively, we could have written the AR(2) process in state space form and realized
that the system has an eigenvalue of one. Otherwise said, one is a root of the second order
autoregressive lag polynomial. As usual, if the logs of a variable are speciﬁed to follow a unit
root process, the rate of growth of the series is a stationary stochastic process; see Hamilton
(1994), chapter 15, for details.
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 65
equation. The system comes down to
E
t
_
−
´
P
t
/
_
´
C
t+1
´
P
t+1
m
t
_
_
= βe
−α(γ+
A,t+1
)
P
t+1
_
α
´
K
α−1
t
N
1−α
t+1
+ (1 −δ)
_
/
_
´c
t+2
´
P
t+2
m
t+1
_
_
´
W
t
=
´
L
t
/N
t
φ
1 −φ
_
´
C
t
´
P
t
/ (1 −N
t
)
_
=
´
L
t
/N
t
R
t
= (1 −α)
´
P
t
e
−α(γ+
A,t+1
)
´
K
α
t−1
N
−α
t
/
´
W
t
_
´
C
t
´
P
t
_
−1
= β
_
(1 −α)
´
P
t
e
−α(γ+
A,t+1
)
´
K
α
t−1
N
1−α
t
_
×E
t
_
´
L
t
m
t
´
C
t+1
´
P
t+1
_
−1
´
C
t
+
´
K
t
= e
−α(γ+
A,t
)
´
K
α
t−1
N
1−α
+ (1 −δ)e
−(γ+
A,t
)
´
K
t−1
´
P
t
´
C = m
t
m
t
−1 +
´
D
t
=
´
L
t
´
Y
t
=
´
K
α
t−1
N
1−α
e
−α(γ+
A,t
)
ln(m
t
) = (1 −ρ) ln(m
) +ρ ln(m
t−1
) +
M,t
A
t
A
t−1
≡ dA
t
= exp(γ +
A,t
)
Y
t
/Y
t−1
= e
γ+
A,t ´
Y
t
/
´
Y
t−1
P
t
/P
t−1
= (
´
P
t
/
´
P
t−1
)(m
t−1
/e
γ+
A,t
)
where, importantly, hats over variables no longer mean deviations from steady
state, but instead represent variables that have been made stationary. We
come back to this important topic in details in section 6.1.3 below. For now,
we pause a moment to give some intuition for the above equations. In order,
these equations correspond to:
1. The Euler equation in the goods market, representing the tradeoﬀ to the
economy of moving consumption goods across time.
2. The ﬁrms’ borrowing constraint, also aﬀecting labor demand, as ﬁrms
use borrowed funds to pay for labor input.
3. The intertemporal labor market optimality condition, linking labor sup
ply, labor demand, and the marginal rate of substitution between con
sumption and leisure.
4. The equilibrium interest rate in which the marginal revenue product of
labor equals the cost of borrowing to pay for that additional unit of
labor.
66 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
5. The Euler equation in the credit market, which ensures that giving up
one unit of consumption today for additional savings equals the net
present value of future consumption.
6. The aggregate resource constraint.
7. The money market equilibrium condition equating nominal consumption
demand to money demand to money supply to current nominal balances
plus money injection.
8. The credit market equilibrium condition.
9. The production function.
10. The stochastic process for money growth.
11. The stochastic process for technology.
12. The relationship between observable variables and stationary variables;
more details on these last two equations appear in the following section.
6.1.2 Declaring variables and parameters
This block of the .mod ﬁle follows the usual conventions and would look like:
var m P c e W R k d n l Y obs P obs y dA;
varexo e a e m;
parameters alp, bet, gam, mst, rho, psi, del;
where the choice of upper and lower case letters is not signiﬁcant, the ﬁrst set
of endogenous variables, up to l, are as speciﬁed in the model setup above,
and where the last ﬁve variables are deﬁned and explained in more details in
the section below on declaring the model in Dynare. The exogenous variables
are as expected and concern the shocks to the evolution of technology and
money balances.
6.1.3 The origin of nonstationarity
The problem of nonstationarity comes from having stochastic trends in tech
nology and money. The nonstationarity comes out clearly when attempting
to solve the model for a steady state and realizing it does not have one. It can
be shown that when shocks are null, real variables grow with A
t
(except for
labor, N
t
, which is stationary as there is no population growth), nominal vari
ables grow with M
t
and prices with M
t
/A
t
. Detrending therefore involves
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 67
the following operations (where hats over variables represent stationary vari
ables): for real variables, ˆ q
t
= q
t
/A
t
, where q
t
= [y
t
, c
t
, i
t
, k
t+1
]. For nominal
variables,
ˆ
Q
t
= Q
t
/M
t
, where Q
t
= [d
t
, l
t
, W
t
]. And for prices,
ˆ
P
t
= P
t
·A
t
/M
t
.
6.1.4 Stationarizing variables
Let’s illustrate this transformation on output, and leave the transformations
of the remaining equations as an exercise, if you wish (Nason and Cogley
(1994) includes more details on the transformations of each equation). We
stationarize output by dividing its real variables (except for labor) by A
t
. We
deﬁne
´
Y
t
to equal Y
t
/A
t
and
´
K
t
as K
t
/A
t
. NOTE! Recall from section 3.5 in
chapter 3), that in Dynare variables take the time subscript of the period in
which they are decided (in the case of the capital stock, today’s capital stock
is a result of yesterday’s decision). Thus, in the output equation, we should
actually work with
´
K
t−1
= K
t−1
/A
t−1
. The resulting equation made up of
stationary variables is
Y
t
A
t
=
_
K
t−1
A
t−1
_
α
A
1−α
t
N
1−α
t
A
−1
t
A
α
t−1
´
Y
t
=
´
K
α
t−1
N
1−α
t
_
A
t
A
t−1
_
−α
=
´
K
α
t−1
N
1−α
t
exp(−α(γ +
A,t
))
where we go from the second to the third line by taking the exponential of
both sides of the equation of motion of technology.
The above is the equation we retain for the .mod ﬁle of Dynare into which
we enter:
y=k(1)^alp*n^(1alp)*exp(alp*(gam+e a))
The other equations are entered into the .mod ﬁle after transforming them
in exactly the same way as the one above. A ﬁnal transformation to consider,
that turns out to be useful since we often deal with the growth rate of tech
nology, is to deﬁne
dA = exp(gam+e a)
by simply taking the exponential of both sides of the stochastic process of
technology deﬁned in the model setup above.
68 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
6.1.5 Linking stationary variables to the data
And ﬁnally, we must make a decision as to our nonstationary observa
tions. We could simply stationarize them by working with rates of growth
(which we know are constant). In the case of output, the observable variable
would become Y
t
/Y
t−1
. We would then have to relate this observable, call it
gy obs, to our (stationary) model’s variables
´
Y
t
by using the deﬁnition that
´
Y
t
≡ Y
t
/A
t
. Thus, we add to the model block of the .mod ﬁle:
gy obs = dA*y/y(1);
where, the y of the .mod ﬁle are the stationary
´
Y
t
.
But, we could also work with nonstationary data in levels. This
complicates things somewhat, but illustrates several features of Dynare worth
highlighting; we therefore follow this path in the remainder of the example.
The result is not very diﬀerent, though, from what we just saw above. The
goal is to add a line to the model block of our .mod ﬁle that relates the non
stationary observables, call them Y
obs
, to our stationary output,
´
Y
t
. We could
simply write Y
obs
=
´
Y
t
A
t
. But since we don’t have an A
t
variable, but just a
dA
t
, we wewrite the above relationship in ratios. To the .mod ﬁle, we there
fore add:
Y obs/Y obs(1) = dA*y/y(1);
We of course do the same for prices, our other observable variable, except
that we use the relationship P
obs
=
´
P
t
M
t
/A
t
as noted earlier. The details
of the correct transformations for prices are left as an exercise and can be
checked against the results below.
6.1.6 The resulting model block of the .mod ﬁle
model;
dA = exp(gam+e a);
log(m) = (1rho)*log(mst) + rho*log(m(1))+e m;
P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(alp*(gam+log(e(+1))))*k^(alp1)
*n(+1)^(1alp)+(1del)*exp((gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
W = l/n;
(psi/(1psi))*(c*P/(1n))+l/n = 0;
R = P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(alp)/W;
1/(c*P)bet*P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(1alp)/
(m*l*c(+1)*P(+1)) = 0;
c+k = exp(alp*(gam+e a))*k(1)^alp*n^(1alp)+(1del)
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 69
*exp((gam+e a))*k(1);
P*c = m;
m1+d = l;
e = exp(e a);
y = k(1)^alp*n^(1alp)*exp(alp*(gam+e a));
Y obs/Y obs(1) = dA*y/y(1);
P obs/P obs(1) = (p/p(1))*m(1)/dA;
end;
where, of course, the input conventions, such as ending lines with semicolons
and indicating the timing of variables in parentheses, are the same as those
listed in chapter 3.
TIP! In the above model block, notice that what we have done is in fact
relegated the nonstationarity of the model to just the last two equations,
concerning the observables which are, after all, nonstationary. The problem
that arises, though, is that we cannot linearize the above system in levels, as
the last two equations don’t have a steady state. If we ﬁrst take logs, though,
they become linear and it doesn’t matter anymore where we calculate their
derivative when taking a Taylor expansion of all the equations in the system.
Thus, when dealing with nonstationary observations, you must log
linearize your model (and not just linearize it); this is a point to which we
will return later.
6.1.7 Declaring observable variables
We begin by declaring which of our model’s variables are observables. In our
.mod ﬁle we write
varobs P obs Y obs;
to specify that our observable variables are indeed P obs and Y obs as noted
in the section above. NOTE! Recall from earlier that the number of observed
variables must be smaller or equal to the number of shocks such that the model
be estimated. If this is not the case, you should add measurement shocks to
your model where you deem most appropriate.
6.1.8 Declaring trends in observable variables
Recall that we decided to work with the nonstationary observable variables
in levels. Both output and prices exhibit stochastic trends. This can be seen
explicitly by taking the diﬀerence of logs of output and prices to compute
growth rates. In the case of output, we make use of the usual (by now!)
70 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
relationship Y
t
=
´
Y
t
· A
t
. Taking logs of both sides and subtracting the same
equation scrolled back one period, we ﬁnd:
∆ln Y
t
= ∆ln
´
Y
t
+γ +
A,t
emphasizing clearly the drift term γ, whereas we know ∆ln
´
Y
t
is stationary in
steady state.
In the case of prices, we apply the same manipulations to show that:
∆ln P
t
= ∆ln
´
P
t
+ ln m
t−1
−γ −
A,t
Note from the original equation of motion of ln m
t
that in steady state,
ln m
t
= ln m
∗
, so that the drift terms in the above equation are ln m
∗
−γ.
2
In Dynare, any trends, whether deterministic or stochastic (the drift term)
must be declared up front. In the case of our example, we therefore write (in
a somewhat cumbersome manner)
observation trends;
P obs (log(mst)gam);
Y obs (gam);
end;
In general, the command observation trends speciﬁes linear trends as a
function of model parameters for the observed variables in the model.
6.1.9 Declaring unit roots in observable variables
And ﬁnally, since P obs and Y obs inherit the unit root characteristics of their
driving variables, technology and money, we must tell Dynare to use a diﬀuse
prior (inﬁnite variance) for their initialization in the Kalman ﬁlter. Note that
for stationary variables, the unconditional covariance matrix of these variables
is used for initialization. The algorithm to compute a true diﬀuse prior is taken
from Durbin and Koopman (2001). To give these instructions to Dynare, we
write in the .mod
unit root vars P obs Y obs;
NOTE! You don’t need to declare unit roots for any nonstationary model.
Unit roots are only related to stochastic trends. You don’t need to use a diﬀuse
2
This can also be see from substituting for ln m
t−1
in the above equation with the
equation of motion of ln m
t
to yield: ∆ln P
t
= ∆ln
P
t
+ln m
∗
+ρ(ln m
t−2
−ln m
∗
) +
M,t
−
γ −
A,t
where all terms on the right hand side are constant, except for ln m
∗
and γ.
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 71
initial condition in the case of a deterministic trend, since the variance is ﬁnite.
6.1.10 Specifying the steady state
Declaring the steady state is just as explained in details and according to
the same syntax explained in chapter 3, covering the initval, steady and
check commands. In chapter 5, section 5.5, we also discussed the usefulness
of providing an external Matlab ﬁle to solve for the steady state. In this
case, you can ﬁnd the corresponding steady state ﬁle in the models folder
under UserGuide. The ﬁle is called fs2000ns steadystate.m. There are some
things to notice. First, the output of the function is the endogenous variables
at steady state, the ys vector. The check=0 limits steady state values to
real numbers. Second, notice the declaration of parameters at the beginning;
intuitive, but tedious... This functionality may be updated in later versions of
Dynare. Third, note that the ﬁle is really only a sequential set of equalities,
deﬁning each variable in terms of parameters or variables solved in the lines
above. So far, nothing has changed with respect to the equivalent ﬁle of
chapter 5. The only novelty is the declaration of the nonstationary variables,
P obs and Y obs which take the value of 1. This is Dynare convention and
must be the case for all your nonstationary variables.
6.1.11 Declaring priors
We expand our .mod ﬁle with the following information:
estimated params;
alp, beta pdf, 0.356, 0.02;
bet, beta pdf, 0.993, 0.002;
gam, normal pdf, 0.0085, 0.003;
mst, normal pdf, 1.0002, 0.007;
rho, beta pdf, 0.129, 0.223;
psi, beta pdf, 0.65, 0.05;
del, beta pdf, 0.01, 0.005;
stderr e a, inv gamma pdf, 0.035449, inf;
stderr e m, inv gamma pdf, 0.008862, inf;
end;
6.1.12 Launching the estimation
We add the following commands to ask Dynare to run a basic estimation of
our model:
72 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
estimation(datafile=fsdat,nobs=192,loglinear,mh replic=2000,
mode compute=6,mh nblocks=2,mh drop=0.45,mh jscale=0.65);
NOTE! As mentioned earlier, we need to instruct Dynare to loglinearize
our model, since it contains nonlinear equations in nonstationary variables.
A simple linearization would fail as these variables do not have a steady state.
Fortunately, taking the log of the equations involving nonstationary variables
does the job of linearizing them.
6.1.13 The complete .mod ﬁle
We have seen each part of the .mod separately; it’s now time to get a picture
of what the complete ﬁle looks like. For convenience, the ﬁle also appears in
the models folder under UserGuide in your Dynare installation. The ﬁle is
called fs2000ns.mod.
var m P c e W R k d n l Y obs P obs y dA;
varexo e a e m;
parameters alp, bet, gam, mst, rho, psi, del;
model;
dA = exp(gam+e a);
log(m) = (1rho)*log(mst) + rho*log(m(1))+e m;
P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(alp*(gam+log(e(+1))))
*k^(alp1)*n(+1)^(1alp)+(1del)
*exp((gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0;
W = l/n;
(psi/(1psi))*(c*P/(1n))+l/n = 0;
R = P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(alp)/W;
1/(c*P)bet*P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(1alp)/
(m*l*c(+1)*P(+1)) = 0;
c+k = exp(alp*(gam+e a))*k(1)^alp*n^(1alp)+(1del)
exp((gam+e a))*k(1);
P*c = m;
m1+d = l;
e = exp(e a);
y = k(1)^alp*n^(1alp)*exp(alp*(gam+e a));
Y obs/Y obs(1) = dA*y/y(1);
P obs/P obs(1) = (p/p(1))*m(1)/dA;
end;
varobs P obs Y obs;
6.1. ALTERNATIVE AND NONSTATIONARY EXAMPLE 73
observation trends;
P obs (log(mst)gam);
Y obs (gam);
end;
unit root vars P obs Y obs;
initval;
k = 6;
m = mst;
P = 2.25;
c = 0.45;
e = 1;
W = 4;
R = 1.02;
d = 0.85;
n = 0.19;
l = 0.86;
y = 0.6;
dA = exp(gam);
end;
// the above is really only useful if you want to do a stoch simul
// of your model, since the estimation will use the Matlab
// steady state file also provided and discussed above.
steady;
estimated params;
alp, beta pdf, 0.356, 0.02;
bet, beta pdf, 0.993, 0.002;
gam, normal pdf, 0.0085, 0.003;
mst, normal pdf, 1.0002, 0.007;
rho, beta pdf, 0.129, 0.223;
psi, beta pdf, 0.65, 0.05;
del, beta pdf, 0.01, 0.005;
stderr e a, inv gamma pdf, 0.035449, inf;
stderr e m, inv gamma pdf, 0.008862, inf;
end;
estimation(datafile=fsdat,nobs=192,loglinear,mh replic=2000,
mode compute=6,mh nblocks=2,mh drop=0.45,mh jscale=0.65);
74 CHAPTER 6. ESTIMATING DSGE MODELS  ADVANCED TOPICS
Figure 6.2: At a high level, there are ﬁve basic steps to translate a model into
Dynare for successful estimation.
6.1.14 Summing it up
The explanations given above of each step necessary to translate the Schorfheide
(2000) example into language that Dynare can understand and process was
quite lengthy and involved a slew of new commands and information. It may
therefore be useful, to gain a “bird’s eyeview” on what we have just accom
plished, and summarize the most important steps at a high level. This is done
in ﬁgure 6.1.14.
6.2 Comparing models based on their posterior
distributions
** TBD
6.3. WHERE IS YOUR OUTPUT STORED? 75
6.3 Where is your output stored?
The output from estimation can be extremely varied, depending on the in
structions you give Dynare. The Reference Manual overviews the complete
set of potential output ﬁles and describes where you can ﬁnd each one.
Chapter 7
Solving DSGE models 
Behind the scenes of Dynare
7.1 Introduction
The aim of this chapter is to peer behind the scenes of Dynare, or under its
hood, to get an idea of the methodologies and algorithms used in its com
putations. Going into details would be beyond the scope of this User Guide
which will instead remain at a high level. What you will ﬁnd below will
either comfort you in realizing that Dynare does what you expected of it 
and what you would have also done if you had had to code it all yourself
(with a little extra time on your hands!), or will spur your curiosity to have
a look at more detailed material. If so, you may want to go through Michel
Juillard’s presentation on solving DSGE models to a ﬁrst and second order
(available on Michel Juillard’s website), or read Collard and Juillard (2001a)
or SchmittGrohe and Uribe (2004) which gives a good overview of the most
recent solution techniques based on perturbation methods. Finally, note that
in this chapter we will focus on stochastic models  which is where the major
complication lies, as explained in section 3.1.1 of chapter 3. For more details
on the NewtonRaphson algorithm used in Dynare to solve deterministic mod
els, see Juillard (1996).
7.2 What is the advantage of a second order
approximation?
As noted in chapter 3 and as will become clear in the section below, lin
earizing a system of equations to the ﬁrst order raises the issue of certainty
equivalence. This is because only the ﬁrst moments of the shocks enter the
linearized equations, and when expectations are taken, they disappear. Thus,
77
78
CHAPTER 7. SOLVING DSGE MODELS  BEHIND THE SCENES OF
DYNARE
unconditional expectations of the endogenous variables are equal to their non
stochastic steady state values.
This may be an acceptable simpliﬁcation to make. But depending on the
context, it may instead be quite misleading. For instance, when using sec
ond order welfare functions to compare policies, you also need second order
approximations of the policy function. Yet more clearly, in the case of asset
pricing models, linearizing to the second order enables you to take risk (or the
variance of shocks) into consideration  a highly desirable modeling feature. It
is therefore very convenient that Dynare allows you to choose between a ﬁrst
or second order linearization of your model in the option of the stoch simul
command.
7.3 How does dynare solve stochastic DSGE
models?
In this section, we shall brieﬂy overview the perturbation methods employed
by Dynare to solve DSGE models to a ﬁrst order approximation. The sec
ond order follows very much the same approach, although at a higher level
of complexity. The summary below is taken mainly from Michel Juillard’s
presentation “Computing ﬁrst order approximations of DSGE models with
Dynare”, which you should read if interested in particular details, especially
regarding second order approximations (available on Michel Juillard’s web
site).
To summarize, a DSGE model is a collection of ﬁrst order and equilibrium
conditions that take the general form:
E
t
{f(y
t+1
, y
t
, y
t−1
, u
t
)} = 0
E(u
t
) = 0
E(u
t
u
t
) = Σ
u
and where:
y : vector of endogenous variables of any dimension
u : vector of exogenous stochastic shocks of any dimension
The solution to this system is a set of equations relating variables in the
current period to the past state of the system and current shocks, that satisfy
the original system. This is what we call the policy function. Sticking to the
above notation, we can write this function as:
y
t
= g(y
t−1
, u
t
)
7.3. HOW DOES DYNARE SOLVE STOCHASTIC DSGE MODELS? 79
Then, it is straightforward to rewrite y
t+1
as
y
t+1
= g(y
t
, u
t+1
)
= g(g(y
t−1
, u
t
), u
t+1
)
We can then deﬁne a new function F, such that:
F(y
t−1
, u
t
, u
t+1
) = f(g(g(y
t−1
, u
t
), u
t+1
), g(y
t−1
, u
t
), y
t−1
, u
t
)
which enables us to rewrite our system in terms of past variables, and current
and future shocks:
E
t
[F(y
t−1
, u
t
, u
t+1
)] = 0
We then venture to linearize this model around a steady state deﬁned as:
f(¯ y, ¯ y, ¯ y, 0) = 0
having the property that:
¯ y = g(¯ y, 0)
The ﬁrst order Taylor expansion around ¯ y yields:
E
t
_
F
(1)
(y
t−1
, u
t
, u
t+1
)
_
=
E
t
_
f(¯ y, ¯ y, ¯ y) +f
y
+
_
g
y
(g
y
ˆ y +g
u
u) +g
u
u
_
+f
y
0
(g
y
ˆ y +g
u
u) +f
y
−
ˆ y +f
u
u
_
= 0
with ˆ y = y
t−1
− ¯ y, u = u
t
, u
= u
t+1
, f
y
+
=
∂f
∂y
t+1
, f
y
0
=
∂f
∂y
t
, f
y
−
=
∂f
∂y
t−1
,
f
u
=
∂f
∂u
t
, g
y
=
∂g
∂y
t−1
, g
u
=
∂g
∂u
t
.
Taking expectations (we’re almost there!):
E
t
_
F
(1)
(y
t−1
, u
t
, u
t+1
)
_
=
f(¯ y, ¯ y, ¯ y) +f
y
+
(g
y
(g
y
ˆ y +g
u
u))
+f
y
0
(g
y
ˆ y +g
u
u) +f
y
−
ˆ y +f
u
u
_
=
_
f
y
+
g
y
g
y
+f
y
0
g
y
+f
y
−
_
ˆ y +
_
f
y
+
g
y
g
u
+f
y
0
g
u
+f
u
_
u
= 0
As you can see, since future shocks only enter with their ﬁrst moments
(which are zero in expectations), they drop out when taking expectations of
the linearized equations. This is technically why certainty equivalence holds
80
CHAPTER 7. SOLVING DSGE MODELS  BEHIND THE SCENES OF
DYNARE
in a system linearized to its ﬁrst order. The second thing to note is that we
have two unknown variables in the above equation: g
y
and g
u
each of which
will help us recover the policy function g.
Since the above equation holds for any ˆ y and any u, each parenthesis must
be null and we can solve each at a time. The ﬁrst, yields a quadratic equation
in g
y
, which we can solve with a series of algebraic trics that are not all imme
diately apparent (but detailed in Michel Juillard’s presentation). Incidentally,
one of the conditions that comes out of the solution of this equation is the
BlanchardKahn condition: there must be as many roots larger than one in
modulus as there are forwardlooking variables in the model. Having recov
ered g
y
, recovering g
u
is then straightforward from the second parenthesis.
Finally, notice that a ﬁrst order linearization of the function g yields:
y
t
= ¯ y +g
y
ˆ y +g
u
u
And now that we have g
y
and g
u
, we have solved for the (approximate) policy
(or decision) function and have succeeded in solving our DSGE model. If we
were interested in impulse response functions, for instance, we would simply
iterate the policy function starting from an initial value given by the steady
state.
The second order solution uses the same “perturbation methods” as above
(the notion of starting from a function you can solve  like a steady state 
and iterating forward), yet applies more complex algebraic techniques to re
cover the various partial derivatives of the policy function. But the general
approach is perfectly isomorphic. Note that in the case of a second order
approximation of a DSGE model, the variance of future shocks remains after
taking expectations of the linearized equations and therefore aﬀects the level
of the resulting policy function.
Chapter 8
Estimating DSGE models 
Behind the scenes of Dynare
This chapter focuses on the theory of Bayesian estimation. It begins by mo
tivating Bayesian estimation by suggesting some arguments in favor of it as
opposed to other forms of model estimation. It then attempts to shed some
light on what goes on in Dynare’s machinery when it estimates DSGE models.
To do so, this section surveys the methodologies adopted for Bayesian estima
tion, including deﬁning what are prior and posterior distributions, using the
Kalman ﬁlter to ﬁnd the likelihood function, estimating the posterior function
thanks to the MetropolisHastings algorithm, and comparing models based on
posterior distributions.
8.1 Advantages of Bayesian estimation
Bayesian estimation is becoming increasingly popular in the ﬁeld of macro
economics. Recent papers have attracted signiﬁcant attention; some of these
include: Schorfheide (2000) which uses Bayesian methods to compare the
ﬁt of two competing DSGE models of consumption, Lubik and Schorfheide
(2003) which investigates whether central banks in small open economies re
spond to exchange rate movements, Smets and Wouters (2003) which ap
plies Bayesian estimation techniques to a model of the Eurozone, Ireland
(2004) which emphasizes instead maximum likelihood estimation, Fernandez
Villaverde and RubioRamirez (2004) which reviews the econometric proper
ties of Bayesian estimators and compare estimation results with maximum
likelihood and BVAR methodologies, Lubik and Schorfheide (2005) which ap
plies Bayesian estimation methods to an open macro model focussing on issues
of misspeciﬁcation and identiﬁcation, and ﬁnally Rabanal and RubioRamirez
(2005) which compares the ﬁt, based on posterior distributions, of four com
peting speciﬁcations of New Keynesian monetary models with nominal rigidi
ties.
81
82
CHAPTER 8. ESTIMATING DSGE MODELS  BEHIND THE SCENES
OF DYNARE
There are a multitude of advantages of using Bayesian methods to esti
mate a model, but ﬁve of these stand out as particularly important and general
enough to mention here.
First, Bayesian estimation ﬁts the complete, solved DSGE model, as op
posed to GMM estimation which is based on particular equilibrium relation
ships such as the Euler equation in consumption. Likewise, estimation in the
Bayesian case is based on the likelihood generated by the DSGE system, rather
than the more indirect discrepancy between the implied DSGE and VAR im
pulse response functions. Of course, if your model is entirely misspeciﬁed,
estimating it using Bayesian techniques could be a disadvantage.
Second, Bayesian techniques allow the consideration of priors which work
as weights in the estimation process so that the posterior distribution avoids
peaking at strange points where the likelihood peaks. Indeed, due to the
stylized and often misspeciﬁed nature of DSGE models, the likelihood often
peaks in regions of the parameter space that are contradictory with common
observations, leading to the “dilemma of absurd parameter estimates”.
Third, the inclusion of priors also helps identifying parameters. Unfortu
nately, when estimating a model, the problem of identiﬁcation often arises. It
can be summarized by diﬀerent values of structural parameters leading to the
same joint distribution for observables. More technically, the problem arises
when the posterior distribution is ﬂat over a subspace of parameter values.
But the weighting of the likelihood with prior densities often leads to adding
just enough curvature in the posterior distribution to facilitate numerical max
imization.
Fourth, Bayesian estimation explicitly addresses model misspeciﬁcation by
including shocks, which can be interpreted as observation errors, in the struc
tural equations.
Sixth, Bayesian estimation naturally leads to the comparison of models
based on ﬁt. Indeed, the posterior distribution corresponding to competing
models can easily be used to determine which model best ﬁts the data. This
procedure, as other topics mentioned above, is discussed more technically in
the subsection below.
8.2 The basic mechanics of Bayesian estimation
This and the following subsections are based in great part on work by, and
discussions with, St´ephane Adjemian, a member of the Dynare development
8.2. THE BASIC MECHANICS OF BAYESIAN ESTIMATION 83
team. Some of this work, although summarized in presentation format, is
available in the “Events” page of the Dynare website. Other helpful material
includes An and Schorfheide (2006), which includes a clear and quite complete
introduction to Bayesian estimation, illustrated by the application of a sim
ple DSGE model. Also, the appendix of Schorfheide (2000) contains details
as to the exact methodology and possible diﬃculties encountered in Bayesian
estimation. You may also want to take a glance at Hamilton (1994), chapter
12, which provides a very clear, although somewhat outdated, introduction
to the basic mechanics of Bayesian estimation. Finally, the websites of Frank
Schorfheide and Jesus FernandezVillaverde contain a wide variety of very
helpful material, from example ﬁles to lecture notes to related papers. Fi
nally, remember to also check the open online examples of the Dynare website
for examples of .mod ﬁles touching on Bayesian estimation.
At its most basic level, Bayesian estimation is a bridge between calibra
tion and maximum likelihood. The tradition of calibrating models is inherited
through the speciﬁcation of priors. And the maximum likelihood approach en
ters through the estimation process based on confronting the model with data.
Together, priors can be seen as weights on the likelihood function in order to
give more importance to certain areas of the parameter subspace. More tech
nically, these two building blocks  priors and likelihood functions  are tied
together by Bayes’ rule. Let’s see how.
First, priors are described by a density function of the form
p(θ
A
A)
where A stands for a speciﬁc model, θ
A
represents the parameters of model A,
p(•) stands for a probability density function (pdf) such as a normal, gamma,
shifted gamma, inverse gamma, beta, generalized beta, or uniform function.
Second, the likelihood function describes the density of the observed data,
given the model and its parameters:
L(θ
A
Y
T
, A) ≡ p(Y
T
θ
A
, A)
where Y
T
are the observations until period T, and where in our case the
likelihood is recursive and can be written as:
p(Y
T
θ
A
, A) = p(y
0
θ
A
, A)
T
t=1
p(y
t
Y
t−1
, θ
A
, A)
We now take a step back. Generally speaking, we have a prior density p(θ)
on the one hand, and on the other, a likelihood p(Y
T
θ). In the end, we are
interested in p(θY
T
), the posterior density. Using the Bayes theorem
84
CHAPTER 8. ESTIMATING DSGE MODELS  BEHIND THE SCENES
OF DYNARE
twice we obtain this density of parameters knowing the data. Generally, we
have
p(θY
T
) =
p(θ; Y
T
)
p(Y
T
)
We also know that
p(Y
T
θ) =
p(θ; Y
T
)
p(θ)
⇔p(θ; Y
T
) = p(Y
T
θ) ×p(θ)
By using these identities, we can combine the prior density and the
likelihood function discussed above to get the posterior density:
p(θ
A
Y
T
, A) =
p(Y
T
θ
A
, A)p(θ
A
A)
p(Y
T
A)
where p(Y
T
A) is the marginal density of the data conditional on the model:
p(Y
T
A) =
_
Θ
A
p(θ
A
; Y
T
A)dθ
A
Finally, the posterior kernel (or unnormalized posterior density, given
that the marginal density above is a constant or equal for any parameter),
corresponds to the numerator of the posterior density:
p(θ
A
Y
T
, A) ∝ p(Y
T
θ
A
, A)p(θ
A
A) ≡ K(θ
A
Y
T
, A)
This is the fundamental equation that will allow us to rebuild all posterior mo
ments of interest. The trick will be to estimate the likelihood function with
the help of the Kalman ﬁlter and then simulate the posterior kernel using
a samplinglike or Monte Carlo method such as the MetropolisHastings.
These topics are covered in more details below. Before moving on, though,
the subsection below gives a simple example based on the above reasoning
of what we mean when we say that Bayesian estimation is “somewhere in
between calibration and maximum likelihood estimation”. The example is
drawn from Zellner (1971), although other similar examples can be found in
Hamilton (1994), chapter 12.
8.2.1 Bayesian estimation: somewhere between calibration
and maximum likelihood estimation  an example
Suppose a data generating process y
t
= µ + ε
t
for t = 1, ..., T, where ε
t
∼
N(0, 1) is gaussian white noise. Then, the likelihood is given by
p(Y
T
µ) = (2π)
−
T
2
e
−
1
2
T
t=1
(y
t
−µ)
2
We know from the above that ´ µ
ML,T
=
1
T
T
t=1
y
t
≡ y and that V[´ µ
ML,T
] =
1
T
.
8.3. DSGE MODELS AND BAYESIAN ESTIMATION 85
In addition, let our prior be a gaussian distribution with expectation µ
0
and variance σ
2
µ
. Then, the posterior density is deﬁned, up to a constant, by:
p (µY
T
) ∝ (2πσ
2
µ
)
−
1
2
e
−
1
2
(µ−µ
0
)
2
σ
2
µ
×(2π)
−
T
2
e
−
1
2
T
t=1
(y
t
−µ)
2
Or equivalently, p (µY
T
) ∝ e
−
(µ−E[µ])
2
V[µ]
, with
V[µ] =
1
_
1
T
_
−1
+σ
−2
µ
and
E[µ] =
_
1
T
_
−1
´ µ
ML,T
+σ
−2
µ
µ
0
_
1
T
_
−1
+σ
−2
µ
From this, we can tell that the posterior mean is a convex combination of
the prior mean and the ML estimate. In particular, if σ
2
µ
→ ∞ (ie, we have
no prior information, so we just estimate the model) then E[µ] → ´ µ
ML,T
, the
maximum likelihood estimator. But if σ
2
µ
→0 (ie, we’re sure of ourselves and
we calibrate the parameter of interest, thus leaving no room for estimation)
then E[µ] → µ
0
, the prior mean. Most of the time, we’re somewhere in the
middle of these two extremes.
8.3 DSGE models and Bayesian estimation
8.3.1 Rewriting the solution to the DSGE model
Recall from chapter 7 that any DSGE model, which is really a collection of ﬁrst
order and equilibrium conditions, can be written in the formE
t
{f(y
t+1
, y
t
, y
t−1
, u
t
)} =
0, taking as a solution equations of the type y
t
= g(y
t−1
, u
t
), which we call
the decision rule. In more appropriate terms for what follows, we can rewrite
the solution to a DSGE model as a system in the following manner:
y
∗
t
= M¯ y(θ) +Mˆ y
t
+N(θ)x
t
+η
t
ˆ y
t
= g
y
(θ)ˆ y
t−1
+g
u
(θ)u
t
E(η
t
η
t
) = V (θ)
E(u
t
u
t
) = Q(θ)
where ˆ y
t
are variables in deviations from steady state, ¯ y is the vector of steady
state values and θ the vector of deep (or structural) parameters to be esti
mated. Other variables are described below.
The second equation is the familiar decision rule mentioned above. But
the equation expresses a relationship among true endogenous variables that
are not directly observed. Only y
∗
t
is observable, and it is related to the true
86
CHAPTER 8. ESTIMATING DSGE MODELS  BEHIND THE SCENES
OF DYNARE
variables with an error η
t
. Furthermore, it may have a trend, which is captured
with N(θ)x
t
to allow for the most general case in which the trend depends on
the deep parameters. The ﬁrst and second equations above therefore naturally
make up a system of measurement and transition or state equations, respec
tively, as is typical for a Kalman ﬁlter (you guessed it, it’s not a coincidence!).
8.3.2 Estimating the likelihood function of the DSGE model
The next logical step is to estimate the likelihood of the DSGE solution system
mentioned above. The ﬁrst apparent problem, though, is that the equations
are non linear in the deep parameters. Yet, they are linear in the endogenous
and exogenous variables so that the likelihood may be evaluated with a linear
prediction error algorithm like the Kalman ﬁlter. This is exactly what Dynare
does. As a reminder, here’s what the Kalman ﬁlter recursion does.
For t = 1, . . . , T and with initial values y
1
and P
1
given, the recursion
follows
v
t
= y
∗
t
− ¯ y
∗
−Mˆ y
t
−Nx
t
F
t
= MP
t
M
+V
K
t
= g
y
P
t
g
y
F
−1
t
ˆ y
t+1
= g
y
ˆ y
t
+K
t
v
t
P
t+1
= g
y
P
t
(g
y
−K
t
M)
+g
u
Qg
u
For more details on the Kalman ﬁlter, see Hamilton (1994), chapter 13.
From the Kalman ﬁlter recursion, it is possible to derive the loglikelihood
given by
ln L(θY
∗
T
) = −
Tk
2
ln(2π) −
1
2
T
t=1
F
t
 −
1
2
v
t
F
−1
t
v
t
where the vector θ contains the parameters we have to estimate: θ, V (θ) and
Q(θ) and where Y
∗
T
expresses the set of observable endogenous variables y
∗
t
found in the measurement equation.
The loglikelihood above gets us one step closer to our goal of ﬁnding the
posterior distribution of our parameters. Indeed, the log posterior kernel
can be expressed as
ln K(θY
∗
T
) = ln L(θY
∗
T
) + ln p(θ)
where the ﬁrst term on the right hand side is now known after carrying out the
Kalman ﬁlter recursion. The second, recall, are the priors, and are also known.
8.3. DSGE MODELS AND BAYESIAN ESTIMATION 87
8.3.3 Finding the mode of the posterior distribution
Next, to ﬁnd the mode of the posterior distribution  a key parameter and
an important output of Dynare  we simply maximize the above log posterior
kernel with respect to θ. This is done in Dynare using numerical methods.
Recall that the likelihood function is not Gaussian with respect to θ but to
functions of θ as they appear in the state equation. Thus, this maximization
problem is not completely straightforward, but fortunately doable with mod
ern computers.
8.3.4 Estimating the posterior distribution
Finally, we are now in a position to ﬁnd the posterior distribution of our
parameters. The distribution will be given by the kernel equation above,
but again, it is a nonlinear and complicated function of the deep parameters
θ. Thus, we cannot obtain an explicit form for it. We resort, instead, to
samplinglike methods, of which the MetropolisHastings has been retained in
the literature as particularly eﬃcient. This is indeed the method adopted by
Dynare.
The general idea of the MetropolisHastings algorithm is to simulate the
posterior distribution. It is a “rejection sampling algorithm” used to generate
a sequence of samples (also known as a “Markov Chain” for reasons that will
become apparent later) from a distribution that is unknown at the outset.
Remember that all we have is the posterior mode; we are instead more often
interested in the mean and variance of the estimators of θ. To do so, the
algorithm builds on the fact that under general conditions the distribution
of the deep parameters will be asymptotically normal. The algorithm, in the
words of An and Shorfheide, “constructs a Gaussian approximation around
the posterior mode and uses a scaled version of the asymptotic covariance
matrix as the covariance matrix for the proposal distribution. This allows for
an eﬃcient exploration of the posterior distribution at least in the neighbor
hood of the mode” (An and Schorfheide (2006), p. 18). More precisely, the
MetropolisHastings algorithm implements the following steps:
1. Choose a starting point θ
◦
, where this is typically the posterior mode,
and run a loop over 234.
2. Draw a proposal θ
∗
from a jumping distribution
J(θ
∗
θ
t−1
) = N(θ
t−1
, cΣ
m
)
where Σ
m
is the inverse of the Hessian computed at the posterior mode.
88
CHAPTER 8. ESTIMATING DSGE MODELS  BEHIND THE SCENES
OF DYNARE
3. Compute the acceptance ratio
r =
p(θ
∗
Y
T
)
p(θ
t−1
Y
T
)
=
K(θ
∗
Y
T
)
K(θ
t−1
Y
T
)
4. Finally accept or discard the proposal θ
∗
according to the following rule,
and update, if necessary, the jumping distribution:
θ
t
=
_
θ
∗
with probability min(r, 1)
θ
t−1
otherwise.
Figure 8.3.4 tries to clarify the above. In step 1, choose a candidate
paramter, θ
∗
from a Normal distribution, whose mean has been set to θ
t−1
(this will become clear in just a moment). In step 2, compute the value of
the posterior kernel for that candidate parameter, and compare it to the value
of the kernel from the mean of the drawing distribution. In step 3, decide
whether or not to hold on to your candidate parameter. If the acceptance
ratio is greater than one, then deﬁnitely keep your candidate. Otherwise, go
back to the candidate of last period (this is true in very coarse terms, notice
that in fact you would keep your candidate only with a probability less than
one). Then, do two things. Update the mean of your drawing distribution,
and note the value of the parameter your retain. After having repeated these
steps often enough, in the ﬁnal step, build a histogram of those retained val
ues. Of course, the point is for each “bucket” of the histogram to shrink to
zero. This “smoothed histogram” will eventually be the posterior distribution
after suﬃcient iterations of the above steps.
But why have such a complicated acceptance rule? The point is to be able
to visit the entire domain of the posterior distribution. We should not be too
quick to simply throw out the candidate giving a lower value of the posterior
kernel, just in case using that candidate for the mean of the drawing distri
bution allows us to to leave a local maximum and travel towards the global
maximum. Metaphorically, the idea is to allow the search to turn away from
taking a small step up, and instead take a few small steps down in the hope
of being able to take a big step up in the near future. Of course, an important
parameter in this searching procedure is the variance of the jumping distri
bution and in particular the scale factor. If the scale factor is too small,
the acceptance rate (the fraction of candidate parameters that are accepted
in a window of time) will be too high and the Markov Chain of candidate
parameters will “mix slowly”, meaning that the distribution will take a long
time to converge to the posterior distribution since the chain is likely to get
“stuck” around a local maximum. On the other hand, if the scale factor is
too large, the acceptance rate will be very low (as the candidates are likely to
land in regions of low probability density) and the chain will spend too much
8.3. DSGE MODELS AND BAYESIAN ESTIMATION 89
Figure 8.1: The above sketches the MetropolisHastings algorithm, used to
build the posterior distribution function. Imagine repeating these steps a large
number of times, and smoothing the “histogram” such that each “bucket” has
inﬁnitely small width.
time in the tails of the posterior distribution.
While these steps are mathematically clear, at least to a machine needing
to undertake the above calculations, several practical questions arise when
carrying out Bayesian estimation. These include: How should we choose the
scale factor c (variance of the jumping distribution)? What is a satisfactory
acceptance rate? How many draws are ideal? How is convergence of the
MetropolisHastings iterations assessed? These are all important questions
that will come up in your usage of Dynare. They are addressed as clearly as
possible in section 5.7 of Chapter 5.
90
CHAPTER 8. ESTIMATING DSGE MODELS  BEHIND THE SCENES
OF DYNARE
8.4 Comparing models using posterior
distributions
As mentioned earlier, while touting the advantages of Bayesian estimation,
the posterior distribution oﬀers a particularly natural method of comparing
models. Let’s look at an illustration.
Suppose we have a prior distribution over two competing models: p(A)
and p(B). Using Bayes’ rule, we can compute the posterior distribution over
models, where I = A, B
p(IY
T
) =
p(I)p(Y
T
I)
I=A,B
p(I)p(Y
T
I)
where this formula may easily be generalized to a collection of N models.
Then, the comparison of the two models is done very naturally through the
ratio of the posterior model distributions. We call this the posterior odds
ratio:
p(AY
T
)
p(BY
T
)
=
p(A)
p(B)
p(Y
T
A)
p(Y
T
B)
The only complication is ﬁnding the magrinal density of the data condi
tional on the model, p(Y
T
I), which is also the denominator of the posterior
density p(θY
T
) discussed earlier. This requires some detailed explanations
of their own.
For each model I = A, B we can evaluate, at least theoretically, the
marginal density of the data conditional on the model by integrating out
the deep parameters θ
I
from the posterior kernel:
p(Y
T
I) =
_
Θ
I
p(θ
I
; Y
T
θ
I
, I)dθ
I
=
_
Θ
I
p(θ
I
I) ×p(Y
T
θ
I
, I)dθ
I
Note that the expression inside the integral sign is exactly the posterior kernel.
To remind you of this, you may want to glance back at the ﬁrst subsection
above, specifying the basic mechanics of Bayesian estimation.
To obtain the marginal density of the data conditional on the model, there
are two options. The ﬁrst is to assume a functional form of the posterior kernel
that we can integrate. The most straightforward and the best approximation,
especially for large samples, is the Gaussian (called a Laplace approxima
tion). In this case, we would have the following estimator:
´ p(Y
T
I) = (2π)
k
2
Σ
θ
m
I

1
2
p(θ
m
I
Y
T
, I)p(θ
m
I
I)
where θ
m
I
is the posterior mode. The advantage of this technique is its com
putational eﬃciency: time consuming MetropolisHastings iterations are not
8.4. COMPARING MODELS USING POSTERIOR DISTRIBUTIONS 91
necessary, only the numerically calculated posterior mode is required.
The second option is instead to use information from the Metropolis
Hastings runs and is typically referred to as the Harmonic Mean Esti
mator. The idea is to simulate the marginal density of interest and to simply
take an average of these simulated values. To start, note that
p(Y
T
I) = E
_
f(θ
I
)
p(θ
I
I)p(Y
T
θ
I
, I)
¸
¸
¸
¸
θ
I
, I
_
−1
where f is a probability density function, since
E
_
f(θ
I
)
p(θ
I
I)p(Y
T
θ
I
, I)
¸
¸
¸
¸
θ
I
, I
_
=
_
Θ
I
f(θ)dθ
_
Θ
I
p(θ
I
I)p(Y
T
θ
I
, I)dθ
I
and the numerator integrates out to one (seeGeweke (1999) for more details).
This suggests the following estimator of the marginal density
´ p(Y
T
I) =
_
1
B
B
b=1
f(θ
(b)
I
)
p(θ
(b)
I
I)p(Y
T
θ
(b)
I
, I)
_
−1
where each drawn vector θ
(b)
I
comes from the MetropolisHastings iterations
and where the probability density function f can be viewed as a weights on
the posterior kernel in order to downplay the importance of extreme values of
θ. Geweke (1999) suggests to use a truncated Gaussian function, leading to
what is typically referred to as the Modiﬁed Harmonic Mean Estimator.
Chapter 9
Optimal policy under
commitment
93
Chapter 10
Troubleshooting
To make sure this section is as user friendly as possible, the best is to compile
what users have to say! Please let me know what your most common problem
is with Dynare, how Dynare tells you about it and how you solve it. Thanks
for your precious help!
95
Bibliography
An, S., and F. Schorfheide (2006): “Bayesian Analysis of DSGE Models,”
Econometric Review, Forthcoming.
Clarida, R., J. Gali, and M. Gertler (1999): “The Science of Monetary
Policy: A New Keynesian Perspective,” Journal of Economic Literature,
XXXVII, 1661–1707.
Collard, F., and M. Juillard (2001a): “Accuracy of stochastic pertur
bation methods: The case of asset pricing models,” Journal of Economic
Dynamics and Control, 25(67), 979–999.
(2001b): “A HigherOrder Taylor Expansion Approach to Simulation
of Stochastic ForwardLooking Models with an Application to a Nonlinear
Phillips Curve Model,” Computational Economics, 17(23), 125–39.
(2003): “Stochastic simulations with DYNARE. A practical guide.,”
CEPREMAP mimeo.
Durbin, J., and S. Koopman (2001): Time Series Analysis by State Space
Methods. Oxford University Press, Oxford, U.K.
FernandezVillaverde, J., and J. F. RubioRamirez (2004): “Compar
ing dynamic equilibrium models to data: a Bayesian approach,” Journal of
Econometrics, 123(1), 153–187.
Geweke, J. (1999): “Using Simulation Methods for Bayesian Econometric
Models: In ference, Development and Communication,” Econometric Re
view, 18(1), 1–126.
Hamilton, J. D. (1994): Time Series Analysis. Princeton University Press,
Princeton, NJ.
Ireland, P. N. (2004): “A method for taking models to the data,” Journal
of Economic Dynamics and Control, 28(6), 1205–1226.
Juillard, M. (1996): “Dynare : a program for the resolution and simulation
of dynamic models with forward variables through the use of a relaxation
algorithm,” CEPREMAP working papers 9602, CEPREMAP.
97
98 BIBLIOGRAPHY
Lubik, T., and F. Schorfheide (2003): “Do Central Banks Respond to
Exchange Rate Movements? A Structural Investigation,” Economics Work
ing Paper Archive 505, The Johns Hopkins University,Department of Eco
nomics.
(2005): “A Bayesian Look at New Open Economy Macroeco
nomics,” Economics Working Paper Archive 521, The Johns Hopkins Uni
versity,Department of Economics.
Nason, J. M., and T. Cogley (1994): “Testing the Implications of Long
Run Neutrality for Monetary Business Cycle Models,” Journal of Applied
Econometrics, 9(S), S37–70.
Rabanal, P., and J. F. RubioRamirez (2005): “Comparing New Key
nesian models of the business cycle: A Bayesian approach,” Journal of
Monetary Economics, 52(6), 1151–1166.
SchmittGrohe, S., and M. Uribe (2004): “Solving dynamic general equi
librium models using a secondorder approximation to the policy function,”
Journal of Economic Dynamics and Control, 28(4), 755–775.
Schorfheide, F. (2000): “Loss functionbased evaluation of DSGE models,”
Journal of Applied Econometrics, 15(6), 645–670.
Smets, F., and R. Wouters (2003): “An Estimated Dynamic Stochastic
General Equilibrium Model of the Euro Area,” Journal of the European
Economic Association, 1(5), 1123–1175.
Zellner, A. (1971): An Introduction to Bayesian Inference in Econometrics.
John Wiley & Sons, Inc., New York.
Dynare v4  User Guide Public beta version
Tommaso Mancini Griﬀoli tommaso.mancini@stanfordalumni.org This draft: June 2010
iii
Copyright c 20072010 Tommaso Mancini Griﬀoli Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no FrontCover Texts, and no BackCover Texts. A copy of the license can be found at: http://www.gnu.org/licenses/ fdl.txt
Contents
Contents List of Figures 1 Introduction 1.1 About this Guide  approach and structure 1.2 What is Dynare? . . . . . . . . . . . . . . . 1.3 Additional sources of help . . . . . . . . . . 1.4 Nomenclature . . . . . . . . . . . . . . . . . 1.5 v4, what’s new and backward compatibility 2 Installing Dynare 2.1 Dynare versions . . . . . 2.2 System requirements . . 2.3 Installing Dynare . . . . 2.4 MATLAB particularities iv vii 1 1 2 4 5 5 7 7 7 7 8 9 9 10 11 15 15 16 16 17 18 18 19 19 19 20 20 21
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
3 Solving DSGE models  basics 3.1 A fundamental distinction . . . . . . . . . . . . . . . . . . . 3.1.1 NOTE! Deterministic vs stochastic models . . . . . . 3.2 Introducing an example . . . . . . . . . . . . . . . . . . . . 3.3 Dynare .mod ﬁle structure . . . . . . . . . . . . . . . . . . . 3.4 Filling out the preamble . . . . . . . . . . . . . . . . . . . . 3.4.1 The deterministic case . . . . . . . . . . . . . . . . . 3.4.2 The stochastic case . . . . . . . . . . . . . . . . . . . 3.4.3 Comments on your ﬁrst lines of Dynare code . . . . 3.5 Specifying the model . . . . . . . . . . . . . . . . . . . . . . 3.5.1 Model in Dynare notation . . . . . . . . . . . . . . . 3.5.2 General conventions . . . . . . . . . . . . . . . . . . 3.5.3 Notational conventions . . . . . . . . . . . . . . . . . 3.5.4 Timing conventions . . . . . . . . . . . . . . . . . . 3.5.5 Conventions specifying nonpredetermined variables 3.5.6 Linear and loglinearized models . . . . . . . . . . . 3.6 Specifying steady states and/or initial values . . . . . . . . iv
. . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
CONTENTS 3.6.1 Stochastic models and steady states . . . . 3.6.2 Deterministic models and initial values . . . 3.6.3 Finding a steady state . . . . . . . . . . . . 3.6.4 Checking system stability . . . . . . . . . . 3.7 Adding shocks . . . . . . . . . . . . . . . . . . . . 3.7.1 Deterministic models  temporary shocks . 3.7.2 Deterministic models  permanent shocks . 3.7.3 Stochastic models . . . . . . . . . . . . . . 3.8 Selecting a computation . . . . . . . . . . . . . . . 3.8.1 For deterministic models . . . . . . . . . . . 3.8.2 For stochastic models . . . . . . . . . . . . 3.9 The complete .mod ﬁle . . . . . . . . . . . . . . . . 3.9.1 The stochastic model . . . . . . . . . . . . . 3.9.2 The deterministic model (case of temporary 3.10 File execution and results . . . . . . . . . . . . . . 3.10.1 Results  stochastic models . . . . . . . . . 3.10.2 Results  deterministic models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . shock) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
v 21 23 23 24 25 25 25 27 27 28 28 31 31 32 33 33 34 37 37 37 38 41 42 43 43 44 44 44 44 46 47 47 48 48 49 49 49 52 55 57 57 57
4 Solving DSGE models  advanced topics 4.1 Dynare features and functionality . . . . . . . . . . . . . . 4.1.1 Other examples . . . . . . . . . . . . . . . . . . . . 4.1.2 Alternative, complete example . . . . . . . . . . . 4.1.3 Finding, saving and viewing your output . . . . . . 4.1.4 Referring to external ﬁles . . . . . . . . . . . . . . 4.1.5 Inﬁnite eigenvalues . . . . . . . . . . . . . . . . . . 4.2 Files created by Dynare . . . . . . . . . . . . . . . . . . . 4.3 Modeling tips . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.1 Stationarizing your model . . . . . . . . . . . . . . 4.3.2 Expectations taken in the past . . . . . . . . . . . 4.3.3 Inﬁnite sums . . . . . . . . . . . . . . . . . . . . . 4.3.4 Inﬁnite sums with changing timing of expectations 5 Estimating DSGE models  basics 5.1 Introducing an example . . . . . . 5.2 Declaring variables and parameters 5.3 Declaring the model . . . . . . . . 5.4 Declaring observable variables . . . 5.5 Specifying the steady state . . . . 5.6 Declaring priors . . . . . . . . . . . 5.7 Launching the estimation . . . . . 5.8 The complete .mod ﬁle . . . . . . . 5.9 Interpreting output . . . . . . . . . 5.9.1 Tabular results . . . . . . . 5.9.2 Graphical results . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
6 Estimating DSGE models  advanced topics 6.1 Alternative and nonstationary example . . . . . . . . . 6.1.1 Introducing the example . . . . . . . . . . . . . . 6.1.2 Declaring variables and parameters . . . . . . . . 6.1.3 The origin of nonstationarity . . . . . . . . . . . 6.1.4 Stationarizing variables . . . . . . . . . . . . . . 6.1.5 Linking stationary variables to the data . . . . . 6.1.6 The resulting model block of the .mod ﬁle . . . . 6.1.7 Declaring observable variables . . . . . . . . . . . 6.1.8 Declaring trends in observable variables . . . . . 6.1.9 Declaring unit roots in observable variables . . . 6.1.10 Specifying the steady state . . . . . . . . . . . . 6.1.11 Declaring priors . . . . . . . . . . . . . . . . . . 6.1.12 Launching the estimation . . . . . . . . . . . . . 6.1.13 The complete .mod ﬁle . . . . . . . . . . . . . . . 6.1.14 Summing it up . . . . . . . . . . . . . . . . . . . 6.2 Comparing models based on their posterior distributions 6.3 Where is your output stored? . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
61 61 61 66 66 67 68 68 69 69 70 71 71 71 72 74 74 75
7 Solving DSGE models  Behind the scenes of Dynare 77 7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 7.2 What is the advantage of a second order approximation? . . . . 77 7.3 How does dynare solve stochastic DSGE models? . . . . . . . . 78 8 Estimating DSGE models  Behind the scenes of Dynare 81 8.1 Advantages of Bayesian estimation . . . . . . . . . . . . . . . . 81 8.2 The basic mechanics of Bayesian estimation . . . . . . . . . . . 82 8.2.1 Bayesian estimation: somewhere between calibration and maximum likelihood estimation  an example . . . . . . 84 8.3 DSGE models and Bayesian estimation . . . . . . . . . . . . . . 85 8.3.1 Rewriting the solution to the DSGE model . . . . . . . 85 8.3.2 Estimating the likelihood function of the DSGE model . 86 8.3.3 Finding the mode of the posterior distribution . . . . . 87 8.3.4 Estimating the posterior distribution . . . . . . . . . . . 87 8.4 Comparing models using posterior distributions . . . . . . . . . 90 9 Optimal policy under commitment 10 Troubleshooting vi 93 95
. a bird’s eyeview . . . . . . . . .List of Figures Bibliography vii 97 List of Figures 1. . . . . . . . . . . . . . . . . . . . Steps of model estimation . . . . . . . .1 6. . . . . . . . . . CIA model illustration . . . . Illustration of the MetropolisHastings algorithm . . . . . . . . . .1 6. . . . . . . . .mod ﬁle . . . . . . Structure of the . .2 8. . . . . . 3 16 62 74 89 . . . . . . . . .1 3. . . . .1 Dynare. . . . . . . . . . . . . .
.
mancini@stanfordalumni.org. please read this with a critical eye and send me comments! Are some areas unclear? Is anything plain wrong? Are some sections too wordy. or preferably on the Dynare Documentation Forum available in the Dynare Forums. The second thing that a work in progress manuscript comes with is a few internal notes. are these clear? On the contrary. Thanks very much for your patience and good ideas. These are mostly placeholders for future work.Work in Progress! This is the second version of the Dynare User Guide which is still work in progress! This means two things. are there certain parts that just click particularly well? How can others be improved? I’m very interested to get your feedback. notes to myself or others of the Dynare development team. Please write either direclty to myself: tommaso. First.our readers . Any such notes are marked with two stars (**). or at times notes to you .to highlight a feature not yet fully stable. are there enough examples. ix .
.
juillard“AT”mjui. The email addresses above are provided in case you wish to contact any one of the authors of Dynare directly. the development of Dynare could not have come such a long ways withough an active community of users who continually pose questions. Klein. almost no question is speciﬁc enough to interest just one person.fr) • George Perendia (george“AT”perendia. O. Collard.Contacts and Credits Dynare was originally developed by Michel Juillard in Paris. Sakata. Sims. Anderson.co. F. P.fr) e Several parts of Dynare use or have strongly beneﬁted from publicly available programs by G. France.uk) • Marco Ratto (marco. S. L.ec.fr) • Michel Juillard (michel. Kamenik. Ingber. and yours is not the exception! xi .eu) • S´bastien Villemot (sebastien.europa. C.fr) • Ferhat Mihoubi (ferhat. Currently.adjemian“AT”ens. Wouters. remember. Soederlind and R. Finally.bastani“AT”ens.fr) e • Houtan Bastani (houtan. We nonetheless encourage you to ﬁrst use the Dynare forums to ask your questions so that other users can beneﬁt from them as well. F.orangehome.ratto“AT”jrc. The help of this community is gratefully acknowledged.villemot“AT”ens. Schorfheide.mihoubi“AT”univevry. the development team of Dynare is composed of • St´phane Adjemian (stephane. P. report bugs and suggest new features.
.
though. thus emphasizing depth over breadth. this Guide is structured around examples and oﬀers practical advice. this Guide also gives some background on Dynare’s algorithms.1 About this Guide . This Guide is written mainly for an advanced economist . Thus. The sophisticated computer programmer. which introduce the program’s basic features to solve (including running impulse response functions) and estimate DSGE models.like a professor. To do 1 . methodologies and underlying theory. or the specialist of computational economics.Chapter 1 Introduction Welcome to Dynare! 1. To do so. We recognize that the “advanced economist” may be either a beginning or intermediate user of Dynare. graduate student or central banker .needing a powerful and ﬂexible program to support and facilitate his or her research activities in a variety of ﬁelds. may not ﬁnd this Guide suﬃciently detailed.approach and structure This User Guide aims to help you master Dynare’s main functionalities. a secondary function of this Guide is to serve as a basic primer on DSGE model solving and Bayesian estimation. respectively. To root this understanding more deeply. If you’re new to Dynare. This Guide will focus on the most common or useful features of the program. on the other. The idea is to get you to use 90% of the program well and then tell you where else to look if you’re interested in ﬁne tuning or advanced customization. from getting started to implementing advanced features. This Guide is written to accommodate both. on the one hand. we recommend starting with chapters 3 and 5.
These chapters can also serve as a basic primer if you are new to the practice of DSGE model solving and Bayesian estimation. At that point. the User Guide goes into some depth in covering the theoretical underpinnings and methodologies that Dynare follows to solve and estimate DSGE models. you will know the crux of Dynare’s functionality and (hopefully!) feel comfortable using Dynare for your own work. though. these chapters lead you through a complete handson example. besides breaking up content into short chapters. you will most likely ﬁnd the advanced chapters. • NOTE! is used to draw your attention to particularly important information you should keep in mind when using Dynare. these chapters read a bit more like a reference manual. . We also recognize that you probably have had repeated if not active exposure to programming and are likely to have a strong economic background. we’ve introduced two diﬀerent markers throughout the Guide to help streamline your reading. Finally. 4 and 6. These chapters cover more advanced features of Dynare and more complicated usage scenarios. to solve. let’s have a look at the “forest” from the top . Once you have read these two chapters. with an intuitive frontend interface.2 What is Dynare? Before we dive into the thick of the “trees”. Thus. The presumption is that you would skip around these chapters to focus on the topics most applicable to your needs and curiosity. in order to “learn by doing”. simulate and estimate DSGE models. which we recommend following from A to Z. Examples are therefore more concise and speciﬁc to each feature. you will probably ﬁnd yourself coming back to the User Guide to skim over some of the content in the advanced chapters to iron out details and potential complications you may run into. just what is Dynare? Dynare is a powerful and highly customizable engine. a black box solution to your needs is inadequate. These are available in the “behind the scenes of Dynare” chapters 7 and 8. . To hopefully address this issue. INTRODUCTION so.2 CHAPTER 1. more appropriate. 1. • TIP! introduces advice to help you work more eﬃciently with Dynare or solve common problems. If you’re instead an intermediate user of Dynare. .
2. but for now it may be helpful to summarize what Dynare is able to do: . Basically.mod ﬁle.2 in chapter 4. That ﬁle is then called from Matlab. WHAT IS DYNARE? 3 Figure 1. results are presented in Matlab. The resulting ﬁle will be called the . Finally. is written equation by equation in an editor of your choice.mod ﬁle into a suitable input for the Matlab routines (more precisely. Figure 1. This initiates the Dynare preprocessor which translates the . Some more details on the internal ﬁles generated by Dynare is given in section 4. like a shock structure for instance. In slightly less ﬂowery words. but also enables you to easily share your code as it is straightforward to read by anyone.1. Each of these steps will become clear as you read through the User Guide.2 gives you an overview of the way Dynare works.1: The . the model and its related attributes. it is a preprocessor and a collection of Matlab routines that has the great advantages of reading DSGE model equations written almost as in an academic paper. it creates intermediary Matlab or C ﬁles which are then used by Matlab code) used to either solve or estimate the model.mod ﬁle being read by the Dynare preprocessor. This not only facilitates the inputting of a model. which then calls the relevant Matlab routines to carry out the desired operations and display the results.
At your disposal. • Dynare forums: this lively online discussion forum allows you to ask your questions openly and read threads from others who might have run into similar diﬃculties.usually well documented .of . it conveniently lists conferences. • Frequently Asked Questions (FAQ): this section of the Dynare site emphasizes a few of the most popular questions in the forums.4 • compute the steady state of a model CHAPTER 1.3 Additional sources of help While this User Guide tries to be as complete and thorough as possible. • DSGE. Besides allowing you to stay up to date with the most recent papers and possibly make new contacts. you have the following additional sources of help: • Reference Manual: this manual covers all Dynare commands. struggle with adapting examples to your own work.mod ﬁles covering models and methodologies introduced in recent papers. giving a clear deﬁnition and explanation of usage for each. is a resource for all scholars working in the ﬁeld of DSGE modeling. . The User Guide will often introduce you to a command in a rather loose manner (mainly through examples). so reading corresponding command descriptions in the Reference Manual is a good idea to cover all relevant details. workshops and seminars that may be of interest. run my members of the Dynare team. as you learn about new features. and yearn to ask that one question whose answer seems to exist nowhere.net: this website. • Oﬃcial online examples: the Dynare website includes other examples . you will certainly want to browse other material for help. INTRODUCTION • compute the solution of deterministic models • compute the ﬁrst and second order approximation to solutions of stochastic models • estimate parameters of DSGE models using either a maximum likelihood or a Bayesian approach • compute optimal policies in linearquadratic models 1.
4 Nomenclature To end this introduction and avoid confusion in what follows. NOMENCLATURE 5 1. 1.5 v4.1E3. All other characters.g. 1. including accents. • Filename indicates a ﬁle name valid in your operating system. 1.is version 4. Note that Matlab requires that names of ﬁles or functions start with alphabetical characters. the option must be speciﬁed in parenthesis in Dynare.4. • Variable name indicates a variable name. The following syntaxes are valid: 1. • Parameter name indicates a parameter name which must follow the same naming conventions as above.1d3. what’s new and backward compatibility The current version of Dynare . • Options or optional arguments for a command are listed in square brackets [ ] unless otherwise noted. optimizations of routines and bug ﬁxes. 1. this new version introduces several important features.1. are forbidden. • Command is an instruction to Dynare or other program when speciﬁed. The drawback is that Dynare can now handle only a limited set of functions.mod ﬁles. for instance. • Typewritten text indicates text as it should appear in Dynare code. it is worthwhile to agree on a few deﬁnitions of terms. as well as improvements. Many of these are shared with the Reference Manual. although in nearly all economic applications this should not be a constraint. • Integer indicates an integer number. • Double indicates a double precision number. as well as underscores ( ). and spaces.1D3 • Expression indicates a mathematical expression valid in the underlying language (e. With respect to version 3. in the Newton algorithm for deterministic models and in the linearizations necessary to solve stochastic models). . This increases computational speed signiﬁcantly. it will show up in the Guide as [(option)].for which this guide is written .1e3. 1. Matlab).1E3. The major new features are the following: • Analytical derivatives are now used everywhere (for instance. this concerns your Dynare . NOTE! These must start with an alphabetical character and can only contain other alphabetical characters and digits. If.
• Speed. The names of the ﬁles internally generated by Dynare have also changed. in section 3. but also apparent in other functionality. NOTE! You will unfortunately have to slightly amend any old steady state ﬁles you may have written. NOTE! This may cause some problems of backward compatibility if you wrote programs to run oﬀ Dynare v3 output. Recall that in version 3. • The names of many internal variables and the organization of output variables has changed. This should be most noticeable when solving deterministic models. (** more on this when explaining internal ﬁle structure TBD) • The syntax for the external steady state ﬁle has changed. .6 CHAPTER 1. This is covered in more details in chapter 3. These are enumerated in details in the relevant chapters. INTRODUCTION • Variables and parameters are now kept in the order in which they are declared whenever displayed and when used internally by Dynare.3. Several largescale improvements have been implemented to speed up Dynare. variables and parameters where at times in their order of declaration and at times in alphabetical order.6.
you may need up to 1GB of RAM to obtain acceptable computational times. it is recommended to allocate at least 256MB of RAM to the platform running Dynare.1) runs on both MATLAB and GNU Octave.Chapter 2 Installing Dynare 2.2 System requirements Dynare can run on Microsoft Windows.3 Installing Dynare Please refer to the section entitled “Installation and conﬁguration” in the Dynare reference manual. There used to be versions of Dynare for Scilab and Gauss. although 512MB is preferred. please ask your question on Dynare forums. Depending on the type of computations required.1.02 and that for Gauss after Dynare version 1.0 and later.2. Dynare++. in particular GNU/Linux and Mac OS X. 2. To run Dynare. 2. like the very processor intensive Metropolis Hastings algorithm. This User Guide will exclusively focus on Dynare version 4. as well as Unixlike operating systems.1 Dynare versions The current version of Dynare (4. 7 . You may also be interested by another program. See the Dynare++ webpage for more information. If you have questions about the support of a particular platform. Development of the Scilab version stopped after Dynare version 3. Note that Dynare++ is distributed along with Dynare since version 4. which is a standalone C++ program specialized in computing korder approximations of dynamic stochastic general equilibrium models.
both of which are deﬁned later. but even then remedies exist (see the Dynare forums for discussions on this. or to ask your particular question).4 MATLAB particularities A question often comes up: what special MATLAB toolboxes are necessary to run Dynare? In fact.8 CHAPTER 2. But if you do have the ‘optimization toolbox’ installed. you will have additional options for solving for the steady state (solve algo option) and for searching for the posterior mode (mode compute option). no additional toolbox is necessary for running most of Dynare. INSTALLING DYNARE 2. except maybe for optimal simple rules (see chapter 9). .
Likewise. Typically. here is the important question: is your model stochastic or deterministic? The distinction hinges on whether future shocks are known. the occurrence of all future shocks is known exactly at the time of computing the model’s solution. But the amount of common material .this will serve as a base to carry out any of the above computations. whether temporary or permanent. agents will take their decisions knowing that future values of the innovations will be zero in all periods to come. agents will take their decisions 9 . This distinction will appear throughout the chapter. 3. In a deterministic context. it is important to recognize a distinction in model types.is notable and writing two chapters would have been overly repetitive. In stochastic models. But instead of skipping to the topic closest to your needs. to learn basic Dynare commands and the process of writing a proper . In a stochastic context.Dynare commands and syntax . you may be interested in how this system behaves in response to shocks. This chapter covers all these topics. the solution of DSGE models.basics This chapter covers everything that leads to. it is so fundamental. You may be interested in simply ﬁnding the solution functions to a set of ﬁrst order conditions stemming from your model.1 A fundamental distinction Before speaking of Dynare. That is to say that the term “solution” in the title of the chapter is used rather broadly. instead. only the distribution of future shocks is known.Chapter 3 Solving DSGE models .mod ﬁle . In deterministic models. in fact. but you may also want to go a bit further. Let’s consider a shock to a model’s innovation only in period 1. you may want to explore how the system comes back to its steady state or moves to a new one. that we considered writing separate chapters altogether. a vast terrain. we recommend that you read this chapter chronologically. Enough suspense. and stems from.
Intuitively. Most often. solutions to deterministic models are usually called “closed loop” solutions.what each of her precise actions will be in the future. the best the agent can do is specify a decision.10 CHAPTER 3. Of course. instead. the two cases become practically the same. As the DSGE (read. or a linear model.at the time of making her decision . SOLVING DSGE MODELS . The solution method for each of these model types diﬀers signiﬁcantly. as in the introduction of a new tax. 3. we therefore search for a function satisfying the model’s ﬁrst order conditions. the following gives some additional details. 5. due to certainty equivalence.1. 3. These models are usually introduced to study the impact of a change in regime. and those to stochastic models are referred to as “open loop”.1 NOTE! Deterministic vs stochastic models Deterministic models have the following characteristics: 1. a highly accurate solution can be found by numerical methods. To complicate things. policy or feedback rule for the future: what will her optimal actions be contingent on each possible realization of shocks. The solution is nothing more than a series of numbers that match a given set of equations. In this case.BASICS knowing that the future value of innovations are random but will have zero mean. if an agent has perfect foresight. models introduce a positive shock today and zero shocks thereafter (with certainty). in which case they would be expected with perfect foresight. In deterministic models. if you consider only a ﬁrst order linear approximation of the stochastic model. deterministic models have become somewhat rare. this function may be nonlinear and thus needs to be approximated. In control theory. though. This isn’t the same thing because of Jensen’s inequality. i. Shocks can hit the economy today or at any time in the future. “stochastic”. for instance. as the variance of shocks will matter. . not deterministic!) literature has gained attention in economics. They can also last one or several periods. 4.e. A second order approximation will instead lead to very diﬀerent results. but also because it has been a source of signiﬁcant confusion in the past. 2. perfect foresight and no uncertainty around shocks. Examples include OLG models without aggregate uncertainty. Because this distinction will resurface again and again throughout the chapter. Models assume full information. In a stochastic environment. she can specify today .
We will nonetheless illustrate both the stochastic and the deterministic settings on the basis of this example. Examples include most RBC models. 3 and 5.2. agents behave as if future shocks where equal to zero (since their expectation is null). Note that when these models are linearized to the ﬁrst order. but thereafter their expected value is zero. which is the certainty equivalence property. INTRODUCING AN EXAMPLE 11 6. this is a good place to look for additional information on any of the following model setup and discussion. Expected future shocks. it involves numerical simulation to ﬁnd the exact paths of endogenous variables that meet the model’s ﬁrst order conditions and shock structure. Its particular notation adopted below is drawn mostly from notes available on Jesus FernandezVillaverde’s very instructive website. in fact. Note that as a general rule. Instead. shocks hit today (with a surprise). you’ll have to use a bit of imagination (on top of that needed to think you have perfect foresight!) to . Future sections will aim to code this example into Dynare and analyze its salient features under the inﬂuence of shocks . In these models. as per the earlier discussion. More complex examples are instead presented in the advanced chapters.3. Thus. or permanent changes in the exogenous variables cannot be handled due to the use of Taylor approximations around a steady state. 7. have the following characteristics: 1.both in a stochastic and a deterministic environment. The model introduced here is a basic RBC model with monopolistic competition. Stochastic models. This solution method can therefore be useful when the economy is far away from steady state (when linearization oﬀers a poor approximation). 2. These types of models tend to be more popular in the literature. are kept as bare as possible. or new keynesian monetary models.2 Introducing an example The goal of this ﬁrst section is to introduce a simple example. used widely in the literature. instead. Note throughout this model description that the use of expectation signs is really only relevant in a stochastic setting. The solution does not require linearization. it doesn’t even really need a steady state. This is an often overlooked point in the literature which misleads readers in supposing their models may be deterministic. the examples in the basic chapters. when thinking of the latter. with just enough features to help illustrate Dynare commands and functionalities. 3. 3.
ct and leisure. . as the derivations are relatively standard. production depends on capital). we obtain the intuitive result that it = kt+1 − (1 − δ)kt . or aggregate output. These equation are 1 1 = βEt (1 + rt+1 − δ) ct ct+1 and ψ ct = wt 1 − lt The ﬁrm side of the problem is slightly more involved. with a little more imagination. equals yt . ∀t > 0 where kt is capital stock.on the right hand side. but is presented below in the simplest possible terms. yields the Euler equation in consumption. leisure and capital stock. the equation can also be interpreted as a capital accumulation equation after bringing ct to the right hand side and noticing that wt lt + rt kt . with a little handwaiving involved. or that investment replenishes the capital stock thereby countering the eﬀects of depreciation. 1−lt . As a consequence. SOLVING DSGE MODELS . due to monopolistic competition. where lt is labor input.including the liquidation value of the capital stock . the consumer therefore faces a tradeoﬀ between consuming and investing in order to increase the capital stock and consuming more in following periods (as we will see later. by the zero proﬁt condition. wt real wages. if we deﬁne investment as it = yt − ct . rt real interest rates or cost of capital and δ the depreciation rate. Households maximize utility over consumption. capturing the intertemporal tradeoﬀ mentioned above. In any given period. total payments to factors. with total expenditures on the left hand side and revenues .12 CHAPTER 3. Alternatively. the more leisure due to the decreasing marginal utility of consumption). and the labor supply equation linking labor positively to wages and negatively to consumption (the wealthier. Maximization of the household problem with respect to consumption. The above equation can be seen as an accounting identity. according to the following utility function ∞ Et t=0 β [log ct + ψ log(1 − lt )] and subject to the following budget constraint ct + kt+1 = wt lt + rt kt + (1 − δ)kt .BASICS ignore the expectation signs.
INTRODUCING AN EXAMPLE 13 There are two ways to introduce monopolistic competition. or relationship between payments to factors: kit rt = α wt lit 1−α The solution to the pricing problem. mct is real marginal cost and pt is the aggregate CES price or average price. Production of intermediate goods follows a CRS production function deﬁned as α yit = kit (ezt lit )1−α where the i subscript stands for ﬁrm i of a continuum of ﬁrms between zero and one and where α is the capital elasticity in the production function. yields the wellknown constant markup pricing condition of monopolistic competition: pit = −1 mct pt where pit is ﬁrm i’s speciﬁc price.3.2. with 0 < α < 1. An additional step simpliﬁes this expression: symmetric ﬁrms implies that all ﬁrms charge the same price and thus pit = pt . The real cost of using this amount of any one . instead. we combine the optimal capital to labor ratio into the production function and take advantage of its CRS property to solve for the amount of labor or capital required to produce one unit of output. instead. The solution to the sourcing problem yields an optimal capital to labor ratio. If we follow the second route. yielding the DixitStiglitz downward sloping demand curve. Also. Or we can postulate that there is a continuum of intermediate producers with market power who each sell a diﬀerent variety to a competitive ﬁnal goods producer whose production function is a CES aggregate of intermediate varieties. zt captures technology which evolves according to zt = ρzt−1 + et where ρ is a parameter capturing the persistence of technological progress and et ∼ N (0. σ). the ﬁnal goods producer chooses his or her optimal demand for each variety. We can either assume that ﬁrms sell diﬀerentiated varieties of a good to consumers who aggregate these according to a CES index. Intermediate producers. face a two pronged decision: how much labor and capital to employ given these factors’ perfectly competitive prices and how to price the variety they produce. we therefore have: mct = ( − 1)/ But what are marginal costs equal to? To ﬁnd the answer.
with the optimal pricing condition yields the ﬁnal two important equations of our model wt = (1 − α) and yit ( − 1) lit yit ( − 1) kit To end. kt /lt . we can rewrite the above two equations for wt and rt without the i subscripts on the right hand side. to yield wt [(1 − α)yit /lit ]−1 . in turn. This should not be a surprise since the optimal capital to labor ratio follows from the maximization of the production function (minus real costs) with respect to its factors. to close. equal to the aggregate output of ﬁnal good.or that. Note. itself equal to household consumption. which is the same for all ﬁrms and thus does not depend on i. we aggregate the production of each individual ﬁrm to ﬁnd an aggregate production function. and noting that price dispersion is null . let’s roll up our sleeves and see how we can input the model into Dynare and actually test how the model will respond to shocks. we obtain mct = 1 1−α 1−α 1 α α 1 1−α α w rt At t which does not depend on i. On the supply side.BASICS factor is given by wt lit + rt kit where we substitute out the payments to the other factor using again the optimal capital to labor ratio. by using the optimal capital ∂l to labor ratio. we factor out the capital to labor ratio. When solving for labor. Combining this result for marginal cost.we obtain aggregate production rt = α α 1−α yt = At kt lt which can be shown is equal to the aggregate amount of varieties bought by the ﬁnal good producer (according to a CES aggregation index) and. we have the DixitStiglitz demand for each variety. that because the ratio of output to each factor is the same for each intermediate ﬁrm and that ﬁrm speciﬁc as well as aggregate production is CRS. or wt ∂yit .14 CHAPTER 3. SOLVING DSGE MODELS . Now. Interestingly. which is the deﬁnition it of marginal cost: the cost in terms of labor input of producing an additional unit of output. as hinted earlier. On the other side. By equating the two and integrating both side. . pit = pt . it is thus the same for all ﬁrms. the above can be worked out. as well as its counterpart in terms of capital. This ends the exposition of the example. for instance.
mod ﬁle structure Input into Dynare involves the . as mentioned loosely in the introduction of this Guide.3.g. let’s start by writing one! It is convenient to think of the . illustrated in ﬁgure 3.mod ﬁle can be written in any editor.4 Filling out the preamble The preamble generally involves three commands that tell Dynare what are the model’s variables. estimating impulse response functions) Our exposition below will structured according to each of these blocks.3. First.3: • preamble: lists variables and parameters • model: spells out the model • steady state or initial value: gives indications to ﬁnd the steady state of a model. • varexo starts the list of exogenous variables that will be shocked. which are endogenous and what are the parameters. forecasting.3 Dynare .mod ﬁle. then we discuss them. . The commands are: • var starts the list of endogenous variables. let’s diﬀerentiate between the stochastic and deterministic cases.mod. But before we get into executing a . to be separated by commas. The .mod is not necessary). • shocks: deﬁnes the shocks to the system • computation: instructs Dynare to undertake speciﬁc operations (e. • parameters starts the list of parameters and assigns values to each. or the starting point for simulations or impulse response functions based on the model’s solution. DYNARE .mod ﬁle is stored and then by typing in the Matlab command line Dynare filename. 3. It will then be read by Matlab by ﬁrst navigating within Matlab to the directory where the . external or internal to Matlab. (although actually typing the extension .mod ﬁle.MOD FILE STRUCTURE 15 3. we lay these out.mod ﬁle as containing four distinct blocks. In the case of our example.
as we can make zt directly exogenous.33.75. we therefore .99. parameters beta psi delta alpha sigma epsilon. varexo z.mod ﬁle contains ﬁve logically distinct parts. Thus.2 The stochastic case In this case.4.1 The deterministic case The model is inherited exactly as speciﬁed in the earlier description. 3.007/(1alpha)). SOLVING DSGE MODELS . except that we no longer need the et variable. alpha = 0. we go back to considering the law of motion for technology. et . delta = 0.BASICS Figure 3. psi = 1.1: The . sigma = (0.023.4. consisting of an exogenous shock. beta = 0. the preamble would look like: var y c k i l y l w r. With respect to the above. epsilon = 10.16 CHAPTER 3. 3.
.75.95. delta = 0. parameters beta psi delta alpha rho sigma epsilon. parameters beta psi delta alpha rho sigma epsilon. // the above instruction reads over two lines /* the following section lists several parameters which were calibrated by my coauthor.023. Ask her all the difficult questions! */ alpha = 0.mod ﬁle must be terminated by a semicolon (. and add the parameter ρ.mod ﬁle is really quite straightforward. beta = 0. beta = 0. sigma = (0. although a single instruction can span two lines if you need extra space (just don’t put a semicolon at the end of the ﬁrst line). varexo e. psi = 1.023. 3.007/(1alpha)).3 Comments on your ﬁrst lines of Dynare code As you can tell. varexo e. writing a . delta = 0. rho = 0. For example: var y c k i l y l w r z.95. epsilon = 10.). TIP! You can also comment out any line by starting the line with two forward slashes (//). rho = 0.33.33. Here’s what the preamble would look like: var y c k i l y l w r z. psi = 1.4.4.75.99. Two quick comments: NOTE! Remember that each instruction of the . FILLING OUT THE PREAMBLE 17 adjust the list of endogenous and exogenous variables.3. alpha = 0. or comment out an entire section by starting the section with /* and ending with */.99.
This greatly facilitates the sharing of your Dynare ﬁles. The third the accounting identity. SOLVING DSGE MODELS . here’s a brief description: the ﬁrst equation is the Euler equation in consumption. 3. The second the labor supply function.007/(1alpha)). and then go through the various Dynare input conventions. indeed. psi*c/(1l) = w. notice that the law of motion for technology is included. See how easy it is to read Dynare code? model. The corresponding model for the deterministic casce would simply loose the last equation. almost as if you were writing them in an academic paper.5. What you can already try to do is glance at the model block below and see if you can recognize the equations from the earlier example. NOTE! that the above model speciﬁcation corresponds to the stochastic case.1 Specifying the model Model in Dynare notation One of the beauties of Dynare is that you can input your model’s equations naturally. The fourth is the production function. w = y*((epsilon1)/epsilon)*(1alpha)/l. as your colleagues will be able to understand your code in notime. Just in case you need a hint or two to recognize these equations. z = rho*z(1)+e.BASICS sigma = (0. The eighth an identity that may be useful and the last the equation of motion of technology. Let’s ﬁrst have a look at our model in Dynare notation. y l = y/l.5 3. i = k(1delta)*k(1). y = (k(1)^alpha)*(exp(z)*l)^(1alpha).18 CHAPTER 3. epsilon = 10. r = y*((epsilon1)/epsilon)*alpha/k(1). . The ﬁfth and sixth are the marginal cost equal to markup equations. The seventh is the investment equality. end. c+i = y. (1/c) = beta*(1/c(+1))*(1+r(+1)delta). as per our discussion of the preamble. There are just a few conventions to follow.
eventhough in the example presented above we wrote kt+1 = it + (1 − δ)kt . 3. For example. • Third.3 Notational conventions • Variables entering the system with a time t subscript are written plainly. equations are entered one after the other. there need to be as many equations as you declared endogenous variables (this is actually one of the ﬁrst things that Dynare checks. . Note that variable and parameter names used in the model block must be the same as those declared in the preamble. For example. . xt−2 would be written x(−2) (incidentally. 3. ).5. • In the same way.5. as in many papers. more on this below . SPECIFYING THE MODEL 19 3. but yesterday (recall that it is a function of yesterday’s investment and capital stock). For example. our capital stock is not decided today. • The ﬁrst thing to notice. • Fourth. For instance. as in the preamble and everywhere along the .5.3. it is what we call in the jargon a predetermined variable.2 General conventions The above example illustrates the use of a few important commands and conventions to translate a model into a Dynarereadable . xt+2 would be written x(+2). Writing x(2) is also allowed. no matrix representation is necessary.4 Timing conventions • In Dynare. TIP! remember that variable and parameter names are case sensitive. . we would translate this equation into Dynare as k=i+(1delta)*k(1). variables entering the system with a time t+n subscript are written with (+n) following them. xt would be written x. This is unlike Matlab where if you break a line you need to add .mod ﬁle. Thus. in between. this would count as two backward looking variables). the timing of each variable reﬂects when that variable is decided. but this notation makes it slightly harder to count by hand the number of forward looking variables (a useful measure to check). it will immediately let you know if there are any problems). . .5. is that the model block of the .mod ﬁle. • Variables entering the system with a time t − n subscript are written with (−n) following them.mod ﬁle begins with the command model and ends with the command end. • Second. each line of instruction ends with a semicolon (except when a line is too long and you want to break it across two lines.
consumption could appear with a lead in the Euler equation. Our example. SOLVING DSGE MODELS . Be careful. First. as we did (on purpose to highlight this distinction!) in the setup of the example model above. a lot of papers use the “stock at the beginning of the period” convention. If this condition is not met. but also with a lag in a habit formation equation. would look like: model (linear). In this case. consider that in some wage negociation models. yy l=yy . In the ﬁrst case. the second order diﬀerence equation would have two eigenvalues.5 Conventions specifying nonpredetermined variables • A (+1) next to a variable tells Dynare to count the occurrence of that variable as a jumper or forwardlooking or nonpredetermined variable. the model in explogs. one needing to be greater and the other smaller than one for stability. end. For instance. you can write wage in period t (when they are set). you must use a “stock at the end of the period” concept. wages should appear with a one period lag. 3. Dynare will put up a warning. the linear model and second. • BlanchardKahn conditions are met only if the number of nonpredetermined variables equals the number of eigenvalues greater than one. • A slightly more roundabout way to explain the same thing is that for stock variables. Thus. 3. Otherwise. where repeating a letter for a variable means diﬀerence from steady state. this turns out to be a very useful option . It is investment during period t that sets stock at the end of period t.20 CHAPTER 3. wages used during a period are set the period before.5. with just the equation for yl for illustration.BASICS • As another example. • Note that a variable may occur both as predetermined and nonpredetermined.ll. you may be interested to have Dynare take Taylor series expansions in logs rather than in levels.5. in the equation for wages.6 Linear and loglinearized models There are two other variants of the system’s equations which Dynare accommodates. but in the labor demand equation. all that is necessary is to write the term (linear) next to the command model. if you had one.
1 Stochastic models and steady states In a stochastic setting. Let’s see in more details how all this works. This section is also useful to specify this starting value. Our example would need to be rewritten as follows (just shown for the ﬁrst two equations) model.mod ﬁle. are provided in section 3. you should get through unscathed. or just approximations and let Dynare ﬁnd the exact steady state (which it will do using numerical methods based on your approximations).3. as we will see in chapter 5.6. You can either enter exact steady state values into your . . SPECIFYING STEADY STATES AND/OR INITIAL VALUES 21 when estimating models with unit roots. If so. this time. histval which is covered only in the Reference Manual. as well as tips to do so more eﬃciently. To do so. note that the relevant commands in this section are initval.6 Specifying steady states and/or initial values Material in this section has created much confusion in the past. as in the following fashion: initval. irrespective of whether you’re working with a stochastic or deterministic model. In passing. or approximations of values. though. you may be interested to start your simulations or impulse response functions from either a steady state.6. they need to have a steady state. The Dynare input convention makes this very easy to do. or another given point. The ﬁrst two are instead covered in what follows.mod ﬁle. endval or. so that the level of a variable is given by exp(repeatedvariable). Dynare needs to know your model’s steady state (more details on ﬁnding a steady state. (1/exp(cc)) = beta*(1/exp(cc(+1)))*(1+exp(rr(+1))delta). 3. Thus. where. In either case. But with some attention to the explanations below. Let’s start by emphasizing the uses of this section of the . psi*exp(cc)/(1exp(ll)) = exp(ww).3 below). simply rewrite your equations by taking the exponential and logarithm of each variable. your model will need to be linearized before it is solved. One of the functions of this section is indeed to provide these steady state values. end. Second. 3. First. repeating a letter for a variable means log of that variable. more rarely. recall that stochastic models need to be linearized. these values are entered in the initval block.6.
by using the command steady. w = 2. CHAPTER 3. you can control whether you want to start your simulations or impulse response functions from the steady state. the above block would be expanded to yield: initval.3.7. l = 0. e = 0. even if Dynare will have calculated your model’s exact steady state for the purpose of linearization. if you don’t add the command steady. l = 0. thus it is strongly recommended that you start your simulations from a steady state. On the contrary. end. TIP! If you’re dealing with a stochastic model. k = 9. steady. r = 0. Adding steady just after your initval block will instruct Dynare to consider your initial values as mere approximations and start simulations or impulse response functions from the exact steady state. or from the exact values you speciﬁed in the initval block. z = 0. e = 0. r = 0. c = 0.0.7. . this means either using the command steady or entering exact steady state values.BASICS Then. For the case in which you would like simulations and impulse response functions to begin at the steady state.3. your simulations or impulse response functions will start from your initial values. z = 0.0. SOLVING DSGE MODELS . remember that its linear approximation is good only in the vicinity of the steady state. end.22 k = 9. w = 2. c = 0.
An illustration of the initval block in the deterministic case appears further below.3. For complicated models. is calculating actual steady state values. you do not need to provide a steady state for these model. In this case. of course. • solve algo = 3: uses the Sims solver. If so. and luck is unfortunately part of the equation.3 Finding a steady state The diﬃculty in the above. another option is to enter your model in linear terms. But it is usually only successful if the initial values you entered are close to the true steady state. Doing so borders on a form of art. you may still run into diﬃculties in ﬁnding your steady state.6. 3. technically. Unfortunately. SPECIFYING STEADY STATES AND/OR INITIAL VALUES 23 3.6. Otherwise. variables would be expressed in percent deviations from steady state. Dynare can help in ﬁnding your model’s steady state by calling the appropriate Matlab functions. If you have trouble ﬁnding the steady state of your model. if any of your original (nonlinear) equations involve sums (a likely fact). Thus. you can begin by playing with the options following the steady command. But practically. As mentioned above. you would enter those values in your initval block and not use the steady command. their initial values would all be zero. If you wanted to shock your model starting from a steady state value. your . This is the default option if none are speciﬁed. the initval block serves very similar functions as described above. These are: • solve algo = 0: uses Matlab Optimization Toolbox FSOLVE • solve algo = 1: uses Dynare’s own nonlinear equation solver • solve algo = 2: splits the model into recursive blocks and solves each block in turn. But even for simpler models. if you wanted to begin your solution path from an arbitrary point. you would enter approximate (or exact) steady state values in the initval block. In the deterministic case. the following TIPS! may help. it is better to start with a smaller model and add new variables one by one. followed by the command steady.2 Deterministic models and initial values Deterministic models do not need to be linearized in order to be solved. Often. Yet.6. most researchers are still interested to see how a model reacts to shocks when originally in steady state. Thus. ﬁnding suitable initial values for the endogenous variables is the trickiest part of ﬁnding the equilibrium of that model.
becomes seamless. SOLVING DSGE MODELS . you need to do a little work to write your steady state program. which you would still need to calculate. The alternative is to write a Matlab program to ﬁnd your model’s steady state. Dynare will automatically check the directory where you’ve saved your . though (unless you’re working with a particular toolbox). If so. in the stochastic case. you could write an external Maple ﬁle and then enter the steady state solution by hand in Dynare. this procedure could be time consuming and bothersome. if your . For example. you could also use an external program to calculate exact steady state values. It is not enough to simply input the equations as you’ve written them in your . it will use that ﬁle to ﬁnd steady state values regardless of whether you’ve provided initial values in your . If this condition is not .m and should be saved in the same directory as your . you need to input your expressions sequentially.mod ﬁle is called example. That is.mod ﬁle. whereby each lefthand side variable is written in terms of known parameters or variables already solved in the lines above. especially if you want to alter parameter values (and thus steady states) to undertake robustness checks. As mentioned earlier. But of course.mod ﬁle. your matlab (. NOTE! When doing so. followed by steadystate For instance.24 CHAPTER 3.4 Checking system stability TIP! A handy command that you can add after the initval or endval block (following the steady command if you decide to add one) is the check command.mod. Yet. would be: (** example ﬁle to be added shortly) 3.mod ﬁle and ask Matlab to solve the system.mod ﬁle so that running loops with diﬀerent parameter values. nonlinear. a necessary condition for the uniqueness of a stable equilibrium in the neighborhood of the steady state is that there are as many eigenvalues larger than one in modulus as there are forward looking variables in the system. the steady state ﬁle corresponding to the above example. model.mod ﬁle to see if such a Matlab ﬁle exists. for instance. you may be left needing to calculate fewer steady state values than in the original.6. For instance. This computes and displays the eigenvalues of your system which are used in the solution method. your Matlab ﬁle should be called example steadystate.mod ﬁle. Alternatively. Doing so has the clear advantages of being able to incorporate your Matlab program directly into your . Because Matlab does not work with analytical expressions.m) ﬁle should have the same name as your . You will instead need to write your steady state program as if you were solving for the steady state by hand.BASICS linearized equations will include ratios of steady state values.
values 0. end.1 entered above. If variables were in logs. To do so. for instance. as explained in our original discussion on stochastic and deterministic models. though. Finally. note that we could have entered future periods in the shocks block. you are free to set the duration and level of the shock. such as periods 5:10.1. this would have corresponded to a 10% shock. 3. The corresponding instructions would be: . To work with a temporary shock. In both cases. ADDING SHOCKS 25 met. For instance.7. 3. Dynare will tell you that the BlanchardKahn conditions are not satisﬁed (whether or not you insert the check command). The distinction is that under a temporary shock. but would simply tell the system to which (steady state) values you would like it to move and let Dynare calculate the transition path.2 Deterministic models . Note that you can also use the mshocks command which multiplies the initial value of an exogenous variable by the mshocks value.7.1 Adding shocks Deterministic models .permanent shocks To study the eﬀects of a permanent shock hitting the economy today. To specify a shock that lasts 9 periods on zt . Given the above instructions. the model reaches a new steady state. while under a permanent shock. in order to study the anticipatory behavior of agents in response to future shocks. var z. you have the choice of introducing both temporary and permanent shocks. the shocks are entirely expected. you would use the endval block following the usual initval block. such as a structural change in your model. except for the value of technology which you may presume changes permanently. the model eventually comes back to steady state. Dynare would replace the value of zt speciﬁed in the initval block with the value of 0. periods 1:9. you would not specify actual “shocks”.7 3. you would write: shocks.3.temporary shocks When working with a deterministic model.7. you may specify all values to remain common between the two blocks.
1. you would have to add a shocks block after the endval block to “undo” the ﬁrst several periods of the permanent shock. l = 0. of telling Dynare to start and/ or end at a steady state close to the values you entered. k = 9. w = 2.will take longer to reach their new steady state values. SOLVING DSGE MODELS . the value of technology would move to 0. but only in period 10. when solved. .7.7. steady.26 CHAPTER 3. we make use of the second steady since the actual terminal steady state values are bound to be somewhat diﬀerent from those entered above. var z. l = 0. steady. c = 0. r = 0. w = 2. end. suppose you wanted the value of technology to move to 0. But of course. you may impose on your system that it does not return to steady state. endval. end. requires that the path of your endogenous variables pass through the steady state closest to your endval values). which. and the latter does not list exact steady state values. For instance. z = 0. k = 9. TIP! If you instead wanted to study the eﬀects of a permanent but future shock (anticipated as usual). This is unusual. your problem would become a socalled two boundary problem.0.1. c = 0. Then you would follow the above endval block with: shocks. If you do not use steady after endval.0.1 in period 1 (tomorrow) and thereafter.the endogenous variables . where steady can also be added to the endval block.3.3. which are nothing but the initial values for all variables except for technology. In our example. the other variables . and serves the same functionality as described earlier (namely. In this case. In the above example. r = 0.BASICS initval. z = 0.
end. as we did in the preamble of the .mod ﬁle. we will distinguish between deterministic and stochastic models.8.4.mod ﬁle in section 3. zt in our example. Supposing we wanted to add a shock with variance σ 2 . TIP! You can actually mix in deterministic shocks in stochastic models by using the commands varexo det and listing some shocks as lasting more than one period in the shocks block. but what should Dynare do with it? What are we interested in? In most cases. var e = sigma^2.7. Furthermore. For information on how to do so. we would declare zt as an endogenous variable and et as an exogenous variable. SELECTING A COMPUTATION periods 1:9. please see the Reference Manual. we would write: shocks. you may be interested in what happens to your monetary model if agents began expecting higher inﬂation. where σ is determined in the preamble block. 3. A permanent shock cannot be accommodated due to the need to stationarize the model around a steady state. as the expectation of future shocks must be zero. which is itself an AR(1).3 Stochastic models Recall from our earlier description of stochastic models that shocks are only allowed to be temporary. Let’s see which are the appropriate commands to give to Dynare. Again. 27 3. that aﬀects the model’s true exogenous variable. In that case. though.8 Selecting a computation So far. or a depreciation of your currency. For instance. we can however make the eﬀect of the shock propagate slowly throughout the economy by introducing a “latent shock variable” such as et in our example. . shocks can only hit the system today. exactly as in the model we introduced from the outset. it will be impulse response functions (IRFs) due to the external shocks. values 0.3. With that in mind. we have written an instructive . This can be particularly useful if you’re studying the eﬀects of anticipated shocks in a stochastic model. end.
the trajectory will basicaly describe how the system gets back to equilibrium after being perturbed from the shocks you entered. If you instead linearize to a second order. you will have cross terms involving the shocks. When the shocks are correlated. variance decomposition.8. note that future shocks will not have a signiﬁcant impact For correlated shocks. Note that unless you use the endval command. Thus. you must specify a large enough number of periods such that increasing it further doesn’t change the simulation for all practical purpose. the command stoch simul is appropriate.8. That said. In the case of a temporary shock. impulse response functions will be the result of actual Monte Carlo simulations of future shocks. This command instructs Dynare to compute a Taylor approximation of the decision and transition functions for the model (the equations listing current values of the endogenous variables of the model as a function of the previous state of the model and current shocks). and repeat this procedure a multitude of times in order to draw out an average response.2 For stochastic models In the more common case of stochastic models.1 For deterministic models In the deterministic case.mod ﬁle. 1 . it is impossible to get algebraic average values of all future shocks and their impact. it uses a Newton method to solve simultaneously all the equations for every period (see Juillard (1996) for details). the variance decomposition depends upon the order of the variables in the varexo command. SOLVING DSGE MODELS . This is because in second order linear equations. impulse response functions and various descriptive statistics (moments. Thus.BASICS 3.TIP! If you linearize your model up to a ﬁrst order. the variance decomposition is computed as in the VAR literature through a Cholesky decomposition of the covariance matrix of the exogenous variables. all you need to do is add the command simul at the bottom of your . The technique is instead to pull future shocks from their distribution and see how they impact your system. 3. Note that the command takes the option [ (periods=INTEGER) ] The command simul triggers the computation a numerical simulation of the trajectory of the model’s solution for the number of periods set in the option. for instance.28 CHAPTER 3. impulse response functions are simply the algebraic forward iteration of your model’s policy or decision rule. To do so. the algorithm makes the simplifying assumption that the system is back to equilibrium after the speciﬁed number of periods. so that the eﬀects of the shocks depend on the state of the system when the shocks hit.1 Impulse response functions are the expected future path of the endogenous variables conditional on a shock in period 1 of one standard deviation. correlation and autocorrelation coeﬃcients).
Dynare will instead report theoretical moments. It may be necessary to increase it for highly autocorrelated processes (default = 512). have a look at Chapter 7.3. .8. • nofunctions: doesn’t print the coeﬃcients of the approximated solution (printing is the default). Details on implementing this appear below. please see the Reference Manual. For ﬁrst order linearizations. • nocorr: doesn’t print the correlation matrix (printing is the default). Dynare will return the actual sample moments from the simulations. • hp ngrid = INTEGER: number of points in the grid for the discreet Inverse Fast Fourier Transform used in the HP ﬁlter computation. For a complete list of options. since they get averaged between each Monte Carlo trial and in the limit should sum to zero. Note that in the case of a second order approximation. given their mean of zero. we focus on the application of the command and reproduce below the most common options that can be added to stoch simul. • drop = INTEGER: number of points dropped at the beginning of simulation before computing the summary statistics (default = 100). • irf = INTEGER: number of periods on which to compute the IRFs (default = 40). suppresses the plotting of IRF’s. SELECTING A COMPUTATION 29 on your results. • hp ﬁlter = INTEGER: uses HP ﬁlter with lambda = INTEGER before computing moments (default: no ﬁlter). If you’re interested to peer a little further into what exactly is going on behind the scenes of Dynare’s computations. Here instead. Options following the stoch simul command: • ar = INTEGER: Order of autocorrelation coeﬃcients to compute and to print (default = 5). TIP! thus you should make sure to specify suﬃcient periods in your IRFs such that you actually see your graphs return to steady state. the return to steady state is asymptotic. In both cases. Setting IRF=0. • relative irf requests the computation of normalized IRFs in percentage of the standard error of each shock. • dr algo = 0 or 1: speciﬁes the algorithm used for computing the quadratic approximation of the decision rules: 0 uses a pure perturbation approach as in SchmittGrohe and Uribe (2004) (default) and 1 moves the point around which the Taylor expansion is computed toward the means of the distribution as in Collard and Juillard (2001b).
mod ﬁle with the following command: stoch simul(periods=2100). and 50 otherwise). SOLVING DSGE MODELS .BASICS • nomoments: doesn’t print moments of the endogenous variables (printing them is the default). except if you ﬁx the seed for the random number generator. We would then end our . • qz criterium = INTEGER or DOUBLE: value used to split stable from unstable eigenvalues in reordering the Generalized Schur decomposition used for solving 1st order problems (default = 1. but a simulation only repeats the process once. TIP! A simulation is similar to running impulse response functions with a model linearized to the second order.30 CHAPTER 3. whereas impulse response functions run a multitude of Monte Carlo trials in order to get an average response of your system. • noprint: cancel any printing. unless you’re working with a linear model in which case the order is automatically set to 1.000001). If you linearized to a second order. Because of the simulation. usefull for loops. . Otherwise a diﬀerent sample is used for each run (default: seed not speciﬁed). you should at least try to run your program without using simul seed. are basically happy with all default options and want to carry out simulations over a good number of periods. • periods = INTEGER: speciﬁes the number of periods to use in simulations (default = 0). suppose we were interested in printing all the various measures of moments of our variables. Dynare will actually undertake Monte Carlo simulations to generate moments of your variables. want to see impulse response functions for all variables. just to check the robustness of your results. TIP! If you do decide to ﬁx the seed. • order = 1 or 2 : order of Taylor approximation (default = 2). Going back to our good old example. in the way that both sample shocks from their distribution to see how the system reacts. results are bound to be slightly diﬀerent each time you run your program. • simul seed = INTEGER or DOUBLE or (EXPRESSION): speciﬁes a seed for the random number generator so as to obtain the same random sample at each run of the program. • replic = INTEGER: number of simulated series used to compute the IRFs (default = 1 if order = 1.
3.07. initval. c = 0.1 The stochastic model var y c k i l y l w r z.95.MOD FILE 31 3. beta = 0. psi*c/(1l) = w. k = 9. z = 0.9. The ﬁles are called RBC Monop JFV.9 The complete . y l = y/l.33. . epsilon = 10.007/(1alpha)). 3. model. end. i = k(1delta)*k(1). y = (k(1)^alpha)*(exp(z)*l)^(1alpha).9. l = 0. sigma = (0.03. delta = 0.75. parameters beta psi delta alpha rho gamma sigma epsilon. e = 0.023. psi = 1. rho = 0. r = y*((epsilon1)/epsilon)*alpha/k(1). end.mod ﬁle For completion’s sake. r = 0.mod ﬁles corresponding to our example for the deterministic and stochastic case.mod for stochastic models and RBC Monop Det. c+i = y. w = 2. and for the pleasure of seeing our work bear its fruits. You can ﬁnd the corresponding ﬁles in the models folder under UserGuide in your installation of Dynare. (1/c) = beta*(1/c(+1))*(1+r(+1)delta).99.mod for deterministic models. varexo e. THE COMPLETE .3. here are the complete .76. z = rho*z(1)+e. alpha = 0. w = y*((epsilon1)/epsilon)*(1alpha)/l.
stoch simul(periods=2100). c+i = y. w = 2. parameters beta psi delta alpha sigma epsilon. initval. delta = 0. check.75.0. end. c = 0.3. beta = 0.32 CHAPTER 3. var e = sigma^2.7. end. alpha = 0. psi = 1. z = 0. w = y*((epsilon1)/epsilon)*(1alpha)/l. (1/c) = beta*(1/c(+1))*(1+r(+1)delta). y l = y/l. end. 3. sigma = (0. l = 0. model. k = 9. psi*c/(1l) = w. shocks. varexo z.023. steady.BASICS steady.9. SOLVING DSGE MODELS . . y = (k(1)^alpha)*(exp(z)*l)^(1alpha).33.007/(1alpha)).99. r = y*((epsilon1)/epsilon)*alpha/k(1). i = k(1delta)*k(1).2 The deterministic model (case of temporary shock) var y c k i l y l w r . r = 0. epsilon = 10.
1 Results . you should get two forms of output .. to execute your . dynare ExSolStoch. 3.mod). which is conveniently installed by default in the Dynare “examples” directory (the .). this may not be the case when testing the beta version of Matlab version 4) To run a .mod ﬁle. var z.10. (** note.mod ﬁle.stochastic models The tabular results can be summarized as follows: 1.mod ﬁle.1. As a result. and you should see a conﬁrmation of the BlanchardKahn conditions if you used the command check in your .mod ﬁles are stored. Running these . FILE EXECUTION AND RESULTS check. all you need to do is place your cursor in the Matlab command window and type. periods 1:9.. simul(periods=2100). You can do this by clicking in the “current directory” window of Matlab. . etc. Eigenvalues should be displayed. Once there.mod ﬁles should take at most 30 seconds. values 0. Model summary: a count of the various variable types in your model (endogenous. for instance.tabular in the Matlab command window and graphical in one or more popup windows. jumpers. shocks.mod ﬁle. let’s run our .3. end.mod ﬁle corresponding to the stochastic model is called RBC Monop JFV. 2. or typing the path directly in the top white ﬁeld of Matlab.10 File execution and results To see this all come to life.mod and that corresponding to the deterministic model is called RBC Monop Det. navigate within Matlab to the directory where the example . Let’s review these results.10. 33 3.
mod ﬁle.e.deterministic models Automatically displayed results are much more scarce in the case of deterministic models. In other words.BASICS 3. or make sure that your model is stationary. your model will probably not converge. show the actual impulse response functions for each of the endogenous variables.10. the function g is a time recursive (approximated) representation of the model that can generate timeseries that will approximatively satisfy the rational expectation hypothesis contained in the original model. you may want to try to increase the periods for the transition to the new steady state (the number of simulations . 3. 7. you should detrend your variables and rewrite your model in terms of those variables. and where gx is the ˆ ¯ ¯ partial derivative of the g function with respect to variable x. The graphical results. If you entered steady. Moments of simulated variables: up to the fourth moments. Details on the policy and transition function can be found in Chapter 6. 6. Matrix of covariance of exogenous shocks: this should square with the values of the shock variances and covariances you provided in the . instead. that your steady state actually exists and is stable. In Dynare. yt−1 . ut ) that could be plugged into the original model and satisfy the implied restrictions (the ﬁrst order conditions). the table “Policy and Transition function” contains the elements of gy and gu . 4. ut )] = 0 . TIP! You should see these errors decrease upon each iteration. If not. Et [f (yt+1 . yt .2 Results .34 CHAPTER 3. eigenvalues will also be displayed and you should receive a statement that the rank condition has been satisﬁed. means ﬁnding an unkown function. with ¯ ˆ yt = yt − y and y being the steadystate value of y. A ﬁrst order approximation of this function can be written as yt = y + gy yt−1 + gu ut . given that they actually moved. if all goes well! Finally. if not. Correlation of simulated variables: these are the contemporaneous correlations. SOLVING DSGE MODELS . 5. you will see some intermediate output: the errors at each iteration of the Newton solver used to estimate the solution to your model. These can be especially useful in visualizing the shape of the transition functions and the extent to which each variable is aﬀected. Autocorrelation of simulated variables: up to the ﬁfth lag. If so. TIP! If some variables do not return to their steady state. presented in a table. you will get a list of your steady state results. i. as speciﬁed in the options of stoch simul. yt = g(yt−1 . either check that you have included enough periods in your simulations. Policy and transition functions: Solving the rational exectation model. If you entered check.
But more often.10. it may be a good idea to revise your equations.1. you should start by looking at section 4.3 of chapter 4 on ﬁnding. it does not mean that you cannot create these by hand from Matlab.3. To do so. FILE EXECUTION AND RESULTS 35 periods). saving and viewing your output. . Of course. although Dynare does not display a rich set of statistics and graphs corresponding to the simulated output.
.
You can ﬁnd these. and/ or feel comfortable with. The second section overviews some of the inner workings of Dynare. The third section of the chapter focusses on modeling tips optimized for Dynare.Chapter 4 Solving DSGE models advanced topics This chapter is a collection of topics . To provide at least some consistency. In particular. such as dealing with correlated shocks. this chapter is divided into three sections.1. ﬁnding and saving your output. indivisible labor and investment speciﬁc technological change). along with helpful notes and explanations. the earlier chapter 3 on the basics of solving DSGE models.mod ﬁles used to generate impulse response functions are available on the Dynare website. Also.1 4. Jesus FernandezVillaverde has provided a series of RBC model variants (from the most basic to some including variable capacity utilization. The ﬁrst section deals directly with features of Dynare. but possibly also helpful for other work.that you will probably ﬁnd interesting or at least understandable. using loops. referring to external ﬁles and dealing with inﬁnite eigenvalues. don’t forget to check occasionally the Dynare contributions and examples forum to see if any other user has posted an example that could help 37 . if you have read.not all related to each other . 4. in the Oﬃcial Examples section of the Dynare website.1 Dynare features and functionality Other examples Other examples of . The goal is to provide a brief explanation of the ﬁles that are created by Dynare to help you in troubleshooting or provide a starting point in case you actually want to customize the way Dynare works.
as usual.1. and where at represents a stochastic technological shock (or Solow residual). the example provided is somewhat more complete than strictly necessary. Actually. The economy consists of an inﬁnitely living representative agent who values consumption ct and labor services ht according to the following utility function ∞ Et τ =t β τ −t h1+ψ log(ct ) − θ t 1+ψ where. where δ is physical depreciation and bt a shock aﬀecting incorporated technological progress. with 0 < α < 1. or maybe you would like to post an example there yourself? 4. Consumers are therefore also owners of the ﬁrms.38 CHAPTER 4. where part of output can be consumed and part invested to form physical capital. and these may be correlated to each other. This is to give you an alternative. It also aims to give you exposure to dealing with several correlated shocks. SOLVING DSGE MODELS . . The example below illustrates how you would introduce this into Dynare. the law of motion of capital is given by kt+1 = exp(bt )it + (1 − δ)kt with 0 < δ < 1. to learn the workings of Dynare. fullblown example to the one described in chapter 3. complete example The following example aims to give you an alternative example to the one in chapter 3.ADVANCED TOPICS you in your work. The model The model is a simpliﬁed standard RBC model taken from Collard and Juillard (2003) which served as the original User Guide for Dynare. the disutility of labor θ > 0 and the labor supply elasticity ψ ≥ 0. A social planner maximizes this utility function subject to the resource constraint ct + it = yt where it is investment and yt output. the discount factor 0 < β < 1. The economy is a real economy. We assume output is produced according to a standard constant returns to scale technology of the form α yt = exp(at )kt h1−α t with α being the capital elasticity in the production function. Your model may have two or more shocks.2 Alternative. As is standard.
This system . . we assume Et ( t ) = 0. Et (νt ) = 0 and that the contemporaneous variancecovariance matrix of the innovations t and νt is given by σ2 ψσ σν and where corr( t νs ) = 0.009. stderr 0. We will assume that you’re comfortable with these and simply present the ﬁnal . Note that the ﬁrst equation captures the labor supply function and the second the intertemporal consumption Euler equation.mod ﬁle below. stderr 0.mod ﬁle To “translate” the model into a language understandable by Dynare. var e.1.yields the following ﬁrst order conditions (which are straightforward to reproduce in case you have doubts. we would follow the steps outlined in chapter 3. That is at bt = ρ τ τ ρ at−1 bt−1 + t νt where ρ + τ  < 1 and ρ − τ  < 1 to ensure stationarity (we call ρ the coeﬃcient of persistence and τ that of crosspersistence). note that to introduce shocks into Dynare. though. Fist. we specify a shock structure that allows for shocks to display persistence across time and correlation in the current period. var u. var e. .009. .009*0. end. DYNARE FEATURES AND FUNCTIONALITY 39 Finally. Either write: shocks.009. Furthermore. corr( t s) ψσ σν 2 σν = 0 and corr(νt νs ) = 0 for all t = s. u = phi*0.4.probably quite similar to standard RBC models you have run into . we have two options (this was not discussed in the earlier chapter). ) and equilibrium conditions drawn from the description above. ct θh1+ψ = (1 − α)yt t 1 = βEt exp(bt )ct exp(bt+1 )ct+1 exp(bt+1 )α yt+1 +1−δ kt+1 α 1−α yt = exp(at )kt ht kt+1 = exp(bt )it + (1 − δ)kt at = ρat−1 + τ bt−1 + t bt = τ at−1 + ρbt−1 + νt The .
So that you can gain experience by manipulating the entire model. You can ﬁnd the corresponding ﬁle in the models folder under UserGuide in your installation of Dynare. psi = 0.95. alpha.36. here is the complete . initval. h. u.mod ﬁle corresponding to the above example.08068253095672. end. y = 1. tau. delta = 0. k. y = exp(a)*(k(1)^alpha)*(h^(1alpha)). u = phi*0. a = rho*a(1)+tau*b(1) + e. beta = 0. alpha = 0. tau = 0. var e = 0.025. k = beta*(((exp(b)*c)/(exp(b(+1))*c(+1))) *(exp(b(+1))*alpha*y(+1)+(1delta)*k)).99. c. theta. psi. a. you can also write: shocks. theta = 2.95. var e. b. . The ﬁle is called Alt Ex1.009. delta.009^2. Alternatively. phi = 0. SOLVING DSGE MODELS . c*theta*h^(1+psi)=(1alpha)*y.025.009^2.ADVANCED TOPICS where the last line speciﬁes the contemporaneous correlation between our two exogenous variables.80359242014163. varexo e. c = 0. b = tau*a(1)+rho*b(1) + u. var u = 0. rho = 0. end.40 CHAPTER 4. rho.mod. var y. model. k = exp(b)*(yc)+(1delta)*k(1). parameters beta.009*0.1.
41 4. a = 0. end. stoch simul(periods=2100). u = phi*0. and so on. DYNARE FEATURES AND FUNCTIONALITY h = 0.1. b = 0.1. and columns correspond to the variables lagged 1. • gamma y: the matrices of autocovariances.009. then lagged 2 for the second matrix. u = 0. for the ﬁrst matrix. e = 0.009. The last matrix (gamma y{7} in .009*0.4. the matrix of autocorrelations that is automatically displayed in the results after running stoch simul has. stderr 0. Dynare will return autocovariances with a lag of 5. the diagonal elements of each of the various autocorrelation matrices described here. Thus. running down each column. gamma y{1} represents variances. stderr 0. By default.29175631001732. k = 5. end. var u. var e. shocks. while gamma y{2} represents autocovariances where variables on each column are lagged by one period and so on.mod ﬁle): • steady state: the steady state of your variables • mean: the mean of your variables • var: the variance of your variables • autocorr: the various autocorrelation matrices of your variables.3 Finding. In global variable oo you will ﬁnd the following (NOTE! variables will always appear in the order in which you declared them in the preamble block of your . or using the workspace interface. var e.009. saving and viewing your output Where is output stored? Most of the moments of interest are stored in global variable oo You can easily browse this global variable in Matlab by either calling it in the command line. Each row of these matrices will correspond to a variables in time t.
The advantage of using Matlab.mat) command. where each column captures the independent contribution of each shock to the variance of each variable.mat.6 of chapter 3 when discussing steady states. if you decide to run impulse response functions. you can add the following command at the end of your .1. To save your simulated variables. The former is described in section 3. you should therefore do just as well to ask Dynare to compute your model’s steady state (except. for instance. as a result of the independent impulse of each exogenous shock. You could then retrieve the exogenous shocks from the oo ﬁle by saving them in a ﬁle called dataﬁle. For most usage scenarios. this is a bit of a workaround. . maybe. as the latter resorted to numerical approximations to ﬁnd steady state values. since you could also use the builtin commands in Dynare to generate impulse response functions from estimated shocks. But of course. to vary your parameter values. Dynare will save all endogenous variables.4 Referring to external ﬁles You may ﬁnd it convenient to refer to an external ﬁle.42 CHAPTER 4. 4.mod ﬁle: dynasave (FILENAME) [variable names separated by commas] If no variable names are speciﬁed in the optional ﬁeld. or when specifying shocks in an external ﬁle. to simulate a model based on shocks from a prior estimation. namely of specifying shocks in an external ﬁle. for instance. SOLVING DSGE MODELS . you could simulate a deterministic model with the shocks saved from the estimation by specifying the source ﬁle for the shocks. But Dynare version 4 now uses the same analytical methods available in Matlab. as described in chapter 5. Finally. in which case writing a Matlab program may be more handy).ADVANCED TOPICS the default case) returns the variance decomposition. either to compute the steady state of your model. to ﬁnd your model’s steady state was clear with respect to Dynare version 3. variables saved with the dynasave command can be retrieved by using the Matlab command load mat FILENAME. you will ﬁnd a global variable oo . reporting the values of the endogenous variables corresponding to the impulse response functions.irfs comprising of vectors named endogenous variable exogenous variable. like y e. say. if you want to run loops. But you may also be interested in the second possibility described above. using the shocks(shocks file = datafile. In Matlab. Furthermore.
They have no detrimental inﬂuence on the solution algorithm. model equations are translated into expression trees). Second (resp. you may get a message that there is an error in a ﬁle with a new name. “params”) vector. exogenous variables.mod ﬁle. Using a compiled C ﬁle is supposed to give better computing performance in model simulation/estimation. You may therefore ﬁnd it helpful to get a brief overview of the internal ﬁles that Dynare generates and the function of each one.mod”.out of curiosity or maybe to do some customization of your own. parameters) are contained in a “y” (resp. the preprocessor will output a C ﬁle (with . It is then compiled to create a library (DLL) ﬁle. (iii) outputting of several ﬁles. If the “use dll” option has been speciﬁed in the model declaration. notably the parameter initializations and the matlab calls corresponding to computing tasks • ﬁlename dynamic.2. “x”.m: a matlab ﬁle containing several instructions.c extension) rather than a matlab ﬁle. with an index number depending on the declaration order.1. FILES CREATED BY DYNARE 43 4. The “y” vector has as many entries as their are (variable. (ii) symbolic derivation of the model equations. Endogenous variables (resp. then the preprocessor creates the following ﬁles: • ﬁlename.m: a matlab ﬁle containing the model equations and their derivatives (ﬁrst. At that point.5 Inﬁnite eigenvalues If you use the command check in your . or you may want to have a closer look at how Dynare actually solves your model . lag) pairs in the declared model. The model equations residuals are stored in a vector named “residuals”. up to the needed order (depending on the computing needs).these are are ﬁrmly grounded in the theory of generalized eigenvalues. third) derivatives are in “g2” matrix (resp. . don’t worry if you get inﬁnite eigenvalues .4. “g3”). which are used from matlab. The dynare preprocessors essentially does three successive tasks: (i) parsing of the mod ﬁle (it checks that the mod ﬁle is syntactically correct). If the mod ﬁle is “ﬁlename. The model jacobian is put in “g1” matrix. and its translation into internal machine representation (in particular. 4. Dynare will report your system’s eigenvalues and tell you if these meet the BlanchardKahn conditions.2 Files created by Dynare At times. second and maybe third). As far as BlanchardKahn conditions are concerned inﬁnite eigenvalues are counted as explosive roots of modulus larger than one.
and needs particular care when working with Dynare. Used to compute the steady state. if yt is I(1). Replaced by a C ﬁle when “use dll” option is speciﬁed. you would need to apply the above manipulation to the entire equation. suppose your model included: ∞ β j xt+j = 0. where dyt = yt − yt−1 .m: a matlab ﬁle containing the stationarized version of the model (i. it is easier to work with the stationarized version of such models. not just a variable. Thus. If you expect to see a growing curve for a variable.3. as if yt were an equation. j=0 . More generally. Again. 4. Of course. Because growth models are nonstationary. you must ﬁrst stationarize your model. For example. For deterministic models. deﬁne st = Et [yt+1 ] and then use s(−1) in your . SOLVING DSGE MODELS . you are thinking about a growth model.3.1 Modeling tips Stationarizing your model Models in Dynare must be stationary. You can then reconstruct expost the nonstationary simulated variables after running impulse response functions. where lagged variables are replaced by current variables). the trick is to use only stationary variables in t + 1. because of Jensen’s inequality. If you do have nonlinear terms on which you want to take expectations in the past.3 Inﬁnite sums Dealing with inﬁnite sums is tricky in general. you can always add it back after the simulation of the stationary components of the variables. if you know the trend. The trick is to use a recursive representation of the sum.e. you need to know the value of dyt at the ﬁnal equilibrium. Same notations than the dynamic ﬁle. 4. either by hand.ADVANCED TOPICS • ﬁlename static. to enter the term Et−1 yt .3.44 CHAPTER 4. it is expected that variables will eventually go back to steady state after the initial shock. then linearize it.mod ﬁle. or by letting Dynare do the work. you can always write yt+1 as yt + dyt+1 . such that you can linearize them around a steady state and return to steady state after a shock. with its jacobian. Note that in a stationary model.2 Expectations taken in the past For instance. you cannot do this for terms that enter your equation in a nonlinear fashion.3 4. Note that. 4.
and mct is marginal cost as described in the example in chapter 3. of course. and Gertler (1999). S1 = pt S2. This is particularly helpful. S2t = yt + γS2t+1 . is instead typical of the new Keya nesian monetary literature. given that it will be able to reset its price only with probability 1 − θ each period. exempliﬁed by papers such as Clarida. for instance.3. Finally. thus implying the t following inﬂation relationship πt = (1 − θ)(p∗ − pt−1 ). The extension with sticky prices. is ∞ p∗ (i) = µ + (1 − βθ) t k=0 (βθ)k Et [mcn (i)] t+k where µ is the markup. ` la Calvo for instance. we can also t rewrite the optimal price setting equation. which can also be written in the following recursive manner: ∞ ∞ ∞ St ≡ j=0 β xt+j = xt + j=1 j β xt+j = xt + β j=0 j β j xt+1+j ≡ xt + St+1 This formulation turns out to be useful in problems of the following form: ∞ ∞ β xt+j = pt j=0 j=0 j γ j yt+j . is how to input this inﬁnite sum into Dynare? It turns out that the Calvo price setting implies that the aggregate price follows the equation of motion pt = θpt−1 + (1 − θ)p∗ . Gali. which can be written as a recursive system of the form: S1t = xt + βS1t+1 . β is a discount factor. in a Calvo type setting. MODELING TIPS 45 Note that the above can also be written by using an auxiliary variable St .4. The optimal price for a ﬁrm resetting its price in period t. as ∞ ∞ p∗ − pt−1 = (1 − βθ) t k=0 (βθ)k Et [mct+k ] + k=0 (βθ)k Et [πt+k ] . after some algebraic manipulations. The RBC model with monopolistic competition introduced in chapter 3 involved ﬂexible prices. as illustrated in the following brief example. i represents a ﬁrm of the continuum between 0 and 1. The trouble. deﬁned as: ∞ St ≡ j=0 β j xt+j .
we can go one step further and write the above as πt = βEt [πt+1 ] + λmct where λ ≡ (1−θ)(1−βθ) .46 CHAPTER 4. but for convenience.+Et−k xt . 4. by writing the right hand side as the ﬁrst term of the sum (with k = 0) plus the remainder of the sum. which can be written as the left hand side term scrolled forward one period and appropriately discounted. . . SOLVING DSGE MODELS . a diﬀerent approach than the one mentioned above is necessary. The trick now is to note that the above can be written recursively. deﬁned as the marginal cost when prices are perfectly ﬂexible. Mathematically. which is the recognizable inﬂation equation in the new θ Keynesian (or new Neoclassical) monetary literature.ADVANCED TOPICS where mct+k = mct+k +µ is the deviation of the marginal cost from its natural rate. In Dynare. as the index of the expectations changes with each element of the sum.3. this yields: p∗ − pt−1 = (1 − βθ)mct+k + πt + β θEt [p∗ − pt ] t t+1 which has gotten rid of our inﬁnite sum! That would be enough for Dynare. . as in the following example. such as: Et−1 xt +Et−2 xt +. Suppose your model included the following sum: ∞ yt = j=0 Et−j xt where yt and xt are endogenous variables. the best way to handle this is to write out the ﬁrst k terms explicitly and enter each one in Dynare.4 Inﬁnite sums with changing timing of expectations When you are not able to write an inﬁnite sum recursively.
the discount factor. but not necessarily to duplicate a “real life scenario” you would face when writing a paper.1 Introducing an example The example introduced in this chapter is particularly basic.Chapter 5 Estimating DSGE models basics As in the chapter 3. you can always move on to chapter 6 where you will ﬁnd a fullﬂedged replication of a recent academic paper. Instead. This chapter is therefore very practicallyoriented and abstracts from the underlying computations that Dynare undertakes to estimate a model. β. we thought it would be easiest to simply continue working with the example introduced in chapter 3 with which you are probably already quite familiar. there’s enough new material to keep you busy. though. the capital share of output. First. the goal of the example in this chapter is really to explain features in context. while more advanced topics of practical appeal are discussed in chapter 6. This is for two reasons. Second. The goal of this chapter is to lead you through the basic functionality in Dynare to estimate models using Bayesian techniques. We could then use Bayesian methods to estimate the parameters of the model: α. Once you feel comfortable with the content of this chapter. featuring a nonstationary model. 5. that subject is instead covered in some depth in chapter 8. so that by the end of the chapter you should have the capacity to estimate a model of your own. we did not want to introduce yet another example in this section. Recall from chapter 3 that we are dealing with an RBC model with monopolistic competition. Suppose also that we thought our little RBC model did a good job of reproducing reality. Suppose we had data on business cycle variations of output. this chapter is structured around an example. 47 .
ρ. c+i = y. 5.BASICS δ. w = y*((epsilon1)/epsilon)*(1alpha)/l.mod ﬁle. y l = y/l.mod ﬁle with: var y c k i l y l w r z. the markup parameter. our model block would look exactly as in chater 3: model. the depreciation rate.yielding posterior distributions identical to prior distributions . This is done exactly as described in chapter 3 on solving DSGE models. varexo e. parameters beta psi delta alpha rho epsilon. ESTIMATING DSGE MODELS . Let’s see how to go about doing this.2 Declaring variables and parameters To input the above model into Dynare for estimation purposes. the weight on leisure in the utility function. ρ. The alternative scenario with nonstationary variables is more complicated and dealt with in chapter 6 (in the additional example). 5.but the Bayesian estimation procedure would still run successfully. i = k(1delta)*k(1). We thus begin the . In the stationary case. It may be that this does not allow you to identify all your parameters . y = (k(1)^alpha)*(exp(z)*l)^(1alpha). we must ﬁrst declare the model’s variables in the preamble of the . the condition for undertaking estimation is that there be at least as many shocks as there are observables (a less stringent condition than for maximum likelihood estimation). and . The model’s variables would therefore be stationary and we can proceed without complications.3 Declaring the model Suppose that the equation of motion of technology is a stationary AR(1) with an autoregressive parameter. ψ.48 CHAPTER 5. the degree of persistence in productivity. . z = rho*z(1)+e. less than one. r = y*((epsilon1)/epsilon)*alpha/k(1). (1/c) = beta*(1/c(+1))*(1+r(+1)delta). psi*c/(1l) = w. Note that in Bayesian estimation.
Dynare must know which variables are observable for the estimation procedure. we must give it a hand by declaring approximate values for the steady state.5 Specifying the steady state Before Dynare estimates a model. as this chapter uses the same model as that outlined in chapter 3. as explained in section 5. in ﬁnding the posterior mode.4 Declaring observable variables This should not come as a surprise. based on the newest round of parameters available.6. covering the initval. the steady state block will look exactly the same. NOTE! These variables must be available in the data ﬁle. This is just as explained in details and according to the same syntax outlined in chapter 3. steady and check commands.mod ﬁle. it ﬁrst linearizes it around a steady state.5. Dynare recalculates the steady state of the model at each iteration of the optimization routine (more on this later). DECLARING OBSERVABLE VARIABLES end.7 below. are declared as a distribution. a steady state must exist for the model and although Dynare can calculate it. Priors. The general syntax to introduce priors in Dynare is the following: . Thus. by providing approximate initial values and relying solely on the builtin Dynare algorithm to ﬁnd the steady state (a numerical procedure). please refer to section 3. Dynare will end up spending 60 to 70% of the time recalculating steady states. 49 5. you will signiﬁcantly slow down the computation of the posterior mode. TIP! During estimation. 5. It is much more eﬃcient to write an external Matlab steady state ﬁle and let Dynare use that ﬁle to ﬁnd the steady state of your model by algebraic procedure. 5. In fact. we write: varobs y.3 of chapter 3. Thus.4. For the moment. in Bayesian estimation. For more details on writing an external Matlab ﬁle to ﬁnd your model’s steady state.6 Declaring priors Priors play an important role in Bayesian estimation and consequently deserve a central role in the speciﬁcation of the .
+∞) [p3 . PARAMETER NAME. PRIOR SHAPE. σ. you should declare them as such. σ) G2 (µ. you therefore have to put two empty spaces for parameters µ and σ. Note also that if some parameters in a model are calibrated and are not to be estimated.PRIOR 4th PARAMETER] . For instance. end. σ) U (p3 . on which side? You may also go one step further and build a distribution for each of your parameters in your mind. p4 ) Range R [p3 . . Then. First. ESTIMATING DSGE MODELS . p4 ) IG1 (µ. uniform pdf. TIP! Choosing the appropriate prior for your parameters is a tricky. think about the domain of your prior over each parameter. PRIOR 3rd PARAMETER] [. yet very important endeavor. say α. Should it be bounded? Should it be opened on either or both sides? Remember also that if you specify a probability of zero over a certain domain in your prior.BASICS estimated params. TIP! When specifying a uniform distribution between 0 and 1 as a prior for a parameter. For a more complete review of all possible options for declaring priors. you will necessarily also ﬁnd a probability of zero in your posterior distribution.1. p4 ] where µ is the PRIOR MEAN. as explained in chapter 3. Should it be symmetric? Skewed? If so. p3 is the PRIOR 3rd PARAMETER (whose default is 0) and p4 is the PRIOR 4th PARAMETER (whose default is 1). p3 ) B(µ. what is the probability that your parameter is bigger than a certain value. Some considerations may prove helpful. see the Reference Manual. and repeat the exercise by incrementally decreasing that value. by using the parameters command and its related syntax. since the uniform distribution only takes p3 and p4 as arguments. you would write alpha. It is worth spending time on your choice of priors and to test the robustness of your results to your priors. where the following table deﬁnes each term more clearly PRIOR SHAPE NORMAL PDF GAMMA PDF BETA PDF INV GAMMA PDF UNIFORM PDF Corresponding distribution N (µ. for instance. 0. PRIOR MEAN. Ask yourself. PRIOR STANDARD ERROR [. You can then pick the standard distribution that best ﬁts . think about the shape of your prior distribution. p4 ] R+ [p3 . and then specify parameters p3 and p4.50 CHAPTER 5. σ. p3 . σ is the PRIOR STANDARD ERROR. as well as the syntax to declare priors for maximum likelihood estimation (not Bayesian). .
002. 0. beta pdf. epsilon.normal pdf. end. as a Matlab expression. 0. 0. bet. end. TIP! It may at times be desirable to estimate a transformation of a parameter appearing in the model. than its inverse which often shows up in Euler equations.6. you are instead encouraged to visualize these distributions yourself.if the optimizer got stuck the ﬁrst time around. beta. by adding a pound sign (#) at the beginning of the corresponding line.75.025. 0. 0. beta pdf. 0. 0. c = sig*c(+1)*mpk. In such a case. gamma pdf.003. Thus you would write: model.02. inf. Coming back to our basic example. another useful command to use is the estimated params init command which declares numerical initial values for the optimizer when these are diﬀerent from the prior mean. 0. or needing a greater number of draws in the MetropolisHastings algorithm . end. β. 10.35.05. instead of describing here the shapes and properties of each standard distribution available in Dynare. 0.003. beta pdf. # sig = 1/bet. The Reference Manual gives more details as to the exact syntax of this command. DECLARING PRIORS 51 your perceived distribution.5. you may ﬁnd it easier to deﬁne a prior over the discount factor.99. 1.and wanting to enter the posterior mode as initial values for the parameters instead of a prior.1. gamma pdf. 0. 0. For example.05. estimated params.01. Finally. rather than the parameter itself.02. it is possible to declare the parameter to be estimated in the parameters statement and to deﬁne the transformation at the top of the model section. TIP! Finally.95. . stderr e. we would write: estimated params. delta.0. rho. psi. This is especially useful when redoing an estimation . alpha. inv gamma pdf. either in a statistics book or on the Web. beta pdf.
for instance. dataﬁle = FILENAME: the dataﬁle (a . 6. conf sig = {INTEGER — DOUBLE }: the level for the conﬁdence intervals reported in the results (default = 0. preﬁlter = 1: the estimation procedure demeans the data (default=0. a . 1. 2. 4. mh replic = INTEGER: number of replication for Metropolis Hasting algorithm. separated by commas. it is advisable to work with a higher value. But the real complexity comes from the options available for the command (to be entered in parentheses and sequentially. to divide the observations into subperiods. Despite this low default value. ﬁrst obs = INTEGER: the number of the ﬁrst observation to be used (default = 1). and encourage you to view the Reference Manual for a complete list. ESTIMATING DSGE MODELS . This is useful if model variables are in deviations from steady state. and variable names would show up in the ﬁrst cell of each column. or an . for instance.mod ﬁle.BASICS 5. one of the key criteria to evaluate the eﬃciency of the MetropolisHastings to evaluate the posterior distribution. we list the most common and useful options.xls ﬁle). and therefore have zero mean. after the command estimation).90) 7. such as 5 or more. but vectors of observations need to be named with the same names as those in var obs. all that is necessary is to add the command estimation at the end of the . This improves the computation of between group variance of the parameter means. nobs = INTEGER: the number of observations to be used (default: all observations in the ﬁle) 3. or instance. This is useful when running loops. Easy enough.7 Launching the estimation To ask Dynare to estimate a model. Demeaning the observations would also impose a zero mean on the observed variables. More details on this subject appear in Chapter 6. nograph: no graphs should be plotted. For the time being. Note that observations do not need to show up in any order. Below. . mh nblocks = INTEGER: number of parallel chains for Metropolis Hasting algorithm (default = 2). no preﬁltering).m ﬁle. mh replic should be larger than 1200 (default = 20000) 8. 5. In Excel ﬁles.52 CHAPTER 5. observations could be ordered in columns.mat ﬁle.
0: the mode isn’t computed. mh drop = DOUBLE: the fraction of initially generated parameter vectors to be dropped before using posterior simulations (default = 0. the literature has settled on a value of between 0.5. ideally. which would defeat the purpose of running several blocks of MetropolisHastings chains.7. Note that the acceptance rate drops if you increase the scale used in the jumping distribution and vice a versa. This is a particularly helpful option to speed up the estimation process if you have already undertaken initial estimations and have values of the posterior mode. mode ﬁle=FILENAME: name of the ﬁle containing previous value for the mode. . 4 (default): uses Chris Sim’s csminwel. When computing the mode.4. the iterations would get stuck in a subspace of the parameter range. mode compute=INTEGER: speciﬁes the optimizer for the mode computation.5. A clear indication of a problem would be that the mode is not at the trough (bottom of the minus) of the posterior distribution. while if it were too low. This is helpful to diagnose problems with the optimizer. This option must be tuned to obtain. 11. 12. Dynare plots the minus of the posterior density for values around the computed mode for each estimated parameter in turn. 2: uses Lester Ingber’s Adaptive Simulated Annealing. The default value is rarely satisfactory. this means that the ﬁrst half of the draws from the MetropolisHastings are discarded). your MetropolisHastings iterations would never visit the tails of a distribution. The idea here is to draw initial values from a stretched out distribution in order to maximize the chances of these values not being too close together. mh jscale = DOUBLE: the scale to be used for the jumping distribution in MH algorithm. The idea is not to reject or accept too often a candidate parameter.Hastings algorithm (default = 0. If the acceptance rate were too high.2). an acceptance rate of 25% in the Metropolis. 13. 14. mode ﬁle must be speciﬁed 1: uses Matlab fmincon (see the Reference Manual to set options for this command). 3: uses Matlab fminunc. 10. mh init scale=DOUBLE: the scale to be used for drawing the initial value of the MetropolisHastings chain (default=2*mh jscale). Dynare stores the mode (xparam1) and the hessian (hh) in a ﬁle called MODEL NAME mode.2 and 0. LAUNCHING THE ESTIMATION 53 9. mode check: when mode check is set.
More details on these diagnostics are given in Chapter 6. Again. TIP! If you stop the estimation procedure after calculating the posterior mode. bayesian irf: triggers the computation of the posterior distribution of impulse response functions (IRFs). ﬁltered vars: triggers the computation of the posterior distribution of ﬁltered endogenous variables and shocks. including the variance of the shocks. 17.if not already . either see the Reference Manual or section 3. If you instead carry out a full MetropolisHastings estimation. not smoothed variables. To view a list of these options. separated by commas. To calculate one period ahead prediction errors. for instance. Dynare pulls parameter and shock values from the corresponding estimated distributions and. you should use ﬁltered. Filtered shocks. The length of the IRFs are controlled by the irf option. ESTIMATING DSGE MODELS . or carry out maximum likelihood estimation. Repeating this process often enough generates a distribution of IRFs. smoother: triggers the computation of the posterior distribution of smoothed endogenous variables and shocks.BASICS 15. . Smoothed shocks are a reconstruction of the values of unobserved shocks over the sample. load mh ﬁle: when load mh ﬁle is declared. Dynare adds to previous MetropolisHastings simulations instead of starting from scratch.if not already . on the other hand. as speciﬁed in chapter 3 when discussing the options for stoch simul. 19. 18.in Dynare version 4. 16. See the note below on the diﬀerence between ﬁltered and smoothed shocks. are built only based on knowing past information. nodiagnostic: doesn’t compute the convergence diagnostics for MetropolisHastings (default: diagnostics are computed and displayed). 21. this is a useful option to speed up the process of estimation. ** will be implemented shortly . the IRFs will use the parameters the posterior distributions. moments varendo: triggers the computation of the posterior distribution of the theoretical moments of the endogenous variables as in stoch simul (the posterior distribution of the variance decomposition is also included).54 CHAPTER 5.in Dynare version 4.8 of chapter 3. using all the information contained in the sample of observations. To build the posterior distribution of the IRFs. Actually seeing if the various blocks of MetropolisHastings runs converge is a powerful and useful option to build conﬁdence in your model estimation. only the corresponding parameter estimates will be used to generate the IRFs. instead. ** will be implemented shortly . for each set of draws. generates an IRF. All options available for stoch simul can simply be added to the above options. 20.
Again. mode compute=6). . those necessary are reconstructed by sampling out of the posterior distribution of parameters.first obs=500. Of course. forecast = INTEGER: computes the posterior distribution of a forecast on INTEGER periods after the end of the sample used in estimation. Finally.mod. 5.mod ﬁle To summarize and to get a complete perspective on our work so far.mh jscale=0. as in bayesian irf.45. repeating this step often enough yields a posterior distribution of the forecast.nobs=200. except that the forecast does not begin at a steady state. The ﬁle is called RBC Est. we could choose a standard option: estimation(datafile=simuldataRBC. running a forecast is very similar to an IRF. mh replic=2000.mod ﬁle. The goal of undertaking a forecast is to see how the system returns to steady state from this starting point. You may therefore want to create a test version of your . This ends our description of the . Note that Dynare cannot forecast out of the posterior mode. coming back to our example. THE COMPLETE .5. Details on model solution and simulation can be found in Chapter 3.if not already . make sure you have steady and possibly check following the initval block if you do not have exact steady state values and run a simulation using stoch simul at the end of your .mod ﬁle. you would comment out or erase the commands related to estimation. In this test ﬁle. TIP! Before launching estimation it is a good idea to make sure that your model is correctly declared. ** will be implemented shortly .mod ﬁle.8. but simply at the point corresponding to the last set of observations. as observation do not exist for all variables. You can ﬁnd the corresponding ﬁle in the models folder under UserGuide in your installation of Dynare.mh nblocks=2. Finally.8.MOD FILE 55 22. You need to run MetropolisHastings iterations before being able to run forecasts on an estimated model.mod ﬁle for the estimation of our very basic model. add a shocks block.mh drop=0. remove the prior estimates for parameter values and replace them with actual parameter values in the preamble. that a steady state exists and that it can be simulated for at least one set of parameter values. The corresponding graph includes one conﬁdence interval describing uncertainty due to parameters and one conﬁdence interval describing uncertainty due to parameters and future shocks. here is the complete . remove any nonstationary variables from your model.in Dynare version 4.8 The complete .
varexo e. mh replic=2000. l = 0. beta pdf. end. 0. beta. estimated params. 0. z = rho*z(1)+e. psi. i = k(1delta)*k(1). end. mode compute=6).02. beta pdf.95. 0. inf. z = 0. 0.75. varobs y.35. gamma pdf. stderr e. 0. w = 2. check.8.first obs=500. beta pdf.3. . k = 9. model. inv gamma pdf. delta.mh jscale=0. beta pdf. (1/c) = beta*(1/c(+1))*(1+r(+1)delta). w = y*((epsilon1)/epsilon)*(1alpha)/l.003. y l = y/l.BASICS var y c k i l y l w r z.45. rho.mh drop=0. y = (k(1)^alpha)*(exp(z)*l)^(1alpha). c = 0.nobs=200. 0.mh nblocks=2. steady. ESTIMATING DSGE MODELS . 0.002. r = y*((epsilon1)/epsilon)*alpha/k(1).99. epsilon. alpha. 0. parameters beta psi delta alpha rho epsilon. initval. psi*c/(1l) = w.56 CHAPTER 5. 0. 10. e = 0. r = 0.0.025.02. end.003. estimation(datafile=simuldataRBC. 0. 1. c+i = y.01. gamma pdf.05. 0.7.
It may be entirely possible that you get an inﬁnite value for a standard deviation.5.2 Graphical results ** corresponding graphs will be reproduced below. The ﬁgure returns a graphical representation of the priors for each parameter of interest. On the basis of the options entered in the example . 5.9. as well as the prior distribution and standard deviation (pstdev).9 Interpreting output As in the case of model solution and simulation.9. Note the dummy values of 1 for the nonstationary variables Y obs and P obs. Dynare give the value of the objective function (the posterior Kernel) at the mode and displays two important table summarizing results from posterior maximization. Dynare will display the following results. The table of eigenvalues is completed with a statement about the BlanchardKahn condition being met . posterior mode.mod ﬁle. The improvement from one iteration to the next reaches zero. 5. probably erroneous when undertaking Bayesian estimation. Dynare returns both tabular and graphical output.9. The ﬁrst ﬁgure comes up soon after launching Dynare as little computation is necessary to generate it. standard deviation and tstat of the mode (based on the assumption of a Normal.hopefully! The next set of results are for the numerical iterations necessary to ﬁnd the posterior mode. It includes: prior means. as explained in more details in Chapter 6.1 Tabular results The ﬁrst results to be displayed (and calculated from a chronological standpoint) are the steady state results. INTERPRETING OUTPUT 57 5. this is simply the limit case of the inverse gamma distribution. The ﬁrst table summarizes results for parameter values. as opposed to standard maximum likelihood). It is followed by a second table summarizing the same results for the shocks. presented in the order in which the endogenous variables are declared at the beginning of the .mod ﬁle above. These results are followed by the eigenvalues of the system. .
Another approach is to undertake a greater number of MetropolisHastings simulations. you may have a problem of poor priors. try starting with a uniform and relatively wide prior and see where the data leads the posterior distribution. Dynare reports both the within and the between chains measures. being a measure of the variance and “m3” based on third moments. you can also . Note that the horizontal axis represents the number of MetropolisHastings iterations that have been undertaken.displays the most interesting set of results. And second. with results. For the results to be sensible. In fact.58 CHAPTER 5. In our example above. where MCMC stands for Monte Carlo Markov Chains. In each case. results between the various chains should be close.BASICS The second set of ﬁgures displays “MCMC univariate diagnostics”. It is advisable to redo the estimation with diﬀerent priors. The ﬁrst to last ﬁgure .ﬁgure 6 in our example . except that they reﬂect an aggregate measure based on the eigenvalues of the variancecovariance matrix of each parameter. More speciﬁcally. If you have trouble coming up with a new prior. each time starting from a diﬀerent initial value). Dynare reports three measures: “interval”. we obtain convergence and relative stability in all measures of the parameter moments. In addition. Dynare plots a green line which represents the posterior mode. ESTIMATING DSGE MODELS . these should be relatively constant (although there will always be some variation) and they should converge. or spot a problem. with the ﬁrst. If the results from one chain are sensible. grey lines). the red and blue lines on the charts represent speciﬁc measures of the parameter vectors both within and between chains. This is the main source of feedback to gain conﬁdence. being constructed from an 80% conﬁdence interval around the parameter mean. the ﬁgure compares the posterior to the prior distribution (black vs. First. “m2”. These allow you to make statements about your data other than simply concerning the mean and variance of the parameters. two things should happen. The ﬁgure entitled “multivariate diagnostic” presents results of the same nature. corresponding to the measure at the initial value of the MetropolisHastings iterations. and the vertical axis the measure of the parameter moments. towards which most of the computations undertaken by Dynare are directed: the posterior distribution. Recall that Dynare completes several runs of MetropolisHastings simulations (as many as determined in the option mh nblocks. on the posterior distribution. and the optimizer did not get stuck in an odd area of the parameter subspace. you can tell that indeed. This is the idea of what the MCMC diagnostics track. results within any of the however many iterations of MetropolisHastings simulation should be similar. TIP! If the plotted moments are highly unstable or do not converge.
the prior and the posterior distributions should not be excessively diﬀerent. the green mode (calculated from the numerical optimization of the posterior kernel) should not be too far away from the mode of the posterior distribution. .9. First. the posterior distributions should be close to normal. represents the number of periods in the sample. That is indeed the case for our example.5. The last ﬁgure returns the smoothed estimated shocks in a useful illustration to eyeball the plausibility of the size and frequency of the shocks. Third. The horizontal axis. or at least not display a shape that is clearly nonnormal. TIP! These graphs are of course especially relevant and present key results. Second. but they can also serve as tools to detect problems or build additional conﬁdence in your results. INTERPRETING OUTPUT 59 discuss the probability that your parameter is larger or smaller than a certain value. in this case. If not. One thing to check is the fact that shocks should be centered around zero. it is advisable to undertake a greater number of MetropolisHastings simulations.
.
and ends with a table summarizing where output series are stored and how these can be retrieved. We will then see in subsequent sections how to estimate it using Dynare. its basic intuitions and equations. The example shows how to use Dynare in a more realistic setting. while emphasizing techniques to deal with nonstationary observations and stochastic trends in dynamics. diﬃculties and solutions.1 Alternative and nonstationary example The example provided in chapter 5 is really only useful for illustration purposes. The chapter begins by presenting a more complex example than the one used for illustration purposes in chapter 5. So we thought you would enjoy (and continue learning from!) a more realistic example which reproduces the work in a recent . 6. with a special interest in model comparison.1 Introducing the example The example is drawn from Schorfheide (2000).1. This ﬁrst section introduces the model. The chapter then follows with sections on comparing models to one another. while the mathematics and economic intuitions of the model it evaluates are drawn from Nason and Cogley (1994). The goal is to show how Dynare would be used in the more “realistic” setting of reproducing a recent academic paper.Chapter 6 Estimating DSGE models advanced topics This chapter focusses on advanced topics and features of Dynare in the area of model estimation. and then to BVARs. That paper should serve as a helpful reference if anything is 61 . Note that the original paper by Schorfheide mainly focusses on estimation methodologies.academic paper.and highly regarded . 6.
In essence. Households maximize their utility function which depends on consumption. while dashed lines show the ﬂow of real variables. ﬁgure 6.62 CHAPTER 6. ﬁrms and banks (representing the ﬁnancial sector). Dt . the model studied by Schorfheide (2000) is one of cash in advance (CIA). Ht . Ct . So to clarify things. In the model. ESTIMATING DSGE MODELS .1. left unclear in the description below.t − 1 interest.1 sketches the main dynamics of the model. there are several markets and actors to keep track of. and hours worked. while deciding how much money to hold next period in cash. while observing only output and inﬂation. The goal of the paper is to estimate the model using Bayesian techniques. Mt+1 and how much to deposit at the bank. in order to earn RH.1: Continuous lines show the circulation of nominal funds. You may want to refer back to the ﬁgure as you read through the following sections. and a monetary authority which plays a minor role.ADVANCED TOPICS Figure 6. The economy is made up of three central agents and one secondary agent: households. Households .
next period’s capital stock.1. It uses these funds to disburse loans to ﬁrms. and where δ is the rate of depreciation. ﬁrms maximize the net present value of future dividends (discounted by the marginal utility of consumption.t Wt Nt ≤ Lt α where the second equation makes use of the production function Yt = Kt (At Nt )1−α and the real aggregate accounting constraint (goods market equilibrium) Ct + It = Yt . The third equation simply speciﬁes that bank loans are used to pay for wage costs. Nt .Lt } E0 ∞ Ft t+1 t=0 β Ct+1 Pt+1 α s. Bt are simply equal to Dt +RF. on their end. Lt . Of course. Ft ≤ Lt + Pt Kt (At Nt )1−α − Kt+1 + (1 − δ)Kt − Wt Nt − Lt RF. bank dividends.t Dt + Ft + Bt where the second equation spells out the cash in advance constraint including wage revenues. since they are owned by households) by choosing dividends.Ht . where It = Kt+1 − (1 − δ)Kt . Ft . by trading oﬀ investment for dividends to consumers.t. ALTERNATIVE AND NONSTATIONARY EXAMPLE therefore solve the problem max {Ct .6. Finally. the third the inability to borrow from the bank and the fourth the intertemporal budget constraint emphasizing that households accumulate the money that remains after bank deposits and purchases on goods are deducted from total inﬂows made up of the money they receive from last period’s cash balances. Mt+1 − Mt ). banks are constrained in their loans by a credit market equilibrium condition Lt ≤ Xt + Dt . Pt Ct ≤ Mt − Dt + Wt Ht Mt+1 = (Mt − Dt + Wt Ht − Pt Ct ) + RH. wages.Nt . Its problem is summarized by max {Ft . Note that it is the ﬁrms that engage in investment in this model.t. Ht = Nt and Pt Ct = Mt + Xt . and from banks. which in both cases are made up of net cash inﬂows deﬁned below. Xt from the central bank (which equals the net change in nominal money balances.t − 1. labor demand.Mt+1 .t Dt −Lt +Xt . Finally.t Lt −RH. as well as the condition that RH. receive cash deposits from households and a cash injection.t due to the equal risk proﬁles of the loans.Dt } 63 E0 ∞ t t=0 β [(1 − φ) ln Ct + φ ln(1 − Ht )] 0 ≤ Dt s. on which they make a net return of RF. To close the model. we add the usual labor and money market equilibrium equations. and loans. Bt . interests. . Kt+1 . as well as dividends from ﬁrms. Banks.Kt+1 .t = RF.
M.64 CHAPTER 6. the rate of growth of the series is a stationary stochastic process. This can be seen from the deﬁnition of mt which can be rewritten as ln Mt+1 = ln Mt + ln mt . We nonetheless give a brief intuitive explanation of each 1 Alternatively. we add a stochastic elements to the model. chapter 15. The model allows for two sources of perturbations. and the second an autoregressive stationary process in the growth rate of money.t . Note that theses expressions for trends are not written in the most straightforward manner nor very consistently. The ﬁrst equation is therefore a unit root with drift in the log of technology. These important equations are ln At = γ + ln At−1 + A. As usual.1 When the above functions are maximized.t 2 ∼ N (0. for details. but encourage you to browse Nason and Cogley (1994) for additional details.t 2 ∼ N (0. σA ) and ln mt = (1 − ρ) ln m∗ + ρ ln mt−1 + M. if the logs of a variable are speciﬁed to follow a unit root process.t . we obtain the following set of ﬁrst order and equilibrium conditions. Otherwise said. to save space.ADVANCED TOPICS More importantly. . but an AR(2) with a unit root in the log of the level of money. We will not dwell on the derivations here. see Hamilton (1994). But we reproduced them nevertheless to make it easier to compare this example to the original paper. A. one is a root of the second order autoregressive lag polynomial. ESTIMATING DSGE MODELS . one real. aﬀecting technology and one nominal. σM ) where mt ≡ MT +1 /Mt is the growth rate of the money stock. aﬀecting the money stock. we could have written the AR(2) process in state space form and realized that the system has an eigenvalue of one.
we pause a moment to give some intuition for the above equations. but instead represent variables that have been made stationary. and the marginal rate of substitution between consumption and leisure. . The intertemporal labor market optimality condition. 3.t+1 ) −1 A. The ﬁrms’ borrowing constraint. these equations correspond to: 1. linking labor supply. labor demand. importantly. also aﬀecting labor demand.t+1 ) 65 α−1 1−α Pt+1 αKt Nt+1 + (1 − δ) / ct+2 Pt+2 mt+1 Wt = Lt /Nt φ Ct Pt / (1 − Nt ) 1−φ −1 = Lt /Nt A. representing the tradeoﬀ to the economy of moving consumption goods across time. 2.t ) Yt /Yt−1 A.t+1 ) Rt = (1 − α)Pt e−α(γ+ Ct P t α Kt−1 Nt−α /Wt α Kt−1 Nt1−α = β (1 − α) Pt e−α(γ+ ×Et Lt mt Ct+1 Pt+1 A.t Pt /Pt−1 = (Pt /Pt−1 )(mt−1 /eγ+ ) where. We come back to this important topic in details in section 6. The system comes down to Et − Pt / Ct+1 Pt+1 mt = βe−α(γ+ A.t M. ALTERNATIVE AND NONSTATIONARY EXAMPLE equation.t ) α Kt−1 N 1−α + (1 − δ)e−(γ+ Kt−1 α Yt = Kt−1 N 1−α e−α(γ+ A. 4.3 below.1.t A.t ) Ct + Kt = e−α(γ+ Pt C = mt mt − 1 + Dt = Lt A.1.t ) ln(mt ) = (1 − ρ) ln(m ) + ρ ln(mt−1 ) + At ≡ dAt = exp(γ + At−1 Yt /Yt−1 = eγ+ A. The equilibrium interest rate in which the marginal revenue product of labor equals the cost of borrowing to pay for that additional unit of labor. The Euler equation in the goods market.6. hats over variables no longer mean deviations from steady state. In order. For now. as ﬁrms use borrowed funds to pay for labor input.
1. rho. and where the last ﬁve variables are deﬁned and explained in more details in the section below on declaring the model in Dynare. 6. Nt . the ﬁrst set of endogenous variables. parameters alp.1. real variables grow with At (except for labor. The money market equilibrium condition equating nominal consumption demand to money demand to money supply to current nominal balances plus money injection. It can be shown that when shocks are null. The Euler equation in the credit market.2 Declaring variables and parameters This block of the . The stochastic process for money growth. The stochastic process for technology. 11. mst. 6. varexo e a e m. The production function. The credit market equilibrium condition. The aggregate resource constraint. gam.ADVANCED TOPICS 5. where the choice of upper and lower case letters is not signiﬁcant. nominal variables grow with Mt and prices with Mt /At . 9. which ensures that giving up one unit of consumption today for additional savings equals the net present value of future consumption. 7. psi. The relationship between observable variables and stationary variables. bet. up to l. del.66 CHAPTER 6.mod ﬁle follows the usual conventions and would look like: var m P c e W R k d n l Y obs P obs y dA. are as speciﬁed in the model setup above. 6. 12. Detrending therefore involves .3 The origin of nonstationarity The problem of nonstationarity comes from having stochastic trends in technology and money. more details on these last two equations appear in the following section. which is stationary as there is no population growth). ESTIMATING DSGE MODELS . The nonstationarity comes out clearly when attempting to solve the model for a steady state and realizing it does not have one. 10. The exogenous variables are as expected and concern the shocks to the evolution of technology and money balances. 8.
kt+1 ].5 in chapter 3). ˆ variables. and leave the transformations of the remaining equations as an exercise.4 Stationarizing variables Let’s illustrate this transformation on output. Thus. A ﬁnal transformation to consider.1. where qt = [yt . lt . is to deﬁne dA = exp(gam+e a) by simply taking the exponential of both sides of the stochastic process of technology deﬁned in the model setup above. that in Dynare variables take the time subscript of the period in which they are decided (in the case of the capital stock.t )) where we go from the second to the third line by taking the exponential of both sides of the equation of motion of technology.6.mod ﬁle after transforming them in exactly the same way as the one above. And for prices.1. .mod ﬁle of Dynare into which we enter: y=k(1)^alp*n^(1alp)*exp(alp*(gam+e a)) The other equations are entered into the . we should actually work with Kt−1 = Kt−1 /At−1 . ALTERNATIVE AND NONSTATIONARY EXAMPLE 67 the following operations (where hats over variables represent stationary variables): for real variables. For nominal ˆ ˆ t = Qt /Mt . qt = qt /At . in the output equation. today’s capital stock is a result of yesterday’s decision). it . that turns out to be useful since we often deal with the growth rate of technology. We deﬁne Yt to equal Yt /At and Kt as Kt /At . where Qt = [dt . Wt ]. The above is the equation we retain for the . The resulting equation made up of stationary variables is Yt At = Kt−1 At−1 α 1−α At Nt1−α A−1 Aα t−1 t α Yt = Kt−1 Nt1−α At At−1 −α α = Kt−1 Nt1−α exp(−α(γ + A. Q 6. ct . We stationarize output by dividing its real variables (except for labor) by At . if you wish (Nason and Cogley (1994) includes more details on the transformations of each equation). NOTE! Recall from section 3. Pt = Pt ·At /Mt .
ADVANCED TOPICS 6. the observable variable would become Yt /Yt−1 . 6. we wewrite the above relationship in ratios. The details of the correct transformations for prices are left as an exercise and can be checked against the results below. but just a dAt .6 The resulting model block of the .mod ﬁle that relates the non stationary observables. we must make a decision as to our nonstationary observations.mod ﬁle model.68 CHAPTER 6. we add to the model block of the . Yt .1. c+k = exp(alp*(gam+e a))*k(1)^alp*n^(1alp)+(1del) . Thus. We could simply write Yobs = Yt At . R = P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(alp)/W. ESTIMATING DSGE MODELS .mod ﬁle: gy obs = dA*y/y(1).mod ﬁle. In the case of output. log(m) = (1rho)*log(mst) + rho*log(m(1))+e m. We of course do the same for prices. we therefore add: Y obs/Y obs(1) = dA*y/y(1). We would then have to relate this observable. to our stationary output. though.5 Linking stationary variables to the data And ﬁnally. we therefore follow this path in the remainder of the example. W = l/n. the y of the . The result is not very diﬀerent. P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(alp*(gam+log(e(+1))))*k^(alp1) *n(+1)^(1alp)+(1del)*exp((gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0. But since we don’t have an At variable. We could simply stationarize them by working with rates of growth (which we know are constant). 1/(c*P)bet*P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(1alp)/ (m*l*c(+1)*P(+1)) = 0. from what we just saw above. This complicates things somewhat. to our (stationary) model’s variables Yt by using the deﬁnition that Yt ≡ Yt /At . where.1. (psi/(1psi))*(c*P/(1n))+l/n = 0. To the . but illustrates several features of Dynare worth highlighting.mod ﬁle are the stationary Yt . our other observable variable. call them Yobs . call it gy obs. The goal is to add a line to the model block of our . But. except that we use the relationship Pobs = Pt Mt /At as noted earlier. we could also work with nonstationary data in levels. dA = exp(gam+e a).
of course. Y obs/Y obs(1) = dA*y/y(1). e = exp(e a). 6.8 Declaring trends in observable variables Recall that we decided to work with the nonstationary observable variables in levels. 6. This can be seen explicitly by taking the diﬀerence of logs of output and prices to compute growth rates. If we ﬁrst take logs. you must loglinearize your model (and not just linearize it). to specify that our observable variables are indeed P obs and Y obs as noted in the section above. the input conventions.mod ﬁle we write varobs P obs Y obs. though. they become linear and it doesn’t matter anymore where we calculate their derivative when taking a Taylor expansion of all the equations in the system. NOTE! Recall from earlier that the number of observed variables must be smaller or equal to the number of shocks such that the model be estimated.1. y = k(1)^alp*n^(1alp)*exp(alp*(gam+e a)). TIP! In the above model block. nonstationary. In our . Thus.7 Declaring observable variables We begin by declaring which of our model’s variables are observables. Both output and prices exhibit stochastic trends. after all. P obs/P obs(1) = (p/p(1))*m(1)/dA. In the case of output. P*c = m. If this is not the case. m1+d = l. ALTERNATIVE AND NONSTATIONARY EXAMPLE *exp((gam+e a))*k(1). 69 where. you should add measurement shocks to your model where you deem most appropriate.1.6. are the same as those listed in chapter 3. though. such as ending lines with semicolons and indicating the timing of variables in parentheses. concerning the observables which are. notice that what we have done is in fact relegated the nonstationarity of the model to just the last two equations. this is a point to which we will return later. is that we cannot linearize the above system in levels. end. when dealing with nonstationary observations. The problem that arises. we make use of the usual (by now!) . as the last two equations don’t have a steady state.1.
except for ln m∗ and γ. any trends. since P obs and Y obs inherit the unit root characteristics of their driving variables.t Note from the original equation of motion of ln mt that in steady state. The algorithm to compute a true diﬀuse prior is taken from Durbin and Koopman (2001). technology and money.mod unit root vars P obs Y obs. 6.9 Declaring unit roots in observable variables And ﬁnally. so that the drift terms in the above equation are ln m∗ − γ. 2 . we therefore write (in a somewhat cumbersome manner) observation trends. ln mt = ln m∗ . ESTIMATING DSGE MODELS .1.t emphasizing clearly the drift term γ. P obs (log(mst)gam). In general. end.t − γ − A. the command observation trends speciﬁes linear trends as a function of model parameters for the observed variables in the model. In the case of prices. Note that for stationary variables.ADVANCED TOPICS relationship Yt = Yt · At . Unit roots are only related to stochastic trends.t where all terms on the right hand side are constant. the unconditional covariance matrix of these variables is used for initialization. Taking logs of both sides and subtracting the same equation scrolled back one period. we ﬁnd: ∆ ln Yt = ∆ ln Yt + γ + A. In the case of our example. we apply the same manipulations to show that: ∆ ln Pt = ∆ ln Pt + ln mt−1 − γ − A. You don’t need to use a diﬀuse This can also be see from substituting for ln mt−1 in the above equation with the equation of motion of ln mt to yield: ∆ ln Pt = ∆ ln Pt + ln m∗ + ρ(ln mt−2 − ln m∗ ) + M. Y obs (gam). To give these instructions to Dynare.70 CHAPTER 6. we must tell Dynare to use a diﬀuse prior (inﬁnite variance) for their initialization in the Kalman ﬁlter. whether deterministic or stochastic (the drift term) must be declared up front. we write in the . NOTE! You don’t need to declare unit roots for any nonstationary model.2 In Dynare. whereas we know ∆ ln Yt is stationary in steady state.
0. 1. There are some things to notice. 0. Second. beta pdf. 0. 6.005. notice the declaration of parameters at the beginning. nothing has changed with respect to the equivalent ﬁle of chapter 5.002. So far.356. the output of the function is the endogenous variables at steady state. inv gamma pdf. gam. alp. mst. but tedious.1.5. beta pdf.035449. beta pdf. end.m. 6. 0. The check=0 limits steady state values to real numbers. P obs and Y obs which take the value of 1.1. 0. stderr e m. ALTERNATIVE AND NONSTATIONARY EXAMPLE 71 initial condition in the case of a deterministic trend.12 Launching the estimation We add the following commands to ask Dynare to run a basic estimation of our model: . The ﬁle is called fs2000ns steadystate.. 0. inv gamma pdf. 0. First. Third. 0.11 Declaring priors We expand our . beta pdf. inf.003. 0. beta pdf. 0. This is Dynare convention and must be the case for all your nonstationary variables.0085.223. 0. del.6. since the variance is ﬁnite. In this case. section 5. This functionality may be updated in later versions of Dynare. covering the initval.007. 0. intuitive. 6. the ys vector. deﬁning each variable in terms of parameters or variables solved in the lines above.10 Specifying the steady state Declaring the steady state is just as explained in details and according to the same syntax explained in chapter 3. steady and check commands.0002.02. you can ﬁnd the corresponding steady state ﬁle in the models folder under UserGuide. 0.1.993.129.1.008862. inf. 0. 0. stderr e a. bet.01.05.65. normal pdf.. The only novelty is the declaration of the nonstationary variables. note that the ﬁle is really only a sequential set of equalities. normal pdf. we also discussed the usefulness of providing an external Matlab ﬁle to solve for the steady state. psi.mod ﬁle with the following information: estimated params. rho. In chapter 5.
c+k = exp(alp*(gam+e a))*k(1)^alp*n^(1alp)+(1del) exp((gam+e a))*k(1). W = l/n. del. bet. varexo e a e m. P*c = m. y = k(1)^alp*n^(1alp)*exp(alp*(gam+e a)).mod.13 The complete . mode compute=6. mst. 6. m1+d = l. NOTE! As mentioned earlier. taking the log of the equations involving nonstationary variables does the job of linearizing them. var m P c e W R k d n l Y obs P obs y dA. log(m) = (1rho)*log(mst) + rho*log(m(1))+e m. Y obs/Y obs(1) = dA*y/y(1). psi. rho. we need to instruct Dynare to loglinearize our model.mod separately. e = exp(e a).mh nblocks=2. dA = exp(gam+e a). parameters alp. 1/(c*P)bet*P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(1alp)/ (m*l*c(+1)*P(+1)) = 0. since it contains nonlinear equations in nonstationary variables.45.mod ﬁle We have seen each part of the . Fortunately.ADVANCED TOPICS estimation(datafile=fsdat.nobs=192. ESTIMATING DSGE MODELS . it’s now time to get a picture of what the complete ﬁle looks like. P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*exp(alp*(gam+log(e(+1)))) *k^(alp1)*n(+1)^(1alp)+(1del) *exp((gam+log(e(+1)))))/(c(+2)*P(+2)*m(+1))=0. end. (psi/(1psi))*(c*P/(1n))+l/n = 0.1.mh replic=2000. A simple linearization would fail as these variables do not have a steady state.72 CHAPTER 6. P obs/P obs(1) = (p/p(1))*m(1)/dA. varobs P obs Y obs. R = P*(1alp)*exp(alp*(gam+e a))*k(1)^alp*n^(alp)/W.mh jscale=0. .loglinear.mh drop=0. the ﬁle also appears in the models folder under UserGuide in your Dynare installation.65). The ﬁle is called fs2000ns. model. gam. For convenience.
beta pdf. 0. initval.mh jscale=0. ALTERNATIVE AND NONSTATIONARY EXAMPLE observation trends.035449. 0. k = 6. 0.65.223. beta pdf. d = 0. alp.0085.6. 0. end.1.45. 0.6. gam. normal pdf. 0. 1.mh nblocks=2. estimated params. 0. P obs (log(mst)gam). 0.02.008862. unit root vars P obs Y obs. e = 1. m = mst.993.02. 0.25. normal pdf.05.loglinear. bet. 0. .005.mh replic=2000.85. stderr e m. c = 0. rho. since the estimation will use the Matlab // steady state file also provided and discussed above.45.007.nobs=192. 0. inf. W = 4. mst. stderr e a. inv gamma pdf. mode compute=6. 0. beta pdf.65). del. l = 0. estimation(datafile=fsdat. 0. 0. psi.01. Y obs (gam).0002. end. dA = exp(gam). end. inv gamma pdf.002. n = 0. P = 2. 73 // the above is really only useful if you want to do a stoch simul // of your model. 0.129. beta pdf. inf.mh drop=0.356. beta pdf.86. y = 0.19. R = 1.003. steady.
there are ﬁve basic steps to translate a model into Dynare for successful estimation.14 Summing it up The explanations given above of each step necessary to translate the Schorfheide (2000) example into language that Dynare can understand and process was quite lengthy and involved a slew of new commands and information. 6.74 CHAPTER 6.14. ESTIMATING DSGE MODELS .2: At a high level. and summarize the most important steps at a high level. It may therefore be useful.ADVANCED TOPICS Figure 6. 6.1. This is done in ﬁgure 6.1.2 Comparing models based on their posterior distributions ** TBD . to gain a “bird’s eyeview” on what we have just accomplished.
3.6. depending on the instructions you give Dynare. The Reference Manual overviews the complete set of potential output ﬁles and describes where you can ﬁnd each one. . WHERE IS YOUR OUTPUT STORED? 75 6.3 Where is your output stored? The output from estimation can be extremely varied.
.
If so. and when expectations are taken. 7. you may want to go through Michel Juillard’s presentation on solving DSGE models to a ﬁrst and second order (available on Michel Juillard’s website). or read Collard and Juillard (2001a) or SchmittGrohe and Uribe (2004) which gives a good overview of the most recent solution techniques based on perturbation methods. This is because only the ﬁrst moments of the shocks enter the linearized equations. 77 . see Juillard (1996). Thus. or will spur your curiosity to have a look at more detailed material.which is where the major complication lies. What you will ﬁnd below will either comfort you in realizing that Dynare does what you expected of it and what you would have also done if you had had to code it all yourself (with a little extra time on your hands!). Finally.1 Introduction The aim of this chapter is to peer behind the scenes of Dynare.2 What is the advantage of a second order approximation? As noted in chapter 3 and as will become clear in the section below. linearizing a system of equations to the ﬁrst order raises the issue of certainty equivalence. Going into details would be beyond the scope of this User Guide which will instead remain at a high level. they disappear.Chapter 7 Solving DSGE models Behind the scenes of Dynare 7. or under its hood. as explained in section 3. to get an idea of the methodologies and algorithms used in its computations. For more details on the NewtonRaphson algorithm used in Dynare to solve deterministic models.1.1 of chapter 3. note that in this chapter we will focus on stochastic models .
To summarize. This may be an acceptable simpliﬁcation to make.a highly desirable modeling feature. yt−1 . This is what we call the policy function. especially regarding second order approximations (available on Michel Juillard’s website). in the case of asset pricing models. The summary below is taken mainly from Michel Juillard’s presentation “Computing ﬁrst order approximations of DSGE models with Dynare”. when using second order welfare functions to compare policies. 7. ut ) .3 How does dynare solve stochastic DSGE models? In this section. yt . But depending on the context. linearizing to the second order enables you to take risk (or the variance of shocks) into consideration . Sticking to the above notation. SOLVING DSGE MODELS . although at a higher level of complexity. it may instead be quite misleading. which you should read if interested in particular details. ut )} = 0 E(ut ) = 0 E(ut ut ) = Σu and where: y : vector of endogenous variables of any dimension u : vector of exogenous stochastic shocks of any dimension The solution to this system is a set of equations relating variables in the current period to the past state of the system and current shocks. Yet more clearly. we shall brieﬂy overview the perturbation methods employed by Dynare to solve DSGE models to a ﬁrst order approximation. For instance. The second order follows very much the same approach.CHAPTER 7. that satisfy the original system. you also need second order approximations of the policy function. It is therefore very convenient that Dynare allows you to choose between a ﬁrst or second order linearization of your model in the option of the stoch simul command.BEHIND THE SCENES OF 78 DYNARE unconditional expectations of the endogenous variables are equal to their nonstochastic steady state values. a DSGE model is a collection of ﬁrst order and equilibrium conditions that take the general form: Et {f (yt+1 . we can write this function as: yt = g(yt−1 .
ut ). Taking expectations (we’re almost there!): Et F (1) (yt−1 . gy = ∂g ∂yt−1 . y . ut . g(yt−1 . ut+1 ) = Et f (¯. fy+ = ˆ ¯ fu = ∂f ∂ut . such that: F (yt−1 . ut+1 ) 79 We can then deﬁne a new function F . y ) + fy+ (gy (gy y + gu u)) y ¯ ¯ ˆ +fy0 (gy y + gu u) + fy− y + fu u ˆ ˆ = fy+ gy gy + fy0 gy + fy− y + fy+ gy gu + fy0 gu + fu u ˆ = 0 As you can see.7. fy0 = ∂f ∂yt . gu = ∂g ∂ut . ∂f ∂yt+1 . fy− = ∂f ∂yt−1 . y ) + fy+ gy (gy y + gu u) + gu u y ¯ ¯ ˆ +fy0 (gy y + gu u) + fy− y + fu u ˆ ˆ =0 with y = yt−1 − y . ut+1 ) = g(g(yt−1 . it is straightforward to rewrite yt+1 as yt+1 = g(yt . HOW DOES DYNARE SOLVE STOCHASTIC DSGE MODELS? Then. u = ut .3. y . y . ut . they drop out when taking expectations of the linearized equations. ut ) which enables us to rewrite our system in terms of past variables. 0) ¯ y The ﬁrst order Taylor expansion around y yields: ¯ Et F (1) (yt−1 . y . since future shocks only enter with their ﬁrst moments (which are zero in expectations). ut . ut+1 ) = f (¯. ut+1 ) = f (g(g(yt−1 . yt−1 . ut+1 ). ut ). ut . ut+1 )] = 0 We then venture to linearize this model around a steady state deﬁned as: f (¯. ut ). and current and future shocks: Et [F (yt−1 . u = ut+1 . 0) = 0 y ¯ ¯ having the property that: y = g(¯. This is technically why certainty equivalence holds .
The ﬁrst. Finally. one of the conditions that comes out of the solution of this equation is the BlanchardKahn condition: there must be as many roots larger than one in modulus as there are forwardlooking variables in the model.CHAPTER 7. Having recovered gy . The second order solution uses the same “perturbation methods” as above (the notion of starting from a function you can solve . we have solved for the (approximate) policy (or decision) function and have succeeded in solving our DSGE model. The second thing to note is that we have two unknown variables in the above equation: gy and gu each of which will help us recover the policy function g. we would simply iterate the policy function starting from an initial value given by the steady state. SOLVING DSGE MODELS . recovering gu is then straightforward from the second parenthesis. . which we can solve with a series of algebraic trics that are not all immediately apparent (but detailed in Michel Juillard’s presentation). Since the above equation holds for any y and any u. yields a quadratic equation in gy . But the general approach is perfectly isomorphic. Incidentally. Note that in the case of a second order approximation of a DSGE model. yet applies more complex algebraic techniques to recover the various partial derivatives of the policy function. for instance. the variance of future shocks remains after taking expectations of the linearized equations and therefore aﬀects the level of the resulting policy function. notice that a ﬁrst order linearization of the function g yields: yt = y + gy y + gu u ¯ ˆ And now that we have gy and gu . If we were interested in impulse response functions. each parenthesis must ˆ be null and we can solve each at a time.like a steady state and iterating forward).BEHIND THE SCENES OF 80 DYNARE in a system linearized to its ﬁrst order.
FernandezVillaverde and RubioRamirez (2004) which reviews the econometric properties of Bayesian estimators and compare estimation results with maximum likelihood and BVAR methodologies. some of these include: Schorfheide (2000) which uses Bayesian methods to compare the ﬁt of two competing DSGE models of consumption. 8. using the Kalman ﬁlter to ﬁnd the likelihood function. Lubik and Schorfheide (2003) which investigates whether central banks in small open economies respond to exchange rate movements. including deﬁning what are prior and posterior distributions. of four competing speciﬁcations of New Keynesian monetary models with nominal rigidities.1 Advantages of Bayesian estimation Bayesian estimation is becoming increasingly popular in the ﬁeld of macroeconomics. It begins by motivating Bayesian estimation by suggesting some arguments in favor of it as opposed to other forms of model estimation. and ﬁnally Rabanal and RubioRamirez (2005) which compares the ﬁt. this section surveys the methodologies adopted for Bayesian estimation. Ireland (2004) which emphasizes instead maximum likelihood estimation. Smets and Wouters (2003) which applies Bayesian estimation techniques to a model of the Eurozone. To do so. It then attempts to shed some light on what goes on in Dynare’s machinery when it estimates DSGE models. estimating the posterior function thanks to the MetropolisHastings algorithm.Chapter 8 Estimating DSGE models Behind the scenes of Dynare This chapter focuses on the theory of Bayesian estimation. Recent papers have attracted signiﬁcant attention. 81 . and comparing models based on posterior distributions. Lubik and Schorfheide (2005) which applies Bayesian estimation methods to an open macro model focussing on issues of misspeciﬁcation and identiﬁcation. based on posterior distributions.
Bayesian techniques allow the consideration of priors which work as weights in the estimation process so that the posterior distribution avoids peaking at strange points where the likelihood peaks. the inclusion of priors also helps identifying parameters. Indeed. This procedure. estimation in the Bayesian case is based on the likelihood generated by the DSGE system. leading to the “dilemma of absurd parameter estimates”. Likewise. St´phane Adjemian.CHAPTER 8. which can be interpreted as observation errors. if your model is entirely misspeciﬁed. Bayesian estimation explicitly addresses model misspeciﬁcation by including shocks. But the weighting of the likelihood with prior densities often leads to adding just enough curvature in the posterior distribution to facilitate numerical maximization. Bayesian estimation ﬁts the complete. the problem of identiﬁcation often arises. Second. rather than the more indirect discrepancy between the implied DSGE and VAR impulse response functions. the problem arises when the posterior distribution is ﬂat over a subspace of parameter values. in the structural equations. 8. ESTIMATING DSGE MODELS . as other topics mentioned above.2 The basic mechanics of Bayesian estimation This and the following subsections are based in great part on work by. First. a member of the Dynare development e . the posterior distribution corresponding to competing models can easily be used to determine which model best ﬁts the data. but ﬁve of these stand out as particularly important and general enough to mention here. Third. estimating it using Bayesian techniques could be a disadvantage. Of course. More technically. is discussed more technically in the subsection below. Unfortunately. Sixth. solved DSGE model.BEHIND THE SCENES 82 OF DYNARE There are a multitude of advantages of using Bayesian methods to estimate a model. when estimating a model. and discussions with. Indeed. It can be summarized by diﬀerent values of structural parameters leading to the same joint distribution for observables. the likelihood often peaks in regions of the parameter space that are contradictory with common observations. Bayesian estimation naturally leads to the comparison of models based on ﬁt. as opposed to GMM estimation which is based on particular equilibrium relationships such as the Euler equation in consumption. due to the stylized and often misspeciﬁed nature of DSGE models. Fourth.
mod ﬁles touching on Bayesian estimation. θ A represents the parameters of model A. priors can be seen as weights on the likelihood function in order to give more importance to certain areas of the parameter subspace. More technically. A) t=1 p(yt Yt−1 . which includes a clear and quite complete introduction to Bayesian estimation.are tied together by Bayes’ rule. p(•) stands for a probability density function (pdf) such as a normal. gamma. the posterior density. we have a prior density p(θ) on the one hand. a likelihood p(YT θ). beta. we are interested in p(θYT ). A) We now take a step back. Let’s see how. THE BASIC MECHANICS OF BAYESIAN ESTIMATION 83 team. At its most basic level. Some of this work. remember to also check the open online examples of the Dynare website for examples of . priors are described by a density function of the form p(θ A A) where A stands for a speciﬁc model. You may also want to take a glance at Hamilton (1994). inverse gamma. Generally speaking. Together. or uniform function. A) ≡ p(YT θ A . from example ﬁles to lecture notes to related papers. is available in the “Events” page of the Dynare website. Second. A) = p(y0 θ A . although somewhat outdated. introduction to the basic mechanics of Bayesian estimation. Using the Bayes theorem . A) where YT are the observations until period T . θ A . The tradition of calibrating models is inherited through the speciﬁcation of priors.priors and likelihood functions .2. illustrated by the application of a simple DSGE model. Bayesian estimation is a bridge between calibration and maximum likelihood. given the model and its parameters: L(θ A YT . generalized beta. Other helpful material includes An and Schorfheide (2006). these two building blocks . the likelihood function describes the density of the observed data. and on the other. In the end. First. the appendix of Schorfheide (2000) contains details as to the exact methodology and possible diﬃculties encountered in Bayesian estimation. Finally. And the maximum likelihood approach enters through the estimation process based on confronting the model with data. which provides a very clear. Also. and where in our case the likelihood is recursive and can be written as: T p(YT θ A . Finally. the websites of Frank Schorfheide and Jesus FernandezVillaverde contain a wide variety of very helpful material. although summarized in presentation format.8. shifted gamma. chapter 12.
YT ) = p(YT θ) × p(θ) p(θ) By using these identities. we can combine the prior density and the likelihood function discussed above to get the posterior density: p(θ A YT .T = 1 T T 1 T 2 t=1 (yt −µ) T t=1 yt ≡ y and that V[µM L.T ] = 1 T. Generally. corresponds to the numerator of the posterior density: p(θ A YT .an example Suppose a data generating process yt = µ + εt for t = 1. Before moving on. A)p(θ A A) ≡ K(θ A YT . . though. chapter 12. 8. 1) is gaussian white noise. YT ) ⇔ p(θ. A) ∝ p(YT θ A . ESTIMATING DSGE MODELS . YT A)dθ A Finally. A)p(θ A A) p(YT A) where p(YT A) is the marginal density of the data conditional on the model: p(YT A) = ΘA p(θ A . the subsection below gives a simple example based on the above reasoning of what we mean when we say that Bayesian estimation is “somewhere in between calibration and maximum likelihood estimation”. given that the marginal density above is a constant or equal for any parameter). A) = p(YT θ A . T . although other similar examples can be found in Hamilton (1994).1 Bayesian estimation: somewhere between calibration and maximum likelihood estimation . YT ) p(θYT ) = p(YT ) We also know that p(YT θ) = p(θ. the posterior kernel (or unnormalized posterior density. .BEHIND THE SCENES 84 OF DYNARE twice we obtain this density of parameters knowing the data. where εt ∼ N (0.CHAPTER 8. These topics are covered in more details below. The trick will be to estimate the likelihood function with the help of the Kalman ﬁlter and then simulate the posterior kernel using a samplinglike or Monte Carlo method such as the MetropolisHastings.2. we have p(θ. Then. the likelihood is given by p(YT µ) = (2π)− 2 e− 2 We know from the above that µM L. The example is drawn from Zellner (1971).. A) This is the fundamental equation that will allow us to rebuild all posterior moments of interest...
In more appropriate terms for what follows. the posterior density is deﬁned. p (µYT ) ∝ e − (µ−E[µ])2 V[µ] . DSGE MODELS AND BAYESIAN ESTIMATION 85 In addition. Then.3 8. the 2 maximum likelihood estimator. the prior mean. y is the vector of steady ˆ ¯ state values and θ the vector of deep (or structural) parameters to be estimated. which is really a collection of ﬁrst order and equilibrium conditions. we have no prior information. Most of the time. can be written in the form Et {f (yt+1 . let our prior be a gaussian distribution with expectation µ0 2 and variance σµ . In particular. ut )} = 0.1 DSGE models and Bayesian estimation Rewriting the solution to the DSGE model Recall from chapter 7 that any DSGE model. if σµ → ∞ (ie. Other variables are described below. we can rewrite the solution to a DSGE model as a system in the following manner: ∗ yt = M y (θ) + M yt + N (θ)xt + ηt ¯ ˆ yt = gy (θ)ˆt−1 + gu (θ)ut ˆ y E(ηt ηt ) = V (θ) E(ut ut ) = Q(θ) where yt are variables in deviations from steady state.3. yt−1 . But the equation expresses a relationship among true endogenous variables that ∗ are not directly observed.T + σµ µ0 T −2 1 −1 + σµ T From this. But if σµ → 0 (ie. The second equation is the familiar decision rule mentioned above.T . we can tell that the posterior mean is a convex combination of 2 the prior mean and the ML estimate.8. taking as a solution equations of the type yt = g(yt−1 . yt . so we just estimate the model) then E[µ] → µM L. 8.3. thus leaving no room for estimation) then E[µ] → µ0 . with 1 −2 + σµ V[µ] = and E[µ] = 1 −1 T 1 −1 −2 µM L. ut ). which we call the decision rule. and it is related to the true . up to a constant. Only yt is observable. by: p (µYT ) ∝ 1 1 − 2 (2πσµ )− 2 e 2 (µ−µ0 )2 2 σµ × (2π)− 2 e− 2 T 1 T 2 t=1 (yt −µ) Or equivalently. we’re sure of ourselves and we calibrate the parameter of interest. we’re somewhere in the middle of these two extremes.
respectively. From the Kalman ﬁlter recursion. is that the equations are non linear in the deep parameters. 8. V (θ) and ∗ ∗ Q(θ) and where YT expresses the set of observable endogenous variables yt found in the measurement equation.BEHIND THE SCENES 86 OF DYNARE variables with an error ηt . it may have a trend. The second. Furthermore. The loglikelihood above gets us one step closer to our goal of ﬁnding the posterior distribution of our parameters. recall. The ﬁrst apparent problem. Yet. .CHAPTER 8. The ﬁrst and second equations above therefore naturally make up a system of measurement and transition or state equations. though. the log posterior kernel can be expressed as ∗ ∗ ln K(θYT ) = ln L (θYT ) + ln p(θ) where the ﬁrst term on the right hand side is now known after carrying out the Kalman ﬁlter recursion. as is typical for a Kalman ﬁlter (you guessed it. Indeed. . . are the priors. they are linear in the endogenous and exogenous variables so that the likelihood may be evaluated with a linear prediction error algorithm like the Kalman ﬁlter. it is possible to derive the loglikelihood given by T Tk 1 1 ∗ ln L (θYT ) = − ln(2π) − Ft  − vt Ft−1 vt 2 2 2 t=1 where the vector θ contains the parameters we have to estimate: θ. T and with initial values y1 and P1 given.3. it’s not a coincidence!). As a reminder. chapter 13. which is captured with N (θ)xt to allow for the most general case in which the trend depends on the deep parameters. This is exactly what Dynare does. here’s what the Kalman ﬁlter recursion does. For t = 1. and are also known. see Hamilton (1994).2 Estimating the likelihood function of the DSGE model The next logical step is to estimate the likelihood of the DSGE solution system mentioned above. . ESTIMATING DSGE MODELS . the recursion follows ∗ vt = yt − y ∗ − M yt − N xt ¯ ˆ Ft = M Pt M + V Kt = gy Pt gy Ft−1 yt+1 = gy yt + Kt vt ˆ ˆ Pt+1 = gy Pt (gy − Kt M ) + gu Qgu For more details on the Kalman ﬁlter. .
Draw a proposal θ ∗ from a jumping distribution J(θ ∗ θ t−1 ) = N (θ t−1 . and run a loop over 234. to samplinglike methods. The algorithm. This allows for an eﬃcient exploration of the posterior distribution at least in the neighborhood of the mode” (An and Schorfheide (2006). It is a “rejection sampling algorithm” used to generate a sequence of samples (also known as a “Markov Chain” for reasons that will become apparent later) from a distribution that is unknown at the outset. we are now in a position to ﬁnd the posterior distribution of our parameters. 18).3.8. More precisely. but fortunately doable with modern computers. we cannot obtain an explicit form for it. cΣm ) where Σm is the inverse of the Hessian computed at the posterior mode. This is indeed the method adopted by Dynare. where this is typically the posterior mode. This is done in Dynare using numerical methods. “constructs a Gaussian approximation around the posterior mode and uses a scaled version of the asymptotic covariance matrix as the covariance matrix for the proposal distribution. instead. Remember that all we have is the posterior mode. To do so. The distribution will be given by the kernel equation above. but again.3.a key parameter and an important output of Dynare . 8. p. to ﬁnd the mode of the posterior distribution . Thus. The general idea of the MetropolisHastings algorithm is to simulate the posterior distribution. the MetropolisHastings algorithm implements the following steps: 1. in the words of An and Shorfheide. . Thus. 2. of which the MetropolisHastings has been retained in the literature as particularly eﬃcient.3.4 Estimating the posterior distribution Finally. it is a nonlinear and complicated function of the deep parameters θ. this maximization problem is not completely straightforward.3 Finding the mode of the posterior distribution Next. Choose a starting point θ ◦ . DSGE MODELS AND BAYESIAN ESTIMATION 87 8.we simply maximize the above log posterior kernel with respect to θ. we are instead more often interested in the mean and variance of the estimators of θ. the algorithm builds on the fact that under general conditions the distribution of the deep parameters will be asymptotically normal. We resort. Recall that the likelihood function is not Gaussian with respect to θ but to functions of θ as they appear in the state equation.
build a histogram of those retained values. Compute the acceptance ratio r= K(θ ∗ YT ) p(θ ∗ YT ) = p(θ t−1 YT ) K(θ t−1 YT ) 4. the acceptance rate (the fraction of candidate parameters that are accepted in a window of time) will be too high and the Markov Chain of candidate parameters will “mix slowly”. Figure 8. just in case using that candidate for the mean of the drawing distribution allows us to to leave a local maximum and travel towards the global maximum. θ∗ from a Normal distribution. notice that in fact you would keep your candidate only with a probability less than one). Of course. Finally accept or discard the proposal θ ∗ according to the following rule. On the other hand. If the scale factor is too small. go back to the candidate of last period (this is true in very coarse terms. We should not be too quick to simply throw out the candidate giving a lower value of the posterior kernel. This “smoothed histogram” will eventually be the posterior distribution after suﬃcient iterations of the above steps. ESTIMATING DSGE MODELS . if the scale factor is too large.4 tries to clarify the above. and compare it to the value of the kernel from the mean of the drawing distribution. an important parameter in this searching procedure is the variance of the jumping distribution and in particular the scale factor. 1) otherwise. the acceptance rate will be very low (as the candidates are likely to land in regions of low probability density) and the chain will spend too much . whose mean has been set to θt−1 (this will become clear in just a moment). in the ﬁnal step. compute the value of the posterior kernel for that candidate parameter. Of course. If the acceptance ratio is greater than one. and update. meaning that the distribution will take a long time to converge to the posterior distribution since the chain is likely to get “stuck” around a local maximum. the jumping distribution: θt = θ∗ θ t−1 with probability min(r. then deﬁnitely keep your candidate.3.CHAPTER 8. and note the value of the parameter your retain. the idea is to allow the search to turn away from taking a small step up. In step 3. if necessary. But why have such a complicated acceptance rule? The point is to be able to visit the entire domain of the posterior distribution. do two things. the point is for each “bucket” of the histogram to shrink to zero. Update the mean of your drawing distribution. and instead take a few small steps down in the hope of being able to take a big step up in the near future. After having repeated these steps often enough. In step 1. Metaphorically. Otherwise. Then. choose a candidate paramter.BEHIND THE SCENES 88 OF DYNARE 3. In step 2. decide whether or not to hold on to your candidate parameter.
3.8. Imagine repeating these steps a large number of times. While these steps are mathematically clear. used to build the posterior distribution function. DSGE MODELS AND BAYESIAN ESTIMATION 89 Figure 8. and smoothing the “histogram” such that each “bucket” has inﬁnitely small width. time in the tails of the posterior distribution.7 of Chapter 5. . several practical questions arise when carrying out Bayesian estimation.1: The above sketches the MetropolisHastings algorithm. at least to a machine needing to undertake the above calculations. These include: How should we choose the scale factor c (variance of the jumping distribution)? What is a satisfactory acceptance rate? How many draws are ideal? How is convergence of the MetropolisHastings iterations assessed? These are all important questions that will come up in your usage of Dynare. They are addressed as clearly as possible in section 5.
Then.4 Comparing models using posterior distributions As mentioned earlier. while touting the advantages of Bayesian estimation. is the Gaussian (called a Laplace approximation). This requires some detailed explanations of their own. where I = A. B p(IYT ) = p(I)p(YT I) I=A. For each model I = A. Let’s look at an illustration.CHAPTER 8. especially for large samples. Suppose we have a prior distribution over two competing models: p(A) and p(B). YT θ I . we can compute the posterior distribution over models. I)dθ I = ΘI p(θ I I) × p(YT θ I . To remind you of this. To obtain the marginal density of the data conditional on the model. the comparison of the two models is done very naturally through the ratio of the posterior model distributions. specifying the basic mechanics of Bayesian estimation. In this case. p(YT I). B we can evaluate. I)p(θ m I) I I I where θ m is the posterior mode. which is also the denominator of the posterior density p(θYT ) discussed earlier. We call this the posterior odds ratio: p(AYT ) p(A) p(YT A) = p(BYT ) p(B) p(YT B) The only complication is ﬁnding the magrinal density of the data conditional on the model. at least theoretically. The most straightforward and the best approximation. the marginal density of the data conditional on the model by integrating out the deep parameters θ I from the posterior kernel: p(YT I) = ΘI p(θ I . the posterior distribution oﬀers a particularly natural method of comparing models. The ﬁrst is to assume a functional form of the posterior kernel that we can integrate.BEHIND THE SCENES 90 OF DYNARE 8. Using Bayes’ rule.B p(I)p(YT I) where this formula may easily be generalized to a collection of N models. there are two options. we would have the following estimator: p(YT I) = (2π) 2 Σθm  2 p(θ m YT . I)dθ I Note that the expression inside the integral sign is exactly the posterior kernel. you may want to glance back at the ﬁrst subsection above. ESTIMATING DSGE MODELS . The advantage of this technique is its comI putational eﬃciency: time consuming MetropolisHastings iterations are not k 1 .
8.4. COMPARING MODELS USING POSTERIOR DISTRIBUTIONS 91 necessary, only the numerically calculated posterior mode is required. The second option is instead to use information from the MetropolisHastings runs and is typically referred to as the Harmonic Mean Estimator. The idea is to simulate the marginal density of interest and to simply take an average of these simulated values. To start, note that p(YT I) = E f (θ I ) θI , I p(θ I I)p(YT θ I , I)
−1
where f is a probability density function, since E f (θ I ) θI , I = p(θ I I)p(YT θ I , I)
ΘI ΘI
f (θ)dθ
p(θ I I)p(YT θ I , I)dθ I
and the numerator integrates out to one (seeGeweke (1999) for more details). This suggests the following estimator of the marginal density 1 p(YT I) = B
(b) B (b) b=1
f (θ I ) p(θ I I)p(YT θ I , I)
(b)
(b)
−1
where each drawn vector θ I comes from the MetropolisHastings iterations and where the probability density function f can be viewed as a weights on the posterior kernel in order to downplay the importance of extreme values of θ. Geweke (1999) suggests to use a truncated Gaussian function, leading to what is typically referred to as the Modiﬁed Harmonic Mean Estimator.
Chapter 9
Optimal policy under commitment
93
.
Thanks for your precious help! 95 .Chapter 10 Troubleshooting To make sure this section is as user friendly as possible. how Dynare tells you about it and how you solve it. the best is to compile what users have to say! Please let me know what your most common problem is with Dynare.
.
Hamilton. F.” Computational Economics.. Koopman (2001): Time Series Analysis by State Space Methods.” Journal of Economic Literature. R. 25(67). Development and Communication. A practical guide. 18(1).” Journal of Econometrics. 1–126.” Journal of Economic Dynamics and Control.. and F.” CEPREMAP mimeo. and S. (2003): “Stochastic simulations with DYNARE. Princeton University Press. Gali. and J. (1999): “Using Simulation Methods for Bayesian Econometric Models: In. Forthcoming. Oxford University Press. (1996): “Dynare : a program for the resolution and simulation of dynamic models with forward variables through the use of a relaxation algorithm. J. Juillard. 17(23). CEPREMAP. Durbin. (2001b): “A HigherOrder Taylor Expansion Approach to Simulation of Stochastic ForwardLooking Models with an Application to a Nonlinear Phillips Curve Model. Juillard (2001a): “Accuracy of stochastic perturbation methods: The case of asset pricing models. J.” Econometric Review. 1661–1707. (1994): Time Series Analysis.” Journal of Economic Dynamics and Control. Ireland. M. Gertler (1999): “The Science of Monetary Policy: A New Keynesian Perspective.. FernandezVillaverde. 153–187. J. D. and M. 1205–1226.” Econometric Review.. U. (2004): “A method for taking models to the data. Clarida. Geweke. 123(1). NJ.ference. Oxford. RubioRamirez (2004): “Comparing dynamic equilibrium models to data: a Bayesian approach. Collard. and M. Schorfheide (2006): “Bayesian Analysis of DSGE Models. N. 979–999. 28(6). F.. 97 . S. J. J. 125–39.Bibliography An. P. XXXVII..” CEPREMAP working papers 9602.K. Princeton.
Schorfheide (2003): “Do Central Banks Respond to Exchange Rate Movements? A Structural Investigation. P.” Journal of Applied Econometrics. 15(6). RubioRamirez (2005): “Comparing New Keynesian models of the business cycle: A Bayesian approach. SchmittGrohe.. and T.” Economics Working Paper Archive 505.” Economics Working Paper Archive 521. (2005): “A Bayesian Look at New Open Economy Macroeconomics. S37–70. New York. F. (2000): “Loss functionbased evaluation of DSGE models. F. Schorfheide. J.98 BIBLIOGRAPHY Lubik.. .. John Wiley & Sons. Zellner.Department of Economics. 1123–1175. The Johns Hopkins University. and R. Smets. S. 645–670.” Journal of Applied Econometrics. 1(5). 755–775.. Wouters (2003): “An Estimated Dynamic Stochastic General Equilibrium Model of the Euro Area.Department of Economics. Rabanal. Inc. and F. Uribe (2004): “Solving dynamic general equilibrium models using a secondorder approximation to the policy function. Cogley (1994): “Testing the Implications of LongRun Neutrality for Monetary Business Cycle Models.. 28(4).” Journal of Economic Dynamics and Control. 52(6). Nason.. F. The Johns Hopkins University. M. (1971): An Introduction to Bayesian Inference in Econometrics.” Journal of Monetary Economics. 9(S). and M. and J. 1151–1166. T. A.” Journal of the European Economic Association.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue reading from where you left off, or restart the preview.