Practical Tools for DSGE Modeling Part 2
Mathias Trabandt
March 2014
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Model Solution and Analysis with MATLAB We know how to set up and solve the Hansen (1985) RBC model with pencil and paper. This session focuses on solving the model using a computer.
1
Learning how to: Use MATLAB to solve and analyze model using: Own code Uhlig (1999) toolkit DYNARE
2
Model workhorse: Hansen (1985) RBC model
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Own MATLAB Code
Given parameters it is easy to solve for the numerical steady state numerical dynamics
Easy to write MATLAB computer code that does this Inspect and run: hansen_by_hand.m
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Uhlig Toolkit Uhlig (1999), "A toolkit for analysing nonlinear dynamic stochastic models easily" in Marimon and Scott, eds, Computational Methods for the Study of Dynamic Economies, Oxford University Press Selection of MATLAB programmes to solve general class of linearized DSGE models Code and documentation available at: http://www2.wiwi.huberlin.de/institute/wpol/html/toolkit.htm
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Uhlig Toolkit Write model in matrix form:
( ) 0 = Axt + Bxt 1 + Cyt + Dzt ( ) 0 = Et [Fxt+1 + Gxt + Hxt 1 + Jyt+1 + Kyt + Lzt+1 + Mzt ] zt = Nzt 1 + εt with εt iid N (0, Σ)
xt denotes the vector of endogenous state variables yt denotes the vector of other endogenous variables zt denotes the vector of exogenous state variables
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Uhlig Toolkit Recall the log-linearized equilibrium equations: ¯ ct + Yˆ ¯ yt I¯ibt Cˆ : 0 = I¯ibt K¯ kˆ t + (1 δ)K¯ kˆ t 1 : 0 = αkˆ t 1 yˆ t + (1 α) nˆ t + zˆ t : 0 = cˆ t + yˆ t nˆ t Y¯ Y¯ ¯R ˆt : 0 = α ¯ kˆ t 1 + α ¯ yˆ t R K K ˆ t+1 + cˆ t : 0 = Et cˆ t+1 + R : zˆ t = ρˆzt 1 + εt
Feasibility (1) : 0 = Capital Acc. (2) Production (3) Labor/Leisure (4) Real Return (5) Euler Equation (6) TFP (7)
h i h i0 ˆ b ˆ De…ne: xt = kt and yt = cˆ t , yˆ t , nˆ t , Rt , it
Now it is easy to write the equations in matrix form
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Uhlig Toolkit Let’s start with matrix equation ( ) : 2
3 0 K¯ 7 7 0 7 7,B = 0 5 0
2
2 3 0 6 6(1 δ)K¯ 7 607 6 6 7 6 7 6 7 , D = 617 α A=6 6 6 7 6 7 4 4 5 405 0 Y¯ 0 α K¯ 2 ¯ 3 C Y¯ 0 0 I¯ 6 0 0 0 0 I¯ 7 6 7 7 0 1 1 α 0 0 ( ) C=6 6 7 4 1 1 1 0 05 ¯ ¯ 0 0 R 0 α KY¯ 0
3
Own Code
Uhlig Toolkit
DYNARE
Uhlig Toolkit Next, matrix equation (
):
F = 0 ,G = 0 ,H = 0 J=
1 0 0 1 0
K= 1 0 0 0 0 L = 0 ,M = 0 Finally, N = ρ , Σ = σ2ε
First vs. Second-Order Approximations
Own Code
Uhlig Toolkit
DYNARE
Uhlig Toolkit
Inspect and run: hansen_by_uhlig.m
First vs. Second-Order Approximations
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Software package developed by M. Juillard and his team Selection of MATLAB programmes to solve and estimate general class of models Code and Documentation available at: http://www.dynare.org Have a look at the DYNARE manuals: manual.pdf, guide.pdf or UserGuide.pdf
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
A Typical Dynare .MOD File //endogenous variables var [expressions] ; //exogenous variables varexo [expressions] ;
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
A Typical Dynare .MOD File //parameters parameters [expressions] ; //initialization of parameters [parameter x = numerical value];
//the model model; [model equations]; end;
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
A Typical Dynare .MOD File //assign steady state values initval; [expressions]; end; //calc. and check steady state steady; //check eigenvalues check;
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
A Typical Dynare .MOD File
//standard deviations of shocks shocks; [expressions]; end; //stochastic simulation stoch_simul([options]) ;
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Execution of DYNARE .MOD File
Save DYNARE folder in MATLAB path (once) Execute DYNARE …le from MATLAB command window by: >>dynare modelname;
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Exercise
Write and run a .mod …le for the following model of TFP: log Zt = (1
ρ) log Z¯ + ρ log Zt
Set σ2 = 0.00712 and ρ = 0.95
1
+ εt , εt
N (0, σ2 )
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
The Hansen RBC model in DYNARE
Inspect and run: dynare hansen_by_dynare.mod
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Particularity Note that DYNARE linearizes (as opposed to log-linearization), i.e. takes absolute deviations from steady state. Example: xt = yt
is approximated by DYNARE by: xt = x¯ + (yt
y¯ )
In order to obtain percent deviations from steady state or a log-linear formulation simply de…ne variables in logs: elog _xt = elog _yt
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Particularity Which is approximated by DYNARE as: log _xt = log _x + log _yt
log _y
y Using xˆ t = log( xx¯t ) and yˆ t = log( y¯t ) we obtain:
xˆ t = yˆ t which has the usual log-linear interpretation.
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Particularity Also, the recursive law of motion provided by DYNARE looks di¤erent than in e.g. Uhlig (1999). Example: log _kt = 2.570 | {z } + 0.941(log _kt
1
log _k)
log _k
+ 0.147 | {z } (log _zt
1
log _z) + 0.155εt
0.95 0.155
So that we have: log _kt
log _k = 0.941(log _kt 1 log _k) +0.155(0.95(log _zt 1 log _z) + εt ) | {z } log _zt log _z
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
DYNARE Particularity Or: log _kt
log _k = 0.941(log _kt 1 +0.155(log _zt
log _k) log _z)
Observe that kˆ t = log( kk¯t ) and zˆ t = log( zz¯t ) so that: kˆ t = 0.94kˆ t
1
+ 0.16ˆzt
which is idential to what we have computed by hand or by using Uhlig (1999).
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
First vs. Second-Order Approximations DYNARE can approximate models using …rst, second or third-order Taylor series expansions. First order approximation (log-linearization): imposes certainty equivalence, i.e. variances of future shocks do not matter for decision rules (RLOMs). yt = y¯ + A (yt
1
y¯ ) + B(zt
z¯ ).
Second-order approximation: RLOMs depend on variances of future shocks: yt = y¯ + 0.5∆2 + A (yt 1 y¯ ) + B(zt +0.5C [(yt 1 y¯ ) (yt 1 y¯ )] +0.5D [(zt z¯ ) (zt z¯ )] +E [(yt 1 y¯ ) (zt z¯ )] .
z¯ )
Own Code
Uhlig Toolkit
DYNARE
First vs. Second-Order Approximations
Stochastic Simulations Using First vs. Second-Order Approximations Solve the model and run a stochastic simulation using …rst and second-order approximations. Examine the constant term 0.5∆2 in the RLOMs. Compare the dynamics for consumption using both approximations. Examine the e¤ects of larger variances of shocks (allow for pruning when using very large shocks). Examine the e¤ects of positive vs. negative shocks.