# Introduction to Dynare study exercise

```EC924: Solving a Baseline NK Model using
Dynare
Vasiliki-Eirini Dimakopoulou
University of Warwick
February 14, 2019
Dynare is a free software which is very often used in Macroeconomics. It is not a program
but is rather a collection of Matlab codes. To run Dynare, you must …rst install it. You can
the User Guide). You need to choose a destination folder. You can “set path”in Matlab so
that you don’t always have to call up the Dynare directory.
To run Dynare, you have to create .mod …les; create these …les in the m-…le editor and
save them as .mod, not as .m …les. Then, to run your code, simply type “dynare …lename”
into the command window. The language of Dynare is quite straightforward, and we will
try to illustrate its basics by solving the following exercise.
1
The Baseline New Keynesian Model
Consider the standard baseline New Keynesian model that you covered in class (see, also,
Galí, 2015, chapter 3). Assume that monetary authority follows a simple interest rate rule :
it =
+
t
+
~t
yy
+
t
where is the steady state value of the nominal interest rate.
In the decentralized and symmetric equilibrium, (i) all households maximize utility, (ii)
all …rms maximize pro…ts, (iii) all constraints are satis…ed and (iv) all markets clear.
The equilibrium system can be summarized by 6 equations (in log-linear form) in 6
endogenous variables fyt ; nt ; it ; rt ; t ; mt g given the exogenous variables f t ; t g:
n
yt ytn = Et yt+1 yt+1
| {z } |
{z
}
y~t
1
(rt
rtn )
(1)
Et y~t+1
t
= Et
t+1
+ yet
(2)
Includes material by Marija Vukotic and is based on notes by Eric Sims. Any errors in presentation or
interpretation are mine.
1
yt =
t
mt
it =
t
+
(1
) nt
(3)
= yt
it
(4)
+
t
r t = it
~t
yy
Et
+
(5)
t:
(6)
t+1
To solve the system , we need to de…ne some auxiliary equations:
ytn
y~t = yt
ytn =
1+'
at
(1
)+'+
|
{z
}
(1
=
)(
(1
|
n
ya
rtn
(7)
0
log (1
)+'+
{z
AU X
B
1+'
B
+ B
)+'+
@ (1
|
{z
n
ya
mrt = mt
t
1
}
C
C
C Et ( at+1 )
A
))
(8)
}
(9)
(10)
We, also, de…ne the annualized nominal and real interest rates, the annualized in‡ation
and the annualized real money balances:
rty = 4rt
(11)
iyt = 4it
(12)
y
t
=4
t
r
mr;y
t = 4mt
(13)
(14)
Finally, we need to specify the stohastic processes of the productivity and monetary
shocks. Both shocks are assumed to follow AR(1) stochastic processes of the form:
at =
a at 1
+ "at
(15)
=
t 1
+ "t
(16)
t
2
Dynare requires that predetermined variables show up as dated t
equations and t in the t + 1 equations.
Which are the state/control variables in the model?
2
1 in the time t
The Dynare code
Declare the endogenous variables of the model. Every line in the code should end with
a semi colon (;).
var
y; ygap; yn; pi; i; rn; n; r; ry; iy; piy; m; mr; mry; a; v
Declare the exogenous variables. Here, we have two shocks:
varexo e_a; e_v
Declare the parameters of the model. We usually use capital letters to distinguish
parameters from the endogenous variables.
parameters ALF A; BET A; T HET A; SIGM A; KAP P A; LAM BDA; P HI; P SI_Y A; EP SILON;
ET A; RHO; F I_P I; F I_Y; RHO_V; RHO_A; AU X
Specify numerical values for these parameters. It is useful to write the description of
ALF A = 1=3; ==capital share in production f unction
BET A = 0:99; ==discount f actor
T HET A = 2=3; ==price stickiness parameter (probability)
SIGM A = 1; ==determines the curvature of the utility of consumption
P HI = 1; ==determines the curvature of the disutility of labour
EP SILON = 6; ==determines monopolistic power (markup)
ET A = 4; ==elasticity of substitution
F I_P I = 1:5; ==response of policy interest rate to inf lation
F I_Y = 0:5=4; ==response of policy interest rate to ouput gap
RHO_V = 0:5; ==persistence of monetary shock
RHO_A = 0:9; ==persistence of T F P shock
Some parameters could be de…ned as functions of other parameters: (of course, you can
just type these parameters directly when writing equations in the model part).
RHO = 1=BET A 1; ==the ss real interest rate
LAM BDA = ((1 T HET A) ((1 BET A T HET A)=T HET A) (1
ALF A + ALF A EP SILON )); ==coef f icient of the P C mc
3
ALF A)=(1
KAP P A = LAM BDA (SIGM A + (P HI + ALF A)=(1 ALF A)); ==coef f icient of
the N KP curve
P SI_Y A = (1+P HI)=(P HI +ALF A+SIGM A (1 ALF A)); ==the T F P parameter
in the natural level equation
AU X = (1 ALF A) (log(EP SILON=(EP SILON 1) log(1 ALF A)))=(SIGM A
(1 ALF A) + P HI + ALF A); ==auxiliary variable in natural level equation
Declare the model. To do this, you type in “model;” followed by the equilibrium
conditions and the auxiliary equations, followed by “end;”.
model;
// Basic equations
ygap = ygap(+1) 1=SIGM A (r rn); // (1) Dynamic IS equation
pi = BET A pi(+1) + KAP P A ygap;// (2) NKPC
y = a + (1 ALF A) n;// (3) production function
m = pi + y ET A i;// (4) money demand
i = RHO + F I_P I pi + F I_Y ygap + v;// (5) Taylor rule
r = i pi(+1); // (6) real interest rate
// Auxiliary equations
ygap = y yn; // (7) de…nition of output gap
yn = P SI_Y A a + AU X; // (8) natural level of output (the ‡exible-price counterpart)
rn = RHO + SIGM A P SI_Y A (a(+1) a);// (9) natural real interest rate
mr = m pi; // (10) real money balances
//Exogenous process
a = RHO_A a( 1) + e_a;// (11) AR(1) technology
v = RHO_V v( 1) + e_v; // (12) AR(1) monetary
// Annualized vrs
ry = 4 r; // (13) annualized real interest rate
iy = 4 i; // (14) annualized nominal interest rate
piy = 4 pi; // (15) annualized in‡ation
mry = 4 mr; // (16) annualized real money balances
end;
4
Declare the initial values of the variables. You need to give Dynare a guess of the
Dynare may not converge and you can get an error. However, a robust equilibrium
model should not be much sensitive to the initial values (i.e. when you slightly change
the initial values you will still get the same steady state solution).
initval;
ygap = 0;
y = 0;
yn = 0;
m = 0;
mr = 0;
mry = 0;
n = 0;
pi = 0;
i = RHO;
rn = RHO;
a = 0;
v = 0;
r = RHO;
ry = 4 r;
iy = 4 i;
piy = 4 pi;
e_a = 0;
e_v = 0;
end;
To check for saddle path stability (according to the Blanchard-Kahn condition), you need
to type the command “check;”
Specify the standard deviation of the exogenous shocks.
shocks;
vare_a;
stderr1;//1 percent technology shock
vare_v;
5
stderr0:25; //25 basis points mp shock
end;
De…ne di¤erent initial values for the simulations.
histval;
a(0) = 1;
v(0) = 0;
end;
Generate impulse responses functions and unconditional second moments. If you just
type “stoch_simul;", it’s going to give you the default output. The default output
is:(1) steady state values of endogenous variables; (2) a model summary, which counts
variables by type; (3) covariance matrix of shocks; (4) the policy and transition functions (in state space notation); (5) theoretical …rst and second moments; (6) a theoretical correlation matrix; (7) theoretical autocovariances up to order 5; and (8) impulse
responses. By default, Dynare does a second order approximation about the steady
state. Dynare will, also, directly do simulations for you if you want. For example, you
can type “stoch_simul(order = 1; IRF = 0; drop = 0; periods = 200”.
Here, to do a …rst order approximation and compute IRFs for 15 periods (as in Galí), we
type:
stoch_simul(IRF = 15; order = 1);
3
Run the Dynare code
Before running the Dynare code, please clear your workspace with the command “clear all”
and the command window with the command “clc”.
Then type “dynare f ilename”(here: “dynare ECON 924_dynare_example_vasiliki: mod”).Dynare
will produce a bunch of output in the command window, unless you include options to suppress it.
1. Simulate the model and plot impulse response functions of output, output gap, in‡ation, employment, real and nominal interest rates, and money supply to an increase of
25 basis points in "t :
6
2. Plot impulse response functions of output, output gap, in‡ation, real and nominal
interest rates, and money supply to a 1% positive technology shock. What is the
response of employment to a positive technology shock?
3. Discuss the variance decomposition results. Which variables are mostly a¤ected by a
TFP shock?
4. What happens when the when monetary policy parameter
7
is less than 1?
8
9
10
output gap
0.2
inflation
0.2
0
0
-0.2
-0.2
5
10
15
5
output
1
0.2
0.5
10
15
employment
0
0
-0.2
5
10
15
5
nominal rate
0.5
0.1
0
10
15
real rate
0
-0.5
-0.1
5
10
15
money supply
2
5
10
15
5
10
15
2
1
1
0
0
5
10
15
IRFs to a technolodgy shock
output gap
0.5
0
0
-0.5
-0.1
5
10
15
5
output
0.5
10
15
employment
0.5
0
0
-0.5
-0.5
5
10
15
5
nominal rate
0.2
10
15
real rate
0.2
0.1
0.1
0
0
5
1
inflation
0.1
10
15
5
money supply
0.4
0
10
15
10
15
v
0.2
-1
0
5
10
15
5
IRFs to a monetary policy shock
11
```
Eurozone

18 Cards

Gilded Age

25 Cards