7
ECON 4741H - Quantitative Analysis of the Macroeconomy Amanda M Michaud Introduction to Dynare Handout RBC with Inelastic Labor Supply 1 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 sta- tionary point, or steady state. Where as we used first order Taylor Approximation, Dynare uses up to a third order approximation for stochastic variables and a different sort of approximation for deterministic variables. You can access the software and documentation at www.dynare.org. 2 Getting Started To configure 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 files required for the latest versions of dynare. 2. Change the working directory to the matlab folder where you have saved the dynare files Ex: Write in Command Window addpath C:\dyn-mat-v3-065\dynare_v3\matlab 3. Create a new m-file. Save this file as ’filename’.mod in the C:\dyn-mat-v3-065\dynare_v3\matlab folder where the dynare matlab files are Make sure the extension is .mod NOT .m. 4. This new file is where you will describe the problem you want Dynare to solve and give additional commands for simulations, etc. To run this file you will save the latest version (as ’filename’.mod) and type into the command window: dynare filename 1

Dynare

  • Upload
    damla87

  • View
    33

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Dynare

ECON 4741H - Quantitative Analysis of the Macroeconomy Amanda M Michaud

Introduction to Dynare Handout

RBC with Inelastic Labor Supply

1 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 sta-

tionary point, or steady state. Where as we used first order Taylor Approximation, Dynare uses

up to a third order approximation for stochastic variables and a different sort of approximation

for deterministic variables. You can access the software and documentation at www.dynare.org.

2 Getting Started

To configure 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 files required for the latest versions of dynare.

2. Change the working directory to the matlab folder where you have saved the dynare files

• Ex: Write in Command Window

addpath C:\dyn-mat-v3-065\dynare_v3\matlab

3. Create a new m-file. Save this file as ’filename’.mod in the

C:\dyn-mat-v3-065\dynare_v3\matlab

folder where the dynare matlab files are

• Make sure the extension is .mod NOT .m.

4. This new file is where you will describe the problem you want Dynare to solve and give

additional commands for simulations, etc. To run this file you will save the latest version

(as ’filename’.mod) and type into the command window:

dynare filename

1

Page 2: Dynare

ECON 4741H - Quantitative Analysis of the Macroeconomy Amanda M Michaud

3 Neoclassical Growth Model with Inelastic Labor Supply

3.1 Environment

This environment satisfies 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

planner’s problem for us:

maxct,kt+1

=∞∑t=0

βE0(cθt (1− lt)1−θ)1−ν

1− ν(1)

such that kt+1 = atkαt l

1−αt − ct + (1− δ)kt (2)

ln(at) = ρln(at−1) + εt ε ∼ N (0, σε) (3)

limt→∞βtc−σt kt+1 = 0 (4)

lt ∈ [0, 1] kt+1 ≥ 0 ct ≥ 0 (5)

Note that total factor productivity at follows an AR(1) process and we impose rational expec-

tations. Taking first order conditions we can characterize the solution to this problem with the

intertemporal Euler, intratemporal Euler, and resource constraint.

(cθt (1− lt)1−θ)1−ν

ct= βEt[

(cθt+1(1− lt+1)1−θ)1−ν

ct+1(1 + αat+1k

α−1t+1 l

αt+1 + 1− δ)] (6)

1− θθ

ct1− lt

= (1− α)atkαt l−αt (7)

kt+1 = atkαt l

1−αt − ct + (1− δ)kt (8)

One caveat is that dynare requires predetermined endogenous variables to show up with sub-

script 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 prede-

termined variable. Therefore we need to re-write the FOC’s with a slightly different timing

convention:

(cθt (1− lt)1−θ)1−ν

ct= βEt[

(cθt+1(1− lt+1)1−θ)1−ν

ct+1(1 + αat+1k

α−1t lαt+1 + 1− δ)] (9)

1− θθ

ct1− lt

= (1− α)atkαt−1l−αt (10)

kt = atkαt−1l

1−αt − ct + (1− δ)kt−1 (11)

We should also define any other static variables we might be interested in. GDP is certainly

one of them! Let’s also track investment.

yt = atkαt−1l

1−αt (12)

it = yt − ct (13)

2

Page 3: Dynare

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 first lines of code in our .mod file is called the preamble. Because dynare is sensitive, we

should not write additional comments or change the order that we give commands.

The first line of code specifies 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 FOC’s at time t

Predetermined Variables Enter FOC’s at times t− 1 and t

Predetermined and Forward Looking Variables Enter FOC’s at times t− 1, t and t+ 1

Forward Looking Variables Enter FOC’s 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 specifies exogenous variables. In this case it is the ε shock to 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 define 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

Page 4: Dynare

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 defining 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

Page 5: Dynare

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, gen-

erate impulse responses, and calculate simulate moments. Here there are a bunch of options of

things that you could as Dynare to do. See the user’s guide for details. The general expression

to run the simulation is stoch simul;. To run the simulation with specified options, write

stoch simul(options); For now we will go through a few options.

hp filter = integer: This command tells Dynare to HP filter 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-filter. 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 file as filename.mod and type

dynare filename

And behold the beauty!

5

Page 6: Dynare

ECON 4741H - Quantitative Analysis of the Macroeconomy Amanda M Michaud

4 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);

6

Page 7: Dynare

ECON 4741H - Quantitative Analysis of the Macroeconomy Amanda M Michaud

5 Troubleshooting

Common Problems

• Is my current path set to the folder with the dynare matlab files?

• Did I save my dynare code as a ’.mod’ file?

• Did I save my dynare code in the same folder as the dynare matlab files?

• Did I follow each command in my dynare code with a semicolon? ;

7