You are on page 1of 7

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

Introduction to Dynare Handout


RBC with Inelastic Labor Supply

What is Dynare?

Dynare is a free module for use with Matlab or Octave that solves stationary models with forward looking variables. The software is capable of solving for steady state values, calculation impulse response paths, and estimating model parameters using Bayesian Methods. It works much like the log-linearization we learned in class to approximate percent deviations from a stationary point, or steady state. Where as we used rst order Taylor Approximation, Dynare uses up to a third order approximation for stochastic variables and a dierent sort of approximation for deterministic variables. You can access the software and documentation at www.dynare.org.

Getting Started

To congure Dynare follow the following steps: 1. Download Dynare Version 3.065 http://www.dynare.org/download/oldies/dynare-3/matlab/windows/dyn-mat-v3-065.zip/view Do not download the latest version! Since we are using Matlab through the server, we cannot install les required for the latest versions of dynare. 2. Change the working directory to the matlab folder where you have saved the dynare les Ex: Write in Command Window addpath C:\dyn-mat-v3-065\dynare_v3\matlab 3. Create a new m-le. Save this le as filename.mod in the C:\dyn-mat-v3-065\dynare_v3\matlab folder where the dynare matlab les are Make sure the extension is .mod NOT .m. 4. This new le is where you will describe the problem you want Dynare to solve and give additional commands for simulations, etc. To run this le you will save the latest version (as filename.mod) and type into the command window: dynare filename

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

3
3.1

Neoclassical Growth Model with Inelastic Labor Supply


Environment

This environment satises the necessary conditions for the Second Welfare theorem, we know there exists a set of prices to implement the optimal allocation in the planners problem in a competitive equilibrium setting. To keep things simple, we will ask dynare to solve the following planners problem for us:
ct ,kt+1

max

=
t=0

E0

1 )1 (c t (1 lt ) 1

(1) (2) (3) (4) ct 0 (5)

such that

1 kt+1 = at kt lt ct + (1 )kt

ln(at ) = ln(at1 ) +

N (0, )

limt t c t kt+1 = 0

lt [0, 1]

kt+1 0

Note that total factor productivity at follows an AR(1) process and we impose rational expectations. Taking rst order conditions we can characterize the solution to this problem with the intertemporal Euler, intratemporal Euler, and resource constraint.
1 )1 (c (1 lt+1 )1 )1 (c t (1 lt ) 1 = Et [ t+1 (1 + at+1 kt +1 lt+1 + 1 )] ct ct+1 1 ct = (1 )at kt lt 1 lt 1 kt+1 = at kt lt ct + (1 )kt

(6) (7) (8)

One caveat is that dynare requires predetermined endogenous variables to show up with subscript t 1 in the equations characterizing the equilibrium. Capital stock today is determined by the investment we made yesterday and the capital stock yesterday, therefore it is a predetermined variable. Therefore we need to re-write the FOCs with a slightly dierent timing convention:
1 )1 (c (1 lt+1 )1 )1 (c t (1 lt ) 1 = Et [ t+1 (1 + at+1 kt lt+1 + 1 )] ct ct+1 1 ct = (1 )at kt 1 lt 1 lt 1 kt = at kt ct + (1 )kt1 1 lt

(9) (10) (11)

We should also dene any other static variables we might be interested in. GDP is certainly one of them! Lets also track investment.
1 yt = at kt 1 lt

(12) (13)

it = yt ct

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

3.2

Dynare Code
CAUTION: The dynare code will not run unless every command is followed by a semicolon ;

3.2.1

Preamble

The rst lines of code in our .mod le is called the preamble. Because dynare is sensitive, we should not write additional comments or change the order that we give commands. The rst line of code species how many periods the model will be simulated to calculate simulated moments of variables. It should look like this: periods 20000; Next we have to describe the endogenous variables of the model so that dynare knows what to do with them! Dynare knows how to think about variables in four ways: Static Variables Enter FOCs at time t Predetermined Variables Enter FOCs at times t 1 and t Predetermined and Forward Looking Variables Enter FOCs at times t 1, t and t + 1 Forward Looking Variables Enter FOCs at times t and t + 1 The second line of code in our .mod declares these variables as follows var y, c, k, l, a; The third line of code species exogenous variables. In this case it is the AR(1) process of TFP which we will call e: varexo e; The fourth line of code declares parameters of the model. We have parameters , epsilon , , , : parameters alpha beta rho sigma theta nu delta; On the very next line, we dene the values for these parameters. (We will discuss calibration issues later) alpha = 0.36; beta = 0.95; rho = 0.95; sigma = 0.01; theta = 0.357; nu = 2; delta = 0.025; 3 shock to the

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

3.2.2

Model Declaration

This section starts with the command model;, declares the equilibrium conditions, and ends with end;. We need to specify timing of variables as follows: If x is decided in period t, write x If x is decided in period t 1, write x(1) If x is decided in period t + 1, write x(+1) For the problem above, the model declaration looks like:
model; (c^theta*(1-l)^(1-theta))^(1-nu)/c= beta*((c(+1)^theta*(1-l(+1))^(1-theta))^(1-nu)/c(+1))*(1+alpha*a(+1)*k^(alpha-1)*l(+1)^(1-alpha)-delta); c=theta/(1-theta)*(1-alpha)*a*k(-1)^alpha*l^(-alpha)*(1-l); k=a*k(-1)^alpha*l^(1-alpha)-c+(1-delta)*k(-1); a = rho*a(-1)+e; end;

3.2.3

Solving the Model

Dynare is going to make your life easy and solve for steady state values for you. However, you have to give it a guess for where to start. If you give it a bad guess, Dynare will not converge and you can get an error. Some guidelines for an initial guess is to remember that Dynare is log-linearizing, therefore the scale of your variables should make sense in logs. This section of code starts with the command initval; and ends with end;. initval; k = 1; c = 1; l = 0.3; a = 0; e = 0; end; We must specify the evolution of shocks by dening the variance of the AR(1) process. This part of the code starts with the command shocks and ends with end;. Important: we are specifying the variance of the shock, not the standard deviation; so we are actually specifying 2. shocks; var e = sigma^2; end; To get Dynare to spit out the steady state values, the next command is steady;: 4

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

steady; If we wanted to solve the deterministic model without the shock, we would just write var e = 0. 3.2.4 Simulating the Model

Finally, we will give Dynare the commands to solve the model, produce policy functions, generate impulse responses, and calculate simulate moments. Here there are a bunch of options of things that you could as Dynare to do. See the users guide for details. The general expression to run the simulation is stoch simul;. To run the simulation with specied options, write stoch simul(options); For now we will go through a few options. hp lter = integer: This command tells Dynare to HP lter the data before calculating the theoretical moments. Remember, we always want calculate statistics from model data as we do with actual data. Since you did such a nice job on HW #3, we will need to use this command. The integer is the of the HP-lter. So, for yearly data we will be using the option stoch simul(hp filter=100);. irf = integer: This command tells Dynare how many periods to plot the impulse response functions for. The default is 40, if you would like a shorter time span, say 20 periods, we would write: stoch simul(irf=20); Putting it altogether, our last line of code is: stoch_simul(hp_filter=100, irf=20); Save the le as filename.mod and type dynare filename And behold the beauty!

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

Full Code
periods 20000; var y, c, k, l, a; varexo e; parameters alpha beta rho sigma theta nu delta; alpha = 0.36; beta = 0.95; rho = 0.95; sigma = 0.01; theta = 0.357; nu = 2; delta = 0.025; model; (c^theta*(1-l)^(1-theta))^(1-nu)/c= beta*((c(+1)^theta*(1-l(+1))^(1-theta))^(1-nu)/c(+1))* (1+alpha*a(+1)*k^(alpha-1)*l(+1)^(1-alpha)-delta); c=theta/(1-theta)*(1-alpha)*a*k(-1)^alpha*l^(-alpha)*(1-l); k=a*k(-1)^alpha*l^(1-alpha)-c+(1-delta)*k(-1); a = rho*a(-1)+e; end; initval; k = 1; c = 1; l = 0.3; a = 0; e = 0; end; shocks; var e = sigma^2; end; steady; stoch_simul(hp_filter=100, irf=20);

ECON 4741H - Quantitative Analysis of the Macroeconomy

Amanda M Michaud

Troubleshooting
Common Problems

Is my current path set to the folder with the dynare matlab les? Did I save my dynare code as a .mod le? Did I save my dynare code in the same folder as the dynare matlab les? Did I follow each command in my dynare code with a semicolon? ;

You might also like