RBC Models in Dynare
Advanced Macroeconomics Tutorials
Matteo Coronese
May 6, 2021
Scuola Superiore Sant’Anna
Planned Schedule
During last lecture, we learned how to use Dynare. In particular, we learned
• The basic structure of the mod file
• How to simulate a very simple RBC model
• Main commands to obtain stochastic simulation results, IRFs, variables
moments and correlation
• Basic interpretation of the results
Today, we proceed by
• Simulating a slightly more complicated RBC model
• Deeper understanding of simulation results
• Experiment with different model setups
2
An RBC Model with Labor
Consider the following optimization problem:
∑
∞ [ ]
c1−σ −1
max E0 βt t
− χnt
ct ,nt
t=0
1−σ (1)
1−α
s.t. kt+1 = at kα
t nt − ct + (1 − δ)kt
With the representative consumer deriving (quasi-linear) utility from consumption
ct and leisure (that’s why the minus sign in front of labor nt ). The meaning of the
law of motion of capital is the usual one: kt+1 = it + (1 − δ)kt . It follows that
1−α
yt =at kα
t nt
(2)
it =yt − ct
Finally, TFP is assumed to follow a mean zero AR(1) in logarithms:
ln at = ρ ln at−1 + εt (3)
3
An RBC Model with Labor II
FOCs with respect to consumption and labor yield
[ ]
c−σ
t =βEt c−σ α−1 1−α
t+1 (αat+1 kt+1 nt+1 + 1 − δ) (4)
χ =c−σ
t (1 − α)at kα −α
t nt (5)
Eq. 4 is a standard Euler equation. The meaning of Eq. 5 is straightforward:
U n,t = wt U c,t
The marginal rate of substitution between leisure and consumption equals the real
wage rate wt . In fact, labor supply, arising from consumer maximization, can be
written as
χ = wt c−σ
t (6)
while labor demand is characterized by the equality between marginal productivity
of labor MPL and its remuneration, i.e. the wage:
∂yt −α
wt = = (1 − α)at kα
t nt (7)
∂nt
Combining Eq. 6 and 7 yields Eq. 5, which thus characterizes labor market
equilibrium. 4
An RBC Model with Labor III
Linear dis-utility of labor is a way to introduce indivisible labor (see Hansen
1985).
• In the US, about two thirds of the fluctuation in labor supply comes from
changes along the extensive margin (movement into and out of employment)
rather than along the intensive margin (changes in hours when employed).
• Partially fix the problem of too small fluctuations in worked ours generated
by basic RBCs.
• Elasticity of labor supply is infinite (stronger effects of changes in
productivity on labor supply).
• Labor supply curve is perfectly horizontal. This allows us to get a bigger
increase in labor hours (and a smaller increase in wages) after the
productivity shock.
• Wages becomes less pro-cyclical.
5
An RBC Model with Labor IV
The full model can thus be written as a system of five equations in five variables:
[ ]
c−σ
t =βEt c−σ α−1 1−α
t+1 (αat+1 kt+1 nt+1 + 1 − δ) Euler Equation
χ =c−σ α −α
t (1 − α)at kt nt Labor Equation
kt+1 =yt − ct + (1 − δ)kt Capital Accumulation
1−α
yt =at kα
t nt Production Function
ln at =ρ ln at−1 + εt Exogenous Process
Which can be plugged into Dynare:
model ;
exp ( c ) ^− sigma = b e t a ∗ exp ( c ( + 1 ) ) ^− sigma ∗ ( a l p h a ∗ exp ( a ( + 1 ) ) ∗ exp ( k ) ^ ( a l p h a − 1 ) ∗ exp ( n ( + 1 ) ) ^(1 − a l p h a ) +1 − d e l t a ) ;
c h i = exp ( c ) ^− sigma ∗ ( 1 − a l p h a ) ∗ exp ( a ) ∗ exp ( k ( − 1 ) ) ^ a l p h a ∗ exp ( n ) ^− a l p h a ;
exp ( c ) + exp ( k ) = exp ( a ) ∗ exp ( k ( − 1 ) ) ^ a l p h a ∗ exp ( n ) ^(1 − a l p h a ) +(1 − d e l t a ) ∗ exp ( k ( − 1 ) ) ;
exp ( y ) = exp ( a ) ∗ exp ( k ( − 1 ) ) ^ a l p h a ∗ exp ( n ) ^(1 − a l p h a ) ;
a = rho ∗ a ( − 1 ) + z ;
end ;
6
Solving the Model - Details
Note that, as seen in the previous lecture, we lagged capital in our code. Dynare
assumes as predetermined variables those variables which are “stocked are the end
of the period”. Why is the distinction between predetermined and control variables
relevant?
The linearized model can be expressed, in the so-called space form, as a system of
forward looking difference equations:
Π0 Et yt+1 = Π1 yt + Π2 Zt (8)
There are several ways to solve this type of rational expectation models. We use
the Blanchard-Kahn (1980) method, which leverages on the distinction between
predetermined and control variables.
Forward Looking Solution
The non-predetermined variables depend on the past only through its effect on
the current predetermined variables
Blanchard-Kahn (1980)
7
Predetermined and Control Variables
So we aim at explaining the evolution of the model in terms of predetermined
variables and current shocks. What’s the difference between predetermined (or
state) variables St and non-predetermined variables or control) variables xt ?
Recall
Rational expectations: Et Xt+1 = E(Xt+1 |Ωt ) where Ωt is the information set at t.
Agents make their best forecast (mathematical expectation) given the available
information.
The difference between predetermined and non-predetermined variables is
extremely important. A predetermined variable is a function only of variables
known at time t, that is of variables in Ωt , so that St+1 = Et St+1 whatever the
realization of the variables in Ωt+1 . A non-predetermined variable Xt+1 , can be a
function of any variable in Ωt+1 , so that we can conclude that Xt+1 , = Et Xt+1 only
if the realizations of all variables in Ωt+1 are equal to their expectations
conditional on Ωt
Blanchard-Kahn (1980)
8
In other words, predetermined variables do not respond to St − Et−1 St .
Predetermined and Control Variables
Rewriting the space form partitioning between predetermined (or state) variables
St and non-predetermined (or control) variables Xt :
[ ] [ ]
St+1 St
Π0 = Π1 + Π 2 Zt
Et Xt+1 Xt
if Π0 is invertible, we can write
[ ] [ ]
St+1 St
= Φ1 + Φ 2 Zt
Et Xt+1 Xt
with Φ1 = Π−1 −1
0 Π1 and Φ2 = Π0 Π2 .
Necessary Condition
If the number of eigenvalues of Φ1 lying outside the unit circle (unstable roots)
are equal the number of non-predetermined variables (jumpers), then a unique
solution exists.
If too many unstable roots, then no solution. If too few, then infinite number of
solutions. In Dynare, such condition is checked through the command check.
9
Understanding Transition and Policy Functions
The state space representation of the solution is thus
St =ASt−1 + BZt (9)
Xt =ΓSt−1 (10)
Dynare shows the solution in a slightly different form. Plug Eq. 9 into Eq. 10,
obtaining Xt = ΓASt−1 + ΓBXt , defining C = ΓA and D = ΓB.
Dynare prints results in the following form:
St =ASt−1 +BZt (11)
Xt =CSt−1 + DZt (12)
• Transition functions: how the period t values of the state variables depend on
t − 1 values of the state variables, and the shocks.
• Policy functions: how the period t values of the other variables depend on
t − 1 values of the state variables, and the shocks.
10
Understanding Transition and Policy Functions II
Since our two predetermined variables are capital k and TFP a (and our shock is z),
this is Dynare output:
Table 1: Policy and Transition Functions in Dynare
y c k n a
Constant -0.257776 -0.561681 0.705661 -0.900068 0
k(-1) 0.191595 0.538937 0.821355 -0.347342 0
a(-1) 1.381119 0.662587 0.340435 0.718531 0.950000
z 1.453809 0.697460 0.358353 0.756349 1.000000
Remember that our model is in logs, so you read each column (e.g. the first one on
y) as
ln yt = ln ȳ + γ1 (ln kt−1 − ln k̄) + γ2 (ln at−1 − ln ā) + γ3 zt (13)
Thus
ln yt = −0.257776+0.191595(ln kt−1 −0.705661)+1.381119(ln at−1 −0)+1.453809zt
(14)
11
Understanding Transition and Policy Functions II
Since our two predetermined variables are capital k and TFP a (and our shock is z),
this is Dynare output:
Table 2: Policy and Transition Functions in Dynare
y c k n a
Constant -0.257776 -0.561681 0.705661 -0.900068 0
k(-1) 0.191595 0.538937 0.821355 -0.347342 0
a(-1) 1.381119 0.662587 0.340435 0.718531 0.950000
z 1.453809 0.697460 0.358353 0.756349 1.000000
Remember that our model is in logs, so you read each column (e.g. the first one on
y) as
ln yt = ln ȳ + γ1 (ln kt−1 − ln k̄) + γ2 (ln at−1 − ln ā) + γ3 zt (15)
Thus
ln yt = −0.257776+0.191595(ln kt−1 −0.705661)+1.381119(ln at−1 −0)+1.453809zt
(16)
12
Understanding Transition and Policy Functions III
Table 3: Policy and Transition Functions in Dynare
y c k n a
Constant -0.257776 -0.561681 0.705661 -0.900068 0
k(-1) 0.191595 0.538937 0.821355 -0.347342 0
a(-1) 1.381119 0.662587 0.340435 0.718531 0.950000
z 1.453809 0.697460 0.358353 0.756349 1.000000
ln yt = −0.257776+ 0.191595(ln kt−1 − 0.705661)+ 1.381119 ln at−1 + 1.453809zt
ln ct = −0.561681+ 0.538937(ln kt−1 − 0.705661)+ 0.662587 ln at−1 + 0.697460zt
ln kt = 0.705661+ 0.821355(ln kt−1 − 0.705661)+ 0.340435 ln at−1 + 0.358353zt
ln nt = −0.900068− 0.347342(ln kt−1 − 0.705661)+ 0.718531 ln at−1 + 0.756349zt
ln at = 0.950000 ln at−1 + 1.000000zt
13
Understanding Transition and Policy Functions IV
By bringing steady state values on the LHS, it is clear that we can interpret our
coefficients as the percentage deviation from the steady state value
triggered by a 1% deviation from the steady state of a certain variable
(predetermined or exogenous).
ln yt + 0.257776 = 0.191595(ln kt−1 − 0.705661)+ 1.381119 ln at−1 + 1.453809zt
ln ct + 0.561681 = 0.538937(ln kt−1 − 0.705661)+ 0.662587 ln at−1 + 0.697460zt
ln kt − 0.705661 = 0.821355(ln kt−1 − 0.705661)+ 0.340435 ln at−1 + 0.358353zt
ln nt + 0.900068 = −0.347342(ln kt−1 − 0.705661)+ 0.718531 ln at−1 + 0.756349zt
ln at = 0.950000 ln at−1 + 1.000000zt
Suppose that the economy is in the steady state at t = 0. Then a shock z1 = 1
arrives at t = 1. How above will output be with respect to its steady state at t = 1?
ŷ1 =0.191595 ∗ k̂0 +1.381119 ∗ â0 +1.453809 ∗ z1
ŷ1 =0.191595 ∗ 0 +1.381119 ∗ 0 +1.453809 ∗ 1
ŷ1 =1.453809
14
Understanding Transition and Policy Functions IV
If we want to know what will be the value of ŷ2 , we need first to compute also the
values for k̂1 and â1 .
k̂1 =0.821355 ∗ k̂0 +0.662587 ∗ â0 +0.697460 ∗ z1
k̂1 =0.821355 ∗ 0 +0.340435 ∗ 0 +0.358353 ∗ 1
k̂1 =0.358353
â1 =0 ∗ k̂0 +0.950000 ∗ â0 +1.000000 ∗ z1
â1 = 0.950000 ∗ 0 +1.000000 ∗ 1
â1 =1.000000
Thus we can obtain
ŷ2 =0.191595 ∗ k̂1 +1.381119 ∗ â1 +1.453809 ∗ z2
ŷ2 =0.191595 ∗ 0.358353 +1.381119 ∗ 1.000000 +1.453809 ∗ 0
ŷ2 =1.4498
15
Impulse Response Functions
This brings us exactly to the concept of Impulse Response Function. Suppose
your system is in equilibrium (in the steady state), and then is perturbed by an
exogenous shock. How will it react?
Luckily, Dynare computes IRFs for us automatically. You can specify the number of
periods for which to compute IRFs inside the stoch_simul command: e.g.
stoch_simul( irf =50).
y c
1.5 1.5
1 1
0.5 0.5
0 0
10 20 30 40 50 10 20 30 40 50
k n
1.5 1
1 0.5
0.5 0
0 -0.5
10 20 30 40 50 10 20 30 40 50
a
1.5
0.5
0
10 20 30 40 50
16
What is going on?
We simulated a 1% positive shock in TFP. What do we see?
• Income effect decreases labor supply
• Substitution effect increases labor supply. This effect prevails.
• The transitory productivity shock temporarily raises the real wage rate:
agents work more today to be able to consume more in the future when the
wage is expected to be lower.
• Higher output implies higher savings and higher investment that in turns
increases (gradually) the capital stock.
• Consumption increases gradually: consumption smoothing.
• Output increases more than proportionally.
17
Looping Over Parameters
Once the mod file is set, it is quite easy to build loops to experiment with different
parameter settings.
Set up a . m Matlab script looping over an array containing different values of a
certain parameter. Suppose you want to vary σ:
clear all ;
sigmas = [ 1 , 2 , 4 ] ; % s p e c i f y v e c t o r o f v a l u e s f o r sigma
results = struct % c r e a t e an empty s t r u c t u r e t o s t o r e r e s u l t s
f o r i = 1 : length ( sigmas ) %open l o o p
sigma = s i g m a s ( i ) ;
s a v e sigma ; %s a v e t h e c u r r e n t v a l u e s i g m a s ( i ) w i t h p a r a m e t e r name used i n . mod f i l e
d y n a r e y o u r _ m o d _ f i l e _ h e r e n o c l e a r a l l ; %run Dynare
r e s u l t s . ( s p r i n t f ( ’ sigma%d ’ , i ) ) = oo_ ; % s t o r e r e s u l t s i n t o s u b s t r u c t u r e
end
In your mod file, after your usual parameter declaration, insert two lines:
l o a d sigma ; %l o a d p r e v i o u s l y s a v e d p a r a m e t e r v a l u e
s e t _ p a r a m _ v a l u e ( ’ sigma ’ , sigma ) ; %o v e r r i d e p r e v i o u s l y s p e c i f i e d parameter value
You can then access the results structure to inspect and plot your results.
When looping, use the nograph option to suppress IRF printing.
18
Varying σ
yz cz
1.5 1.5
sigma =1 sigma =1
1 sigma =2 1 sigma =2
sigma =4 sigma =4
0.5 0.5
0 0
0 10 20 30 40 0 10 20 30 40
kz nz
1.5 1
sigma =1 sigma =1
1 sigma =2 sigma =2
sigma =4 0 sigma =4
0.5
0 -1
0 10 20 30 40 0 10 20 30 40
az
1.5
sigma =1
1 sigma =2
sigma =4
0.5
0
0 10 20 30 40
19
Varying σ II
How do we interpret these results?
• Loosely speaking, σ governs the household’s desire to smooth consumption.
• If σ is very large, the household will want consumption (in expectation) to be
very smooth.
• If σ is quite small then the household will be quite willing to allow
consumption to not be smooth (again in expectation).
• What about labor fluctuations? Think about labor supply and demand curves.
• When TFP increases, labor demand shifts right, the amount by which is
independent of σ (see Eq. 7)
• When consumption increases, labor supply shifts left. The bigger is σ, the
bigger is this inward shift in labor supply, and therefore the smaller is the
hours response in equilibrium and the larger is the wage response (see Eq. 5).
• That’s exactly what we see in terms of IRFs: when σ is bigger, the
employment jump is smaller (possibly negative), and the wage jump is larger.
• As a result, the output increases less than proportionally.
20
Varying ρ
How strong are propagation mechanisms for turning technology shocks into
business cycles? Fluctuations appear to heavily rely on shock persistence.
yz cz
2 1
rho =0.2 rho =0.2
rho =0.5 rho =0.5
1 rho =0.9 0.5 rho =0.9
0 0
0 10 20 30 40 0 10 20 30 40
kz nz
1.5 2
rho =0.2 rho =0.2
1 rho =0.5 1 rho =0.5
rho =0.9 rho =0.9
0.5 0
0 -1
0 10 20 30 40 0 10 20 30 40
az
2
rho =0.2
rho =0.5
1 rho =0.9
0
0 10 20 30 40
21