Upload
hoangnhu
View
225
Download
3
Embed Size (px)
Citation preview
Lecture 2A simple quantitative exercise using dynare
Prof. Michael WeberUniversity of Chicago Booth School of Business
September 16, 2015
1 )
Lecture Outline
I Introduction to Dynare
I Simple Neoclassical Model
I Writing Dynare Code
I Running Dynare
I Dynare output
2 )
Introduction to Dynare
3 )
Installation
I Today: solve and simulate DSGE model using Dynare
I In general: also estimation using MLE and Baysian MLE
I Dynare: collection of Matlab and C++ codes
I Core development team at CEPREMAP
I Freely available at: http://www.dynare.org/download
I Read instruction in readme file to add Dynare to Matlab
4 )
Simple Neoclassical Model
5 )
Planner’s Problem
I Neoclassical model with fixed labor. Planner’s problem:
max E0
∞∑t=0
βtc1−σ − 1
1 − σ
s.t. kt+1 = atkαt − ct + (1 − δ)kt
ln at = ρ ln at−1 + εt
6 )
First-order Conditions
c−σt = βEtc−σt+1(at+1αk
α−1t+1 + (1 − δ))
kt+1 = atkαt − ct + (1 − δ)kt
ln at = ρ ln at−1 + εt
limt→∞
= βtc−σt kt+1
7 )
Static Equations
I Output from production function
yt = atkαt
I Investment from market clearing
it = yt − ct
8 )
Prices in Decentralized Economy
I Real interest rate:
c−σt = βEtc−σt+1(1 + rt)
I Real rental rate on capital:
Rt = αatkα−1t
I Real wage:
wt = (1 − α)atkt
9 )
Choice of Parameter Values
σ = 1
α = 1/3
δ = 0.025
β = 0.99
ρ = 0.95
σa = 0.01
10 )
Writing Dynare Code
11 )
General Structure
I Preamble
I Declaration of endogenous, exogenous variables and parametersI Assignment of parameter values
I Declaration of model
I Start: model;I End: end;I In between: all equilibrium conditions
I Initial conditions
I Start: initvalI Provide initial conditions for steady state of modelI End: end
12 )
General Structure cont.
I Specify shocks
I Start: ShocksI Define (all non-zero entries of) Variance–Covariance matrix of
shocksI End: end
I Solution of Model
I Use command stoch simulI More on options later
13 )
Timing Convention
I Pre-determined variables (e.g., capital stock) dated t − 1 intime t equation
I Way to tell Dynare which variables are state variables
I Need to rewrite set of equations
I Lag capital stock in all equations
14 )
More on Conventions
I Timing conventions
I If variable x is decided in period t, write xI If variable x is decided in period t − 1, write x(-1)I If variable x is decided in period t + 1, write x(+1)I If variable x is decided in period t + 2, introduce auxiliary
variable
I Solutions
I Dynare default: linear approximation of levels of variablesI Linear approximation in logs convenient as IRFs are in
percentage termsI Define variables as exp(x)I Now x will be interpreted as log of variable
15 )
Dynare code: Preamble
I Define the endogenous variables:
var y, I, k, a, c, w, R, r;
I Define the exogenous variables:
varexo e;
I Define the parameters:
parameters alpha, beta, delta, rho, sigma, sigmaa;
I Specify parameter values:
sigma = 1;
alpha = 1/3;
delta = 0.025;
beta = 0.99;
rho = 0.95;
sigmaa = 0.01;16 )
Dynare code: Model
I Write first-order conditions:
model;
exp(c)^(-sigma) = beta*exp(c(+1))^(-sigma)*(alpha*exp(a(+1))
*exp(k)^(alpha-1) + (1-delta));
exp(y) = exp(a)*exp(k(-1))^(alpha);
exp(k) = exp(a)*exp(k(-1))^(alpha) - exp(c) + (1 - delta)
*exp(k(-1));
a = rho*a(-1) + e;
exp(y) = exp(c) + exp(I);
exp(c)^(-sigma) = beta*exp(c(+1))^(-sigma)*(1 + r);
exp(R) = alpha*exp(a)*exp(k(-1))^(alpha - 1);
exp(w) = (1 - alpha)*exp(a)*exp(k(-1))^(alpha);
end;17 )
Dynare code: Things to keep in mind
I Dynare interprets all variables now in logs
I Stochastic process for technology was already defined in logs
I Dynare solve for steady state numerically
I We have to provide initial guesses
I Bad guesses might lead to non-convergence!
18 )
Dynare code: Initial conditions
initval;
k = log(30);
y = log(3);
c = log(2.5);
I = log(0.5);
a = 0;
r = (1/beta) - 1;
R = log((1/beta) - (1-delta));
w = log(1);
end;
19 )
Dynare code: Specify Shocks
shocks;
var e = sigmaa^2;
end;
20 )
Dynare code: Steady State
I To get the steady state, simply type
steady;
21 )
Dynare code: Solution of Model
I stoch simul command solves and simulates model
I Default output:
I Steady-state values of endogenous variablesI Model summaryI Covariance matrix of shocksI Policy and transition functionsI Theoretical first and second momentsI Theoretical correlation matrixI Theoretical autocovariances up to order 5I Impulse responses
22 )
Dynare code: Options
I ar = Integer: Order of autocorrelation coefficients tocompute and to print
I periods = Integer: If different from zero, the model will besimulated and empirical moments will be computed instead oftheoretical moments. The value of the option specifies thenumber of periods to use in the simulations (default = 0)
I nocorr: Doesn’t print the correlation matrix (default =PRINT)
I drop = Integer: Number of points dropped at the beginningof simulation before computing the summary statistics(default = 100)
I hp filter = Integer: theoretical moments after HP filteringthe data. The integer corresponds to the penalty parameter inthe HP filter. NB: simulated data cannot be hp-filtered.
23 )
Dynare code: Options
I irf = Integer: Number of periods on which to compute theIRFs (default = 40)
I nofunctions: Doesn’t print the coefficients of theapproximated solution
I nomoments: Doesn’t print moments of the endogenousvariables
I order = [1,2,3]: Order of Taylor approximation (default = 2)
I replic = Integer: Number of simulated series used tocompute the IRFs (default = 1, if order = 1, and 50otherwise)
I simul seed = Integer: sets the seed used in the randomnumber generator for the simulations
24 )
Dynare code: Example
I stoch simul(nofunctions,hp filter=1600,order=1,irf=20) will
I suppress policy functionI produce analytical hp-filtered momentsI do first-order approximationI plot first 20 periods in impulse response functions
25 )
Running Dynare
26 )
Running Dynare
I Create .mod file containing model
I Use m.file editor but save as filename.mod
I Go to directory where you saved .mod file
I Type dynare filename.mod
I Alternative, write new m.file containing “dynare filename” andrun m.file
I Latter approach convenient for simulation and loops
I Option noclearall makes sure that workspace is not erased
27 )
Dynare Output
28 )
Dynare Output: Comments
I Steady-state resultsI Model Summary
I State variables: date t − 1 variablesI Jumpers: date t + 1 variablesI Static variables: date t variablesI NB: in our case, a is both jumper and state variable
I Covariance matrix of shocksI Policy and transition functions
I Constant is just steady-state valueI Other coefficients are just coefficients of state-space
representation
I Theoretical momentsI Correlation matrixI Autocorrelation coefficientsI Variance decomposition in case of multiple shocksI Impulse-response functions
29 )
Dynare Output: Storage location
I IRF of variable x to shock e: x e
I Variables of state-space representation Yt = Ψst−1 + Ωεe :
I Ψ: oo .dr.ghxI Ω: oo .dr.ghuI Steady-state values: oo dr.ysI The decisions rule (dr) saves in the following ordering: static
variables (only dated t), backward-looking variables (dated tand t − 1), mixed variables (dated t − 1, t, and t + 1), andforward-looking variables (variables dated t and t + 1)
I Inverse mapping from dr to order of variable declaration:oo dr.inv. order var
30 )
Useful Links
I Simple explanation on how to run Dynare
I Dynare User Manual
I Dynare Forums
I Macroeconomic Model Data Base: Dynare code for manystandard models
31 )