• No results found

e550 hw2

N/A
N/A
Protected

Academic year: 2020

Share "e550 hw2"

Copied!
9
0
0

Loading.... (view fulltext now)

Full text

(1)

Homework 2 for Computational Macro

Instructor: Grey Gordon

Due date: Monday, 11/04/13

Instructions

Provide the code and derivations necessary to answer the questions. You must use Fortran for this assignment. Feel free to ask each other questions when things are unclear, but the answers and code should be specific to you (if you have questions about my policy regarding this, ask). REMEMBER TO CITE ALL YOUR SOURCES OR I WILL BE FORCED TO CITE YOU FOR PLAGIARISM! You should begin to work on the project soon as it will likely take a significant amount of time to complete and more time than you think.

If you find any errors, please let me know ASAP so I can fix them and tell the class.

NOTE: If you finish this homework successfully, then know that your computational prowess exceeds that of the vast majority of economists.

Code Toolbox

Do the following:

1. Create a module calledmod interp. In it, define a derived typespline:

type s p l i n e

i n t e g e r :: n = -1 ! N u m b e r of k n o t s

real(8) , a l l o c a t a b l e :: k (:) ! K n o t s

real(8) , a l l o c a t a b l e :: co (: ,:) ! C o e f f i c i e n t s

end type

2. Add to the module a functionbsearchthat uses binary search to find the location of x in a sorted list {xi}ni=1. It should have the following

(2)

f u n c t i o n b s e a r c h ( xhat , x ) r e s u l t( ilo ) i m p l i c i t none

real(8) , d i m e n s i o n(:) , i n t e n t(in) :: x real(8) , i n t e n t(in) :: xhat

i n t e g e r :: ilo

Further, it should have the following properties:

• Ifx < x1, ilo = 1.

• Ifx∈[xi, xi+1) for some i∈ {1, . . . , n−1}, iloshould equal i. • Ifx≥xn,ilo=n-1 not n.

This way, bsearch always returns the index of the lowerbound of an interval[x(ilo),x(ilo+1)]that can be used for interpolation (or ex-trapolation). Note: ilo is always in 1 to n-1.

3. Add to the module a subroutinesub schumakerthat constructs a piece-wise polynomial using a Schumaker spline. It should have the following interface:

s u b r o u t i n e s u b _ s c h u m a k e r ( pp , x , y )

! use any m o d u l e s here

i m p l i c i t none

real(8) , d i m e n s i o n(:) , i n t e n t(in) :: x , y type( s p l i n e ) , i n t e n t(out) :: pp

This routine should construct a Schumaker spline using the data x,y. Note that the number of knots,pp%n, the knotspp%k, and the coefficient

pp%co depend on the data x and y data in a non-trivial way.

4. Add to the module a routineppval that evaluates a piecewise polyno-mial. It should have the following interface:

! E v a l u a t e s the p i e c e w i s e p o l y n o m i a l

! y = pp % co ( i ,1) + pp % co ( i ,2)( x - pp % k ( i )) + ! pp % co ( i ,3)( x - pp % k ( i ) ) * * 2 + ... for ! x \ in [ pp % k ( i ) , pp % k ( i +1)]

f u n c t i o n p p v a l ( x , pp ) r e s u l t( y )

! use any m o d u l e s here

i m p l i c i t none

type( s p l i n e ) , i n t e n t(in) :: pp real(8) , i n t e n t(in) :: x

(3)

To do the evaluation, you should use binary search (since the knots will be sorted) and Horner’s method.

5. Add to the module a routine interp1q that constructs a linear inter-polation of the data assuming x is sorted and evaluates it. It should have the following interface:

f u n c t i o n i n t e r p 1 q ( x , y , xi ) r e s u l t( yi )

! use any m o d u l e s here

i m p l i c i t none

real(8) , i n t e n t(in) :: x (:) , y (:) , xi (:) real(8) :: yi (size( xi ))

To find the location of each xi in the x, you should use binary search (since the knots are sorted). The actual interpolation step is very simple once you have this.

6. Add a routine tomod bellman:

s u b r o u t i n e s u b _ b e l l m a n _ c o n t i n u o u s ( V , c , ap ,& W , y , x , gAP , nA , nE , Ap , crra )

! use any m o d u l e s here

i m p l i c i t none

integer, i n t e n t(in) :: nA , nE , nAp

real(8) , d i m e n s i o n( nA , nE ) , i n t e n t(out) :: V , c , ap real(8) , d i m e n s i o n( nA , nE ) , i n t e n t(in) :: y

real(8) , d i m e n s i o n( nAp , nE ) , i n t e n t(in) :: W , x

real(8) , d i m e n s i o n( nAp ) , i n t e n t(in) :: gAP ! grid for AP

real(8) , i n t e n t(in) :: crra

This routine should solve

V(a, e) = max

a0

c1−crra

1−crra+ ˆW(a

0

, e)

s.t.c+ ˆx(a0, e) =y(a, e)

