Seitani(2013)Toolkit for DSGE

download Seitani(2013)Toolkit for DSGE

of 27

Transcript of Seitani(2013)Toolkit for DSGE

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    1/27

    Matlab Toolkit for Simulating

    Dynamic Stochastic General Equilibrium Models

    Haruki Seitani*

    August 2013

    Abstract

    Behavior of a dynamic stochastic general equilibrium model can be best

    understood by working out an approximated solution. A set of Matlab codes is

    designed for 1) log-linearizing equilibrium conditions around a steady-state, 2) solving

    the system of expectational difference equations by applying eigenvalue decomposition,

    and 3) simulating the model by calculating impulse-response functions and generating

    artificial time series data. Taking a typical real business cycle model as an example, it is

    shown how a calibrated model provides an insight into refinement of business cycle

    theory.

    *Economic and Social Research Institute, Cabinet Office, Government of Japan. Opinionsexpressed here are the authors alone and do not represent the views of the organization.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    2/27

    - 1 -

    1. Introduction

    As Campbell (1994) advocates, behavior of a dynamic stochastic general

    equilibrium (DSGE) model can be best understood by working out an approximatedsolution. In the DSGE analysis, it has become a common exercise to log-linearly

    approximate equilibrium conditions derived from dynamic optimization of economic

    agents around a deterministic steady state. Such approximated equilibrium conditions

    typically take a form of a system of first-order expectational difference equations.

    Solution to the approximated system governs development of economic states and

    economic agents decisions functional on those states. Behavior of a DSGE model can

    then be investigated by simulating the approximated model with artificially generated

    data.

    This Matlab toolkit linearizes equilibrium conditions around a steady state and

    finds a set of policy functions and laws of motion of state variables as a solution to a

    system of first-order expectational difference equations. Once policy functions are

    obtained, one can simulate the model by giving it exogenous stochastic shocks to state

    variables. The toolkit calculates response of the model economy to such a shock and

    compares variation and correlation among aggregate economic variables.

    A typical real business cycle (RBC) model is taken as an example of DSGE

    models here not because it provides a better explanation of actual economic activities

    but because it has been a work-force of development of almost all DSGE approach to

    business-cycle analyses.

    Many authors have already provided this sort of guidance and toolkits and the

    present deliverable is entirely based on the contributions of the predecessors1. Thus this

    paper does neither offer any original insights nor provide complete treatment of

    alternative solution techniques. The purpose of it is to serve as a quick reference that

    relates economic theory, guide for mathematical technique, its application, and literature

    in a succinct manner.

    2. Real Business Cycle Model

    2.1. Setup of the Model

    The model is based on a perfectly competitive economy populated by identical

    infinitely-lived households and firms, so that their economic choices reduce to decisions

    made by a single representative agent.

    1

    See Hartley, Hoover, and Salyer (1998), Uhlig (1999), Kato (2002). Dejong and Dave (2011)compare various alternative solution techniques.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    3/27

    - 2 -

    Households own and lease capital stock, tk , and sell labor (measured by hours

    worked),tl , to firms respectively at the rental rate of capital and real wage rate. They

    allocate their income into purchases of consumption goods, tc , and capital goods, ti ,

    and their time into labor and leisure so that their lifetime expected utility is maximized.

    Their preferences are represented by an identical utility function as follows:

    00

    0

    0 1lnln1,t

    tt

    t

    t

    tt

    t lcElcUE , 10 . (1)

    Capital stock owned by households depreciates at a constant rate, .

    Firms have an access to a constant-returns-to-scale production technology that is

    subject to random technology shocks; specifically the production technology takes the

    Cobb-Douglas type functional form and the technology shocks follow a first-order

    autoregressive process (AR(1)) with a log-normally distributed disturbance.

    1, ttttttt lkzlkfzy , (2)

    11 exp ttt zz

    , zt N ,0 . (3)

    2.2. Deriving the Equilibrium Conditions

    Since the economic structure above satisfies complete markets, price-taking

    behavior, convexity of a production set, and convexity and local nonsatiation of

    preferences, the fundamental theorems of welfare economics is applicable; a Pareto

    optimal allocation coincides with a competitive equilibrium.2

    The Pareto optimum is the solution to the following social-planners problem:

    00 1lnlnMax

    t

    tt

    tlcE ,

    tttttt ylkzic 1subject to ,

    ttt ikk 1and 1 .

    This infinite horizon problem can be solved by exploiting its recursive structure; the

    2 See Cooley and Prescott (1994).

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    4/27

    - 3 -

    social planners problem is recast as the following dynamic programming:

    11,, ,1lnlnMax, 1 tttttlkctt zkVElczkV ttt ,

    1subject to1

    1 tttttt klkzkc ,

    where V denotes the optimized value function, or in this context the indirect utility

    function of the household.

    A solution to this problem has to satisfy the necessary conditions and aggregate

    resource constraint below.

    t

    ttt

    t c

    lkz

    l

    1

    1 . (4)

    111 1

    1

    1

    11

    1

    ttt

    t

    t

    t

    lkzc

    Ec

    . (5)

    tttttt cklkzk

    11

    1 . (6)

    The first equation that relates the current variables to each other is called

    intratemporal optimality condition. It implies that the marginal rate of substitution

    between labor and consumption has to equal the marginal product of labor. The second

    equation that connects the current and one-period ahead variables is called

    intertemporal optimality condition. The left-hand side of the equation represents the

    marginal utility loss of investing in capital while the right-hand side represents the

    expected marginal utility gain from it; these costs and benefits have to be equalized at

    the optimum. These intra- and intertemporal optimality conditions, together with the

    resource constraint and the dynamic low of motion for the technology shock, govern the

    equilibrium behavior of the model economy.

    3. Approximation and Solution

    Since the solution to the social planners problem exists and is unique (Prescott

    1986) but is NOT analytical, approximation helps us make the model operational. One

    of the widely exercised methods is to take a log-linear approximation of the equilibrium

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    5/27

    - 4 -

    conditions around the steady-state values of consumption, capital, labor, and

    technology3.

    3.1. Steady State of the Economy

    A steady state equilibrium for the model economy is one in which the

    technology shock is assumed to be constant: tzt ,1 , and the values of capital, labor,

    and consumption are constant: tccllkk tt ,,, . The steady-state values of

    capital, labor, and consumption are solution to the following equations obtained by

    imposing these conditions on the necessary conditions for the optimality.

    c

    lk

    l

    1 . (7)

    k

    ylk

    1111

    . (8)

    cyclkk 1 . (9)

    3.2. Log-Linear Approximation of the Equilibrium Conditions

    Recall that the first-order Taylor series expansion of a function xf around a

    point x takes the following form.

    xxxfxfxf .

    Taking natural logarithmic of x and noting that xx lnexp , natural logarithmic of

    xf can be approximated as follows.

    xx

    xf

    xxfxfxf lnlnlnln

    ,

    x

    x

    xf

    xxf

    xf

    xflnln . (10)

    Suppose that x deviates from x by only a small number, . Then,

    3 Log-linearization can be justified as a good approximation as far as

    the stochastic behavior of the model does not push the economy too far from the steady-state

    behavior. It is also possible to approximate the model at higher order; for example, Schmitt-Grohand Uribe (2004) analyze a solution to second-order approximated conditions.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    6/27

    - 5 -

    x

    xxx

    x

    x

    x ~1lnlnln

    .

    Thus xxln can be interpreted as percentage deviation of x from x , x~ . Note

    also that xfxxf is the elasticity of xf with respect to x . Thus equation

    (10) represents percentage deviation of xf from xf due to the deviation of x .

    This can easily be generalized to multivariate cases:

    ii

    n

    i n

    i

    i

    n

    n

    n

    xx

    xxfx

    xxxf

    xxfxxf ln

    ,,,,

    ,,,,ln

    1 1

    1

    1

    1

    . (11)

    Applying this technique to the equilibrium conditions from (4) to (6) and the process of

    technology shocks, (3), delivers the following log-linearly approximated counterparts.

    1) Intratemporal Optimality Condition

    ttttt clkzl ~

    ~~~~ . (12)

    2) Intertemporal Optimality Condition

    .~1~1~~

    ~

    1

    1~

    1

    1

    ~

    1

    ~~

    1111

    111

    11

    111

    11

    111

    11

    1

    tttttttt

    tttt

    ttttt

    lEkEzEk

    ycE

    lElk

    lk

    kElk

    lk

    zElk

    lkcEc

    (13)

    The last expression uses the steady-state equilibrium condition:

    k

    ylk 11 , and

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    7/27

    - 6 -

    1111 lk .

    3) Aggregate Resource Constraint

    .~~1~~

    ~

    1

    ~

    1

    1

    ~

    1

    ~

    1

    ~

    11

    1

    1

    1

    1

    1

    1

    tttt

    tt

    tttt

    ck

    clkz

    k

    y

    ccklk

    cl

    cklk

    lk

    kcklk

    lkz

    cklk

    lkkE

    (14)

    The final line of the equation results from the steady-state relationships:

    ylk 1 , and

    kcklk 11 .

    4) Technology Shock Process

    11~~

    ttt zz .

    Taking expectations of both sides of the last equation,

    ttt zzE~~

    1 . (15)

    Let

    tttt zklc ~~~~tY . Then the equilibrium conditions can be written as a system

    of first-order expectational difference equations:

    1tt YBYA tE , (16)

    where

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    8/27

    - 7 -

    000

    1

    0001

    111

    ky

    ky

    ky

    kcA ,

    1000

    0100

    111

    0000

    k

    y

    k

    y

    k

    y

    B .

    Premultiplying both sides of equation (16) by 1A yields:

    1t1

    t YBAY tE . (17)

    3.3. Solving the Approximated Model

    The trouble with solving the system of equations is that terms related to other

    variables appear one another in each individual equation. It would be much easier to

    solve if only we were able to transform these equations so that they are decoupled

    each other.

    This indeed possible by applying eigenvalue decomposition to BA 1 .

    1t1

    1t1

    t YQQYBAY

    tt EE , (18)

    where is a diagonal matrix whose diagonal entries are eigenvalue of BA 1 , and

    Q is a matrix whose columns are the associated eigenvectors4. Let tt

    1 YYQ . Then,

    1 tt YY tE

    1

    1

    1

    1

    4

    3

    2

    1

    ~

    ~

    ~

    ~

    000

    000

    000

    000

    ~

    ~

    ~

    ~

    tt

    tt

    tt

    tt

    t

    t

    t

    t

    zE

    kE

    lE

    cE

    z

    k

    l

    c

    Thus the transformation successfully decouples the equations.

    4 This technique of changing variables is discussed in Chapter 23 of Simon and Blume (1994).

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    9/27

    - 8 -

    Notice that the system of equations generally involves both control (or jump)

    and state (or predetermined) variables. In this case, there are two control variables,tc

    and tl , and two state variables, tk and tz . Suppose that in a general case tY

    consists of n control variables, tX , and m state variables, tS :

    t

    t

    tS

    XY .

    Let 1ijQ and i be partitioned matrices of

    1Q and whose numbers of rows and

    columns are respectively conformable to those of X and S .

    1t

    1t

    1

    22

    1

    21

    1

    12

    1

    11

    S

    X

    t

    t

    1

    22

    1

    21

    1

    12

    1

    11

    S

    X

    QQ

    QQ

    O

    O

    S

    X

    QQ

    QQtE .

    1t

    1t

    S

    X

    t

    t

    S

    X

    O

    O

    S

    X

    tE (19)

    Notice that equation (19) implies:

    t

    t

    1

    S

    1

    X

    t

    t

    S

    X

    O

    O

    S

    X

    T

    T

    T

    Tt

    E . (20)

    Existence and uniqueness of stable rational expectations solutions require that all

    eigenvalues contained in S have to be greater than unity so that

    O 1S

    T

    Tlim ,

    while those contained in X have to be smaller than unity (Blanchard and Kahn

    1980)..

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    10/27

    - 9 -

    1) Solution to Control Variables

    It directly follows from equation (19) that:

    t1XTt XX T

    tE

    .

    Provided that the Blanchard-Kahn condition is satisfied, since all eigenvalues in X is

    greater than one, it has to be true in order for TtX

    tE not to explode that:

    OSQXQOX t1

    12t

    1

    11t

    .

    This leads to the solution to control variables:

    tXt112111t SPSQQX 1 . (21)

    2) Solution to State Variables

    It also follows from equation (19) that:

    1t1221t1211S1t1221t121

    t

    1

    St

    SQXQSQXQ

    SS

    tt

    t

    EE

    E 1

    .

    Substituting (21) into above equation,

    tX1211221S1tX121122 SPQQSPQQ tE

    Then the solution to state variables is given by:

    tStX1211221SX1211221t SPSPQQPQQS

    1

    tE . (22)

    3.4.

    Matlab Codes

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    11/27

    - 10 -

    This subsection explains some key lines of Matlab codes written in the toolkit.

    The complete lines are provided in Appendix. The codes draw a direct line with those in

    Kato (2002).

    3.4.1. Linearization Part

    In Matlab, linearization of equilibrium conditions is implemented by taking

    Jacobian of the system of equations from (3) to (6) and evaluating it at the steady-state

    values:

    %---- Differentiation ----%

    J = jacobian ( eqcon,xx ) ;

    %---- Evaluation at the Steady State ----%

    cc = CS ;

    ca = CS ;

    lc = LS ;

    la = LS ;

    kc = KS ;

    ka = KS ;

    zc = Z ;

    za = Z ;

    coef = eval ( J ) ;

    3.4.2. Solution Part

    The Matlab function named bksolve returns mn ,,, SX PP by

    implementing the eigenvalue decomposition:

    [ Q, L ] = eig (inv(A)*B) ;

    Then the eigenvalue matrix L is vectorized and sorted in ascending order; columns of

    the matrix Q, eigenvectors associated with eigenvalues, are also rearranged in line with

    the same order:

    L = diag ( L ) ;

    [ L, order ] = sort ( diag ( L ), ascending ) ;

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    12/27

    - 11 -

    Q = Q ( : , order) ;

    The following lines count the number of control and state variables in the system, n andm.

    n = 0;

    for i = 1:length ( L )

    if abs ( L ( i ) ) < 1.0000

    n = n + 1;

    end

    end

    m = length ( L ) - n;

    Then the inverse matrix of Q is partitioned into four blocks while L is divided into

    stable and unstable roots.

    %--- Partition Matrices ---%

    QI11 = QI(1:n, 1:n);

    QI21 = QI(n+1:m+n, 1:n);

    QI12 = QI(1:n, n+1:m+n);

    QI22 = QI(n+1:m+n, n+1:m+n);

    %--- Extracting Stable Roots ---%

    L1 = L ( 1:n, : ) ;

    L2 = L ( n+1:m+n, : ) ;

    LS = diag ( L2 ) ;

    The rest of the code calculates XP and SP according to formulae (21) and (22) (see

    Appendix).

    4. Simulation with a Calibrated Model

    Once one obtains the approximated solution to a model, she can exercise a

    quantitative analysis by assigning numerical values to parameters. The strategy for

    finding numerical parameter values is called calibration.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    13/27

    - 12 -

    By imposing restriction on the mapping between theory and data, calibration

    enables us to measure the distance between an artificial model economy and its actual

    counterpart in that it identify in which dimensions the former succeeds or fails inmatching with the latter. Results of the exercise serve as guidance about refinements of

    the theoretical model or improvements in the measurements of the actual economy

    (Cooley 1997).5

    4.1. Parametarization

    Cooley (1997) provides some rules for good calibration. According to them,

    it is important to set parameter values so that the behavior of the model economy

    matches features of the measured data such that one cannot abstract from. In the

    context of the RBC model here, parameter values should be chosen so that the Kaldors

    stylized facts of economic growth are mimicked, for the underlying structure of the

    model is the neoclassical growth framework. Also, some information about individual

    choices over time such as total hours worked could be useful for setting parameter

    values related to preference specifications.

    The parameter values employed here are:

    007.0,95.0,025.0,36.0,0.2,99.0 z .

    These parameter values imply the following steady-state values, which are broadly

    consistent with the post-war U.S. experience:

    11.1,9.10,30.0,83.0 yklc .

    4.2. Impulse-Response Function

    Then one can investigate propagation and amplification mechanisms of the model

    economy by looking at impulse-response functions. Figure 1 displays the behavior of

    output, consumption, investment, hours worked, and labor productivity in response to a

    unitary shock to technology. As can be seen in the figure, consumption shows the

    smallest response among them. This is due to the optimizing behavior of households

    who have risk-averse preferences and thus want to smooth their consumption. The other

    side of the same coin is the response of investment, which is the largest among all

    5 This is an advantage of calibration exercise over classical statistical inference. Since the

    distribution theory for a standard statistical test of a model is derived under the null hypothesis, it isunlikely to provide much information about how to proceed if the test rejects the model.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    14/27

    - 13 -

    variables. Turning eyes to behavior of labor, one can see that hours worked show a

    positive response to the technology shock but it is not greater than that of output. This is

    an outcome of interaction between income- and substitution effects. While the formereffect induces the household to reduce labor supply, the latter gives incentive for

    working more. Since the latter dominates the former, the net effect is positive.

    While these results are intuitively comprehensible, it has been pointed out that the

    impulse-response functions of the RBC model have properties inconsistent with their

    empirical counterparts in some dimensions. For example, the calibrated model

    predicts positive comovement among output, hours worked, and labor productivity in

    response to a positive technology shock. However, Gal (1999) points out that an

    empirical impulse-response function estimated by a vector autoregression (VAR) shows

    a negative response of hours-worked. In addition, while Cogley and Nason (1995)

    report that a trend reverting component of U.S. output has a hump-shaped

    moving-average representation, the theoretical impulse-response of output does not

    show any such a property; it peaks at the first period in which the shock hits the

    economy.

    Figure 1

    0 5 10 15 200

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    Horizon

    %DeviationfromS

    teadyState

    Impulse Response to a Unitary Technology Shock

    Output

    Consumption

    Investment

    Hours-worked

    Labor Productivity

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    15/27

    - 14 -

    4.3. Simulated Second Moments

    Another common simulation exercise is second moment comparison between

    artificial data and their actual counterparts. Figure 2 shows an artificial time paths forconsumption, output, and investment, which are detrended by the Hodrick-Prescott filter.

    It confirms that investment fluctuates more volatilely than output while consumption is

    smoother than output, as is also true in actual data.

    But at the same time, a careful look at precise statistics sheds lights on some

    defects about the model. Table 1 reports the standard deviations of simulated series of

    output, consumption, investment, hours worked, and labor productivity, and correlations

    among them, comparing with actual data. It should be noted that 1) the calibrated model

    predict considerably less volatile output than actually observed, 2) the predicted hours

    worked is also less volatile than actual, and 3) it generates a strong comovement

    between hours-worked and labor productivity, which has not been observed in the U.S.

    experience (Hansen and Wright 1992) .

    These failures mainly results from the fact that the model economy relies solely

    on a single technology shock to generate fluctuation; not only the driving force of

    business cycle is underestimated but also the behavior of the labor market is too much

    simplified. That is, wage (=productivity) and hours worked in the model fluctuate in

    response to shifts in labor demand only, which is triggered by technology shocks. A

    strong positive correlation between them represents a stable upward sloping labor

    supply curve traced out by a labor demand curve shifting over time. This calibration

    exercise suggests that the model should take account of other impulse factors which

    have multifaceted influence on a labor market. Hansen and Wright (1992) introduce a

    shock to home production technology and stochastic government expenditure as a

    demand shock. They both affect the households choice on participation in labor market

    so that labor supply curve shifts. Hansen and Wright demonstrate that the correlation

    between hours and productivity is mitigated under the environment in which both labor

    supply and demand are shifting incessantly.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    16/27

    - 15 -

    Figure 2

    0 50 100 150-0.15

    -0.1

    -0.05

    0

    0.05

    0.1

    0.15

    0.2

    0.25

    Time Period

    %DeviationfromS

    teadyState

    Simulated Time Series Data

    Output

    Consumption

    Investment

    Table 1 Second Moments of Simulated and Actual US Data

    Standard Error

    Output

    y

    Consumption

    c / y

    Investment

    i / y

    Hours

    l / y

    Productivity

    w / y

    Simulated 0.0135 0.31 3.12 0.51 0.50

    Actual 0.0192 0.45 2.78 0.78-0.96 0.45-0.57

    Correlation with Output

    Output Consumption Investment Hours Productivity

    Simulated 1.00 0.90 0.99 0.98 0.98Actual 1.00 0.71 0.73 0.82-0.90 0.31-0.63

    Standard Error and Correlation between Hours-worked and Labor Productivity

    Hours

    l / w

    Correlation

    Simulated 1.02 0.92

    Actual 1.37-2.15 -0.14-0.07* Simulated moments are the sample means of statistics computed for 300 times simulations with 150 periods.* Actual data are reported in Hansen and Wright (1992). Sample period is 1947:1-1991:3. Statistics related to hours

    and productivity take different figures depending on which of two sources of data (household survey orestablishment survey) is used.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    17/27

    - 16 -

    5. Summary

    A DSGE framework provides a foundation for a logically coherent analysis on

    how stochastic shocks are amplified and propagated through optimizing behavior ofeconomic agents. Since equilibrium conditions in a DSGE model generally take

    non-linear forms, approximation would be helpful for making them easy to handle.

    A common exercise is to log-linearly approximate intra- and intertemporal

    optimal conditions around a steady state. A resulting approximated version of the model

    takes a form of a system of first-order expectational difference equations, which can be

    solved relying on eigenvalue decomposition.

    This paper illustrated how the technique works by taking a typical RBC model for

    an instance. Calibration of the model reveals that the RBC theory succeeds in

    explaining some features of an actual economy but fails in other important dimensions

    such as behavior of the labor market. The results of the quantitative exercise points to a

    direction in which the theory should proceed in order to reach better understanding of

    business cycle phenomena.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    18/27

    - 17 -

    Reference

    Blanchard, Oliver J., and Charles M. Kahn. The Solution of Linear Difference Modelsunder Rational Expectations.Econometrica, Vol. 48, No. 5, 1980, 1305-1311.

    Campbell, John Y. Inspecting the Mechanism: An Analytical Approach to the

    Stochastic Growth Model. Journal of Monetary Economics, Vol. 33, Issue 3,

    1994, 463-506.

    Cogley, Timothy, and James M. Nason. Output Dynamics in Real-Business-Cycle

    Models.American Economic Review, Vol. 85, No. 3, 1995, 492-511.

    Cooley, Tomas F. Calibrated Models. Oxford Review of Economic Policy, Vol. 13,

    Issue 3, 1997, 55-69.

    _________., and Edward C. Prescott. Economic Growth and Business Cycles. Tomas

    F. Cooley ed., Frontiers of Business Cycle Research, Princeton University Press,

    Princeton, New Jersey, 1994, 1-38.

    Dejong, David N., and Chetan Dave. Structural Macroeconometrics: second edition,

    Princeton University Press, Princeton, New Jersey, 2011.

    Gal, Jordi. Technology, Employment, and the Business Cycle: Do Technology Shocks

    Explain Aggregate Fluctuations? American Economic Review, Vol. 89, No. 1,

    1999, 249-271.

    Hansen, Gary D., and Randall Wright. The Labor Market in Real Business Cycle

    Theory. Federal Reserve Bank of Minneapolis Quarterly Review, Vol. 16, No. 2,

    1992, 2-12.

    Hartley, James E., Kevin D. Hoover, and Kevin D. Salyer. A Users Guide to Solving

    Real Business Cycle Models. Real Business Cycles, A Reader, Routledge,

    London and New York, 1998, 43-54.

    Kato, Ryo. A User Guide for Matlab Code for An RBC Model Solution and

    Simulation. mimeo, 2002.

    Schmitt-Groh, Stephanie and Martin Uribe. Solving Dynamic General Equilibrium

    Models Using a Second-Order Approximation to the Policy Function.Journal of

    Economic Dynamics and Control, Vol. 28, Issue 4, 2004, 755-775.

    Prescott, Edward C. Theory Ahead of Business Cycle Measurement.

    Carnegie-Rochester Conference Series on Public Policy, Vol. 25, autumn, 1986,

    11-44.

    Simon, Carl P., and Lawrence Blume. Mathematics for Economists. W. W. Norton &

    Company, London and New York, 1994.

    Uhlig, Harrold. A Toolkit for Analysing Non-linear Dynamic Stochastic Models

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    19/27

    - 18 -

    Easily. R. Marimon and A. Scott eds. Computational Methods for the Study of

    Dynamic Economies, Oxford and New York, Oxford University Press, 1999,

    30-61.

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    20/27

    - 19 -

    Appendix: Matlab Code for Simulating a DSGE Model

    A-1: Main Program modelsim.m

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Basic Real Business Cycle Model %%%% Matlab Code Written by Haruki Seitani %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    clear all%==================================================%% Initialization: Model Settings %%==================================================%%--- Deep Parmeter Values ---%alpha = 0.36 ; % Capital Income Sharebeta = 0.99; % Subjective Discount rate

    delta = 0.025; % Capital Depreciation RatePsi = 2.0 ; % Marginal Disutility of LaborZ = 1.0 ; % Mean of Aggregate Technologysigma_z = 0.007; % Standard Deviation of Technologyrho = 0.95 ; % Autocorrelation of Technology Shocks

    %--- Variales ---%syms cc lc kc zc ca la ka za;xx = [ca la ka za cc lc kc zc];% Variables with "a" / "c" denote forward/current variables, respectively% 1) Control Variables% c : Consumpton

    % l : Hours-worked% 2) State Variables% k : Capital% z : Technology

    varname = char('Consumption', 'Hours-worked', 'Capital', 'Technology');

    %--- Simulation Settings ---%% 1) Impulse-Response Analysish = 24; % Horizons of Impulse-Response Functionhit = 2; % Period in which an innovation occursimp = varname(4,:); % Variable hit by an innovationSI = [0, 1]'; % Innovation Vector

    % 2) 2nd Moments Comparisonmcreps = 300; % # of Monte-Carlo Simulationssize = 150; % Size of simulated time seriesdisc = 300; % First "disc" observations will be discarded.vars = 5; % # of variables among which 2nd moments are analyzed

    % 5 variables: y, c, i, l, y/llambda = 1600; % Smoothing parameter of HP filter

    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')disp(' Toolkit for a Standard RBC Model ')

    disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%')

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    21/27

    - 20 -

    disp('Welcome!')disp('This is a toolkit for solving and simulating an approximated DSGE model.')disp(' ')disp('First of all, the steady state of the model economy will be calculated.' )disp('Hit any key when ready......')pause;

    %==================================================%% Calculation of the Steady State %%==================================================%disp('=========================================')disp(' Steady State ')disp('=========================================')disp(' K/Y CS KS LS YS IS')

    KY = 1/((1-beta*(1-delta))/(alpha*beta*Z));CY = 1-delta*KY;LS = 1/(1+Psi/((1-alpha)/CY));KS = LS*(alpha*beta*Z/(1-(beta*(1-delta))))^(1/(1-alpha));YS = Z*(KS^alpha)*(LS^(1-alpha));IS = delta*KS;CS = YS - IS;

    s = [CS, LS, KS, Z];

    disp([KY, CS, KS, LS, YS, IS]);

    disp('Then the equilibrium conditions are linearized around the steady state,')disp('and the solution to the approximated system will be found.')disp('Hit any key when ready......')pause;

    %===================================================%% Equilibrium Conditions %%===================================================%%---- Intratemporal Optimality Condition ----%intra = Psi/(1-lc) - (1-alpha)*zc*((kc/lc)^(alpha))*(1/cc);

    %---- Intertemporal Optimality Condition ----%inter = beta*(alpha*za*(la/ka)^(1-alpha) + (1-delta))*(1/ca) - (1/cc);

    %---- Resource Constraint ----%resource = zc*(kc^alpha)*(lc^(1-alpha)) + (1-delta)*kc - cc - ka;

    %---- Dynamics of Technology Shock ----%tech = za - zc^rho;

    %---- Optimal Conditions ----%eqcon = [intra; inter ; resource; tech ];

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    22/27

    - 21 -

    %===================================================%% Linearization and Solving the Model %%===================================================%%---- Differentiation ----%J = jacobian(eqcon,xx);

    %---- Evaluation at the Steady State ----%cc = CS;ca = CS;kc = KS;ka = KS;lc = LS;la = LS;zc = Z;za = Z;

    coef = eval(J);SS = [ s ; s ; s ; s];

    %---- Solving the Model ----%[PX, PS, n, m] = bksolve(SS,s,coef);

    %===================================================%% Impulse-Response Function %%===================================================%disp('Next, responses to a technology shock are to be displayed.')disp('Hit any key when ready......')

    disp(' ')pause;

    SC = SI; % SI will initially be used as the current state vector% SC will be revised recursively.

    S = zeros(h, m); % Simulated state variables% which will be revised as the simulation proceeds.

    for i = hit:h % Shock occurs in s-th period; matrix S is revised from 6throw.SA = PS*SC ; % New state vectorS(i,:) = SA'; % Revise i-th row of state matrixSC = S(i,:)' ; % Use revised i-th row of state matrix

    % as state vector in next period.end

    S(hit,:) = SI; % Simulated endogenous & exogenous state variablesX = (PX*S')'; % Simulated jump variables

    Y = [X, S];

    ct = Y(:, 1);lt = Y(:, 2);kt = Y(:, 3);

    zt = Y(:, 4);

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    23/27

    - 22 -

    yt = Y(:, 4) + alpha*Y(:, 3) + (1-alpha)*Y(:, 2); % Outputit = (YS/IS)*yt - (CS/IS)*Y(:, 1); % Investmentwt = yt - Y(:,2); % Marginal Product of Labor

    %---- Graphics ----%t = 1:length(yt);set(gca, 'Fontsize', 12);plot(t, yt,'k-', t, ct,'m--+', t, it,'r-.o', t, lt,'b:s', t, wt,'c:*',...

    'Linewidth', 1.5, 'Markersize', 4.5');axis([0,h,0,Inf]);xlabel('Horizon');ylabel('% Deviation from Steady State');title('Impulse Response to a Unitary Technology Shock', 'Fontsize', 14);legend('Output', 'Consumption', 'Investment', 'Hours-worked', 'Labor

    Productivity');

    %===================================================%% 2nd Moments of Simulated Time Series %%===================================================%disp('Finally, the model will be simulated to show 2nd moments of artificial time

    series.')disp('Hit any key when ready......')pause;

    sstd = zeros(mcreps,vars);sstdy = zeros(mcreps,vars);scorr = zeros(mcreps,vars);

    scorrpl = zeros(mcreps, 2);

    for i = 1:mcreps%--- Generating Shock Variables ---%

    eps = zeros(ssize+disc, m);shock = sigma_z*randn(ssize+disc,1);eps(:, 2) = shock;

    %--- Generating State Variables ---%SI = [0 0]';Sc = SI;S = zeros(ssize+disc, m);for j = 1:ssize+disc

    Sa = PS*Sc+(eps(j,:))' ;S(j,:) = Sa';Sc = S(j,:)' ;

    endS(1,:) = SI;

    %--- Generating Control Variables ---%X = (PX*S')';

    Y = [X, S];kt = Y(disc+1:disc+ssize, 3);zt = Y(disc+1:disc+ssize, 4);

    ct = Y(disc+1:disc+ssize, 1);

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    24/27

    - 23 -

    lt = Y(disc+1:disc+ssize, 2);yt = zt + alpha*kt + (1-alpha)*lt;it = (YS/IS)*yt - (CS/IS)*ct;wt = yt - lt;

    simy = [yt, ct, it, lt, wt];

    %--- Hodrick-Prescott Filter ---%simy = hpfilter(simy, lambda)*simy;

    %--- Second Moments of Simulated Series ---%sstd(i,:) = std(simy);sstdy(i,:) = sstd(i,:)/sstd(i,1);correlations = corrcoef(simy);scorr(i,:) = correlations(1,:);scorrpl(i,:) = [sstd(i,4)/sstd(i,5), correlations(4,5)];

    end

    %--- Monte-Carlo Average of Simulated Moments ---%disp('=========================================')disp(' Second Moments of Simulated Series ')disp('=========================================')disp(' ')disp('--- S.D. of y, c, i, l, y/l ---')MCSTD = mean(sstd);disp(MCSTD);

    disp('--- S.D. Relative to y ---')

    MCSTDY = mean(sstdy);disp(MCSTDY);

    disp('--- Correlation with y ---')MCCORR = mean(scorr);disp(MCCORR);

    disp('--- S.D.(l vs y/l) & Corr. b/w l and y/l ---')MCCORRPL = mean(scorrpl);disp(MCCORRPL);

    %--- Graphics ---%t = 1:length(yt);

    set(gca, 'Fontsize', 12);plot(t, yt,'k-', t, ct,'m:+', t, it,'r-.o',...

    'Linewidth', 1.0, 'Markersize', 3.0');xlabel('Time Period');ylabel('% Deviation from Steady State');title('Simulated Time Series Data', 'Fontsize', 14);legend('Output', 'Consumption', 'Investment');

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    25/27

    - 24 -

    A-2: Difference Equations Solver bksolve.m

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Solving First-Order Difference Equations %%%% by Blanchard and Kahn(1980)'s Method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    function [PX, PS, n, m] = bksolve(SS,s,coef)%==============================================%% Coefficient Matrices %%==============================================%%---- Coefficients Associated with Current Variables ----%A = [ coef(:, 1+size(coef,2)/2:size(coef,2))].*SS ;

    %---- Coefficients Associated with Forward Variables ----%

    B = [ -coef(:, 1:size(coef,2)/2)].*SS ;

    % NOTE% A*Y(t) = B*Y(t+1)% Y(t) = inv(A)*B*Y(t+1)

    %==============================================%% Eigenvalue Decomposition %%==============================================%

    %--- Eigenvalue Decomposition ---%[Q,L] = eig(inv(A)*B); % columns of Q : eigenvectors

    % diagonal matrix L : eigenvalues% Q*L*inv(Q) = inv(A)*B

    %--- Reordering Eigenvalues and Eigenvectors ---%disp('=========================================')disp(' Eigenvelues ')disp('=========================================')

    L = diag(L); % vectorize eigenvaluesdisp(L);[L, order] = sort(abs(L), 'ascend');

    % sort eigenvalues in ascending orderQ = Q(:, order); % reorder eigenvectors associated with their eigenvalues

    QI = inv(Q); % Q-inverse

    %--- # of Eigenvalues Inside/Outside a Unit Circle ---%% 1) # of Control Variables X(t)n = 0;for i = 1:length(L)

    if abs(L(i)) < 1.00000n = n + 1;

    endend

    % 2) # of State Variables S(t)

    m = length(L)-n;

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    26/27

    - 25 -

    %--- Partition Matrices ---%QI11 = QI(1:n, 1:n);QI21 = QI(n+1:m+n, 1:n);QI12 = QI(1:n, n+1:m+n);QI22 = QI(n+1:m+n, n+1:m+n);

    %--- Extracting Stable Roots ---%L1 = L(1:n, :);L2 = L(n+1:m+n, :);VL = diag(L(n+1:n+m,:));

    %==============================================%% Solution to the System %%==============================================%

    %--- Solution to Control Variables ---%disp('==========================================')disp(' Coefficient Matrix for Control Variables ')disp('==========================================')

    PX = -inv(QI11)*QI12;disp(PX);% QI11*X(t) + QI12*S(t) = 0% X(t) = -inv(QI11)*QI12*S(t)

    %--- Solution to State Variables ---%disp('==========================================')

    disp(' Coefficient Matrix for State Variables ')disp('==========================================')

    PS = inv(QI22+QI21*PX)*inv(VL)*(QI22+QI21*PX);PS = real(PS);disp(PS);

  • 8/9/2019 Seitani(2013)Toolkit for DSGE

    27/27

    - 26 -

    A-3: Hodrick-Prescott Filter hpfilter.m

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %% Hodrick-Prescott Filter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    function [hp_y]=hpfilter(y,lambda);

    %--- Input Arguments ---% lambda: smoothing parameter% y: original series%% NOTE% lambda = 100 for yearly data% lambda = 1600 for quarterly data% lambda = 14400 for monthly data% are commonly used.%%--- Output ---% hp_y: filtering matrix%% NOTE% hp_y*y = y_hpfiltered

    if size(y,1)