You are on page 1of 5

An Introduction to Gensys

Nora Traum1

Gensys is a MATLAB program written by Chis A. Sims to solve stochastic linear rational
expectations models. This document provides a brief introduction about using the program.
The MATLAB files, in addition to Sims’ (2001) paper that explains the mechanics behind the
program, can be downloaded from Sims’ website at: http://sims.princeton.edu/yftp/
gensys/2 .

The program gensys.m is called from MATLAB by a statement of the form:

[G,C,M,fmat,fwt,ywt,gev,eu] = gensys(G0,G1,C,Psi,Pi,div)

The arguments on the right hand side are the user specified inputs. The first five correspond
to the to the five coefficients in our canonical form for a rational expectations system:

G0 yt+1 = G1 yt + Ψt+1 + Πηt+1 + C (1)

where y is a vector of the variables in the model,  is a vector of the exogenous random
variables, C is a vector of constants, and η is a vector of forecast errors satisfying Et ηt+1 =
0. Specifically, the element η x of η is defined as

x
ηt+1 ≡ xt+1 − Et xt+1

The last argument, div, determines the size of root that is treated as “unstable” for de-
termining existence and uniqueness. By default, if this argument is omitted, the program
assumes that any root strictly greater than one must be suppressed in the solution, while
roots that have an absolute value of one are retained. Although it is useful to know what
this argument does, it is highly probable you will never need to specify this value since most
of the time the default value is what we want.

The output of the program determines the coefficients in a “solved” system of the form

X
yt+1 = Gyt + M t+1 + C + {(ywt)(fmat)s (fwt)Et t+s+2 }
s=0

Note that with the assumption that the ’s are mean zero iid random variables, the last term
1
December 2, 2008. Indiana University Bloomington. Please report any typos to ntraum@indiana.edu
2
You will need qzswitch.m and qzdiv.m along with gensys.m to use the program.

1
is equal to zero. The returned value eu is a 2 x 1 vector whose first element characterizes
existence of an equilibrium (1 if true and 0 if false) and whose second element characterizes
uniqueness of the equilibrium (1 if true and 0 if false). Thus, we hope to get eu = [1 1].
If you mess up where you put your variables, severely mess up an equation, or commit a
gross programming error, you will often end up with strange results for eu. For instance, eu
= [−2 −2] indicates indeterminacy due to singularity, and the first element of eu equal to
-1 indicates that there is existence only for the  term.

Finally, the returned value gev is the generalized eigenvalue matrix. Its second column
divided by its first column is the vector of eigenvalues of G−1
0 G1 if G0 is invertible, and its
first column divided by its second column is the vector of eigenvalues of G0 G−1 1 if G1 is
invertible.

Examples

Neoclassical Growth Model

Consider the stochastic neoclassical growth model:



X c1−γ
t −1
max∞ E0 βt
{ct ,kt+1 }t=0
t=0
1−γ
s.t. ct + kt+1 ≤ zt ktα + (1 − δ)kt
ln(zt ) = (1 − ψ) ln(z̄) + ψ ln(zt−1 ) + t
ct , kt+1 ≥ 0, t ∼ i.i.d. N (0, σ 2 ), k0 given

where x̄ denotes the steady state value of variable x. The Euler equation for this model is
given by
c−γ
t = βEt c−γ α−1
t+1 [αzt+1 kt+1 + (1 − δ)]

Defining the variable rt to be the real return to capital at time t, the Euler equation can be
rewritten as

c−γ
t = βEt c−γ α−1
t+1 rt+1 , where rt+1 = αzt+1 kt+1 + (1 − δ)

In order to get the model in a form that is compatible with Gensys, it is best to linearize
the model, either in logs or in levels. We will use log-linearization, defining x̂t to be the

2
log deviation of the variable x from its steady state value at time t. The log-linearized
equilibrium conditions are given by3

Et [γ(ĉt − ĉt+1 ) + r̂t+1 ] ≈ 0


k̄ ȳ k̄
ĉt + k̂t+1 ≈ ẑt + r̄k̂t
c̄ c̄ c̄
r̂t+1 ≈ (1 − β(1 − δ))[ẑt − (1 − α)k̂t ]
ẑt = ψẑt−1 + t

At this point we still need to do one more thing to get the model into a form that Gensys
can use. That is, we must eliminate the expectation terms in the Euler equation by defining
forecast errors. We can do this by rewriting the Euler equation the following way:

− γĉt ≈ −γEt ĉt+1 + γĉt+1 − γĉt+1 + Et r̂t+1 + r̂t+1 − r̂t+1


c r
→ −γĉt ≈ −γĉt+1 + r̂t+1 + γηt+1 − ηt+1

where we have created forecast errors for the variables c and r. Now the equations are
written in a form that is consistent with equation (1) and the Gensys’ inputs:
         
−γ 0 1 0 ĉt+1 −γ 0 0 0 ĉt 0 −γ 1 "
          c #
 0
 0 1 −(1 − β(1 − δ))
 k̂t+2  =  0
   −(1 − β(1 − δ))(1 − α) 0 0 k̂t+1  + 0 t+1 + 0
     0
 ηt+1
 1 k̄ −ȳ k̄r̄ r
 c̄ 0 c̄   r̂t+1   0
   
c̄ 0 0   r̂t  0
      0
 0
 ηt+1
0 0 0 1 ẑt+1 0 0 0 ψ ẑt 1 0 0
| {z }
η
| {z } | {z } | {z } | {z } |{z} | {z } t+1
G0 yt+1 G1 yt Ψ Π

All that remains is to enter the model equations into MATLAB and run Gensys.

Adding Forward and/or Lag Variables

Consider the following utility function with internal habit formation

(ct − hct−1 )1−γ − 1


u(ct , ct−1 ) =
1−γ

With this utility function, the log-linearized Euler equation from the previous example is
now given by

−γ[1 + h(1 + βh)]ĉt + γhĉt−1 ≈ −γ[1 + h(1 + βh)]Et ĉt+1 + γβhEt ĉt+2 + (1 − βh)(1 − h)Et r̂t+1
3
For details of these derivations, refer to Uhlig’s toolkit paper http://www2.wiwi.hu-berlin.de/
institute/wpol/html/toolkit.htm.

3
How can we handle the ĉt−1 and Et ĉt+2 terms with our Gensys notation? By defining lead
and lag variables! First, we define a variable X c such that Xt+1
c
≡ Et ĉt+2 . Notice that this
implies
Xc
ct+1 = Xtc + ηt+1
Second, we define a variable Y c such that Yt+1
c
≡ ĉt . With these two new variables, we can
write the system of equations for Gensys as
  
−γ[1 + h(1 + βh)] 0 (1 − βh)(1 − h) 0 γβh 0 ĉt+1
  

 0 0 1 −(1 − β(1 − δ)) 0 0  k̂t+2 
 
k̄ −ȳ

 1 c̄ 0 c̄ 0 0  r̂t+1 
 

  

 0 0 0 1 0 0
 ẑt+1 

1 0 0 0 0 0  c 
 Xt+1 


c
0 0 0 0 0 1 Yt+1
| {z } | {z }
G0 yt+1
      
−γ[1 + h(1 + βh)] 0 0 0 0 γh ĉt 0 −γ 1 0
      

 0 −(1 − β(1 − δ))(1 − α) 0 0 0 0 k̂t+1  0
     0 0 0 
  ηc

k̄r̄ t+1
 0 c̄ 0 0 0 0   r̂t  0
    
 0 0 0  r 
 
= +  +  η 

 ẑt  1 t+1  0 0 0 t+1

 0 0 0 ψ 0 0  Xc
 0 0 1 ηt+1
     
 0 0 0 0 1 0  X c  0
  t      | {z }
ηt+1
1 0 0 0 0 0 Ytc 0 0 0 0
| {z } | {z } |{z} | {z }
G1 yt Ψ Π

Incorporating Moving Average Components

Consider the following process for technological productivity

ln(zt ) = (1 − ψ) ln(z̄) + ψ ln(zt−1 ) + t−1

Now, instead of a shock occurring at time t, the “shock” at time t − 1 affects technological
productivity at time t. In other words, we have one period news about a future change in
technological period, and at time t, technological productivity is known with certainty. How
can we incorporate such a process into our Gensys notation? By creating a new variable

4

Xt+1 = t+1 and using this variable in our system of Gensys equations:
  
−γ 0 1 0 0 ĉt+1
 0 0 1 −(1 − β(1 − δ)) 0  k̂t+2 
  
−ȳ
   
 1 k̄
 c̄ 0 c̄ 0  r̂t+1 
 
 0 0 0 1 0  ẑt+1 
  

0 0 0 0 1 Xt+1
| {z } | {z }
G0 yt+1
      
−γ 0 0 0 0 ĉt 0 −γ 1
 0 −(1 − β(1 − δ))(1 − α) 0 0 0 k̂t+1  0  0 0 " c #
      
       ηt+1
= k̄r̄  r̂t  + 0 t+1 +  0
 0 c̄ 0 0 0     0
 ηr
 t+1
 0 0 0 ψ 1  ẑt  0  0 0 | {z
     
}
 ηt+1
0 0 0 0 0 Xt 1 0 0
| {z } | {z } |{z} | {z }
G1 yt Ψ Π

With these techniques, we can transfer any linearized system of equations into a system for
Gensys, and use the Gensys program to see if we get a unique solution!

You might also like