where ˆW(a0, e) is the Schumaker spline interpolation of using the data

{gAP,W(:,iE)}and ˆx(a0, e) is the linear interpolation of the data{gAP,x(:,iE)}. The routine should assume the objective function is concave.

(4)

(a) Construct a 10,000 point grid linearly spaced from gAP(1) to

gAP(nAp).

(b) Get the Schumaker spline interpolated values of ˆW(a0, e) on this grid.

(c) Get the linearly interpolated values of ˆx on this grid.

(d) Call sub bellman discrete assuming concavity (opt==2) from HW1 to find the optimal policy indices.

HINT: when you callsub bellman discrete, it will look like this:

call s u b _ b e l l m a n _ d i s c r e t e (&

V , c , api , What , y , xhat , nA , nE ,10000 , crra ,2)

whereWhatandxhatare the interpolated values. Now you see one reason why we did not assumenAp==nAinsub bellman discrete!

(e) Recover ap using api and gAP.

Theoretical Model

One of the most powerful and widely used models in macro—and even struc-tural micro—is the Overlapping Generations (OLG) model first introduced by Samuelson in the 1950s. Consider the following standard OLG / life-cycle economy (different names, essentially the same thing). We will look only at steady state equilibrium. Consequently, aggregates such as capital and labor and the invariant distribution and prices will not have time indices. The time subscripts indicate a generation’s/household’s individual variables which do evolve period by period.

Sequential Formulation

At any point in time, there are a continuum of finitely lived households with total measure 1. Households live for t = 1, . . . , T <∞periods. They do not value leisure and have preferences over consumption given by

T

X

t=1

βtu(ct). (1)

Assume u(c) =c1−σ/(1σ) and σ = 2.

(5)

marginal product with the wage w= (1−α)(K/N)−α and the rental rate on capital r=α(K/N)α−1. Capital depreciates at rateδ.

Household are each endowed with a unit of time. However they differ in their productive efficiency eof their unit of time. Since leisure is not valued, households use all their time endowment. Consequently, a household’s total earnings arewet. As is standard in the literature, assume eevolves according

to

loget=ρloget−1+σt, t∼N(0,1)

for t >1 with e1 = 1.

Household’s have access to one asset, a claim to capital (hence markets are incomplete). The price is 1 and the return is 1 +r−δ. Let at+1 denote

the amount purchased by a households of age t. Household’s are subject to some borrowing limit A such that at+1 ≥A. We will assume A= 0, but

this is not necessary.

The household maximization problem can be written as

max

{at+1}Tt=1−1

T

X

t=1

βtu(ct). (2)

subject to

ct+at+1 =wet+ (1 +r−δ)at fort < T

cT =weT + (1 +r−δ)aT

ct≥0, at+1 ≥0

a1, e1 given.

(3)

For a given w and r, household policies induce an invariant distribution µ(a, e, t) over asset holdings, efficiency, and age. The market clearing condi-tions for the economy are

K =

Z

adµand N = Z

edµ (4)

Recursive Formulation

The sequential problem has a recursive formulation given by

V(a, e, T) =u(we+a(1 +r−δ)) (5)

for t=T and

V(a, e, t) = max

a0 u(c) +βEeV(a 0

(6)

subject to

c+a0 =we+a(1 +r−δ)

c≥0, a0 ≥0 (7)

for t < T. This delivers asset policiesa0(a, e, t)∀a, e, t < T. Let a0(a, e, T) = 0.

Any policya0(a, e, t), implies a unique corresponding distributionµ(a, e, t) given initial conditions. For t = 1, assume households are born with zero assets (and recall e = 1). Then, in the discrete version1 of the model a ∈

A, e∈E, we have

µ(a, e, t = 1) = 1[a= 0, e= 1]

T . (8)

The distribution for t = 1 is divided by T because there is no population growth or mortality risk in this model, so each generation has measure 1/T.

If we know µ(a, e, τ) for some τ < T, we have

µ(a0, e0, τ + 1) =X

a,e

1[a0 =a0(a, e, τ)]F(e0|e)µ(a, e, τ). (9)

Hence, by forward induction, we can compute µ(a, e, t) for all t.

A steady state recursive equilibrium is pricesr, w, capital and laborK, N, a distribution µ, and policies and value functions such that

1. Given prices, households optimize and the value/policy functions are correct.

2. The distribution implied by household policies and stochastic transi-tions and is invariant, µ= Γµ.

3. Markets clear, K =R adµ, N =R edµ.

4. Firms optimize / prices are given by their marginal products (which are functions of K and N).

Empirical Section

For this section, assume β =.96, α=.36, δ=.1, ρ=.963, σ =.125, σ = 2,

and T = 60 (this gives a common annual calibration).

1The discrete version is nice because there are no measurability issues. The

con-tinuous version says something along the lines of µ(A, E, t) = R 1[a0(a, e, t −1) ∈

(7)

Using Tauchen (1986), discretize the et process. Use ne = 7. Create an

A grid with 200 equally spaced points from 0 to 200 (the E grid comes from Tauchen).

Write a routine that computes the equilibrium of this model. Do this as follows:

1. Write a routine that, givenK/N, computesw,r, and solves the house-hold problem:

(a) Compute the value function fort=T for each a∈A and e∈E.

(b) Fort < T and givenV(·,·, t+ 1), computeV(a, e, t) and a0(a, e, t) as follows:

i. Fix a∈A and e ∈E.

ii. Compute the expectation W(a0, e, t) = EeV(a0, e0, t+ 1) for

eacha0 ∈A.

iii. Callsub bellman continuousto computeV(a, e, t) and poli-ciesc(a, e, t) anda0(a, e, t). HINT: when you call it, it will look like

call s u b _ b e l l m a n _ c o n t i n u o u s ( V (: ,: , t ) , c (: ,: , t ) ,...)

2. Compute an approximation to the invariant distribution associated with an a0 policy as follows:2

(a) Letµ(a, e, t = 1) be given, as in the theory, by 1/T∗1[a= 0, e= 1] (this only works if a=0 and e=1 are on your grid, which they should be).

(b) Now, given µ(a, e, t) for some t and each a ∈ A, e ∈ E, compute µ(a0, e0, t+ 1) as follows:

i. Set µ(a0, e0, t+ 1) = 0 for all a0 ∈A, e0 ∈E.

ii. For each a ∈ A, e ∈ E, distribute the measure µ(a, e, t) of households of that type into their appropriate slots.

2Note: in the literature there is an alternative way to compute statistics of the invariant

distribution. Specifically, you can take a large sample of households S, say 10,000 to 100,000, and simulate their individual paths to obtain {as

t} S,T

s=1,t=1. Then an estimate of

the capital stock is K = R

adµ(a, e, t) ≈ 1 S 1 T

P

s,ta s

t. (Keeping track of est leads to a

similar estimate of N. This method works to compute estimates of R

f(a, e, t)dµ(a, e, t) for any f. This is Monte Carlo integration, and is generally inefficient relative to the

(8)

A. First, find theis.t.a0(a, e, t)∈[ai, ai+1] (forai, ai+1 ∈A).

Use binary search to do this step.

B. Compute θi = (ai+1−a0(a, e, t))/(ai+1−ai). This is the

weight / probability mass that would be placed on theai

grid point from linear interpolation.

C. AddθiF(e0|e)µ(a, e, t) toµ(ai, e0, t+1) and (1−θi)F(e0|e)µ(a, e, t)

toµ(ai+1, e0, t+ 1).

(c) Once you’ve reachedt =T, you have found the entire distribution (really, a close approximation of it).

3. With the invariant distribution, compute the implied K/N ratio:

(a) K =P

a,e,taµ(a, e, t)

(b) N =P

a,e,teµ(a, e, t)

(c) K/N

4. Compute the steady state equilibrium using fixed point iteration. That is, do the following

(a) Make a guess on the capital-labor ratio, (K/N)guess. A decent

guess is 4.

(b) Solve the household problem, compute the invariant distribution, and compute the implied capital-labor ratio. Call it (K/N)implied.

(c) If|(K/N)guess−(K/N)implied|<10−5, stop. (K/N)guessis a decent

approximation to the steady state value. O/w, make a new guess on the ratio,

(K/N)guess =λ(K/N)implied+ (1−λ)(K/N)guess

and go to 2.

If λ is chosen close enough to 0, this thing should converge. A λ value of around .05 should work.

Questions

Answer/do all the following:

(9)

2. For K/N = 4, plot the marginal distribution over assets evaluated at t = 5, i.e. P

eµ(a, e, t= 5)).

3. For K/N = 4, plot the marginal distribution over assets evaluated at t = 30, i.e. P

eµ(a, e, t = 30)). How does the distribution differ form

t = 5.

4. For K/N = 4, plot average wealth by age, i.e. P

a,eaµ(a, e, t)/µ(t) for

each t. Interpret household savings behavior.

5. For eachK/N in {2,3,4,5,6,7,8,9,10}, plot the impliedK/N.

6. Since in equilibrium, the initialK/N must equal the implied, visually, what should the equilibrium level be?

7. Generally speaking, we do not have any theoretical proofs of uniqueness of equilibrium in these models. Do you see any evidence of multiplicity?

8. What are the equilibrium levels of r, w, K, N, Y = F(K, N), and C =R c(a, e, t)dµ?

9. Report the time required to compute equilibrium.

10. In the definition of equilibrium, I omitted the goods market clearing condition. This condition can be written3

C+δK =Y.

Walras’ law says that if all but one market clearing conditions are met, then the last one will be met as well. Is this true in your code? That is, what is

C+δK −Y

in your code? If this is significantly different from 0, you have an error!

11. In the steady state of a representative agent model (like in Homework 1), one has β(1 +r−δ) = 1. What is β(1 +r−δ) in this model? Do you have any interpretation for this result?

References

Related documents