• No results found

e550 hw1

N/A
N/A
Protected

Academic year: 2020

Share "e550 hw1"

Copied!
8
0
0

Loading.... (view fulltext now)

Full text

(1)

Homework 1 for Computational Macro

Instructor: Grey Gordon

Due date: 09/26/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.

Code Toolbox

Do the following (and probably in this order):

1. Create amod matlab.f90with a modulemod matlab. Insidemod matlab

place

(a) function linspace(a,b,n) result(x)doing the same thing as Matlab’s linspace

(b) function normcdf(x,var,mean) result(F)replicating Matlab’s normcdf. Hint: you’ll need to use the error function erf. See wikipedia.

(c) a parameter calledpi with at least 20 decimal places.

(2)

(a) subroutine sub tauchen(logy,Fyy,ar1,cdnal stdev,cover,n)

that uses Tauchen’s method to discretize the process

logy=ρlogy−1+σε, ε∼N(0,1)

where ρ = ar1 and σ = cdnal stdev. Use a coverage of cover

and n points. Take care of the special case of n = 1. Use the convention that Fyy(iy,iyp)= F(y0|y)

Hint: uselinspace and normcdf! Also, add a check ensuring the rows of the transition matrices sum to 1.

3. Create a mod bellman.f90 with a module mod bellman. Inside the module, place

(a) s u b r o u t i n e s u b _ b e l l m a n _ d i s c r e t e ( V , c , api , W , y , x ,& nA , nE , nAp , crra , opt )

i m p l i c i t n o n e

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

r e a l(8) , d i m e n s i o n( nA , nE ) , i n t e n t(out) :: V , c

integer, d i m e n s i o n( nA , nE ) , i n t e n t(out) :: api

r e a l(8) , d i m e n s i o n( nA , nE ) , i n t e n t(in) :: y

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

r e a l(8) , i n t e n t(in) :: c r r a

This routine should solve the general bellman equation

V(a, e) = max

a0

c1−crra

1−crra+W(a

0, e)

subject to

c+x(a0, e) = y(a, e)

for a0 lying in some discrete grid (note: what the actual grid is here does not matter!).

Depending on the value of opt, the routine should do three dif-ferent optimizations:

i. opt=0: Brute-force grid search

ii. opt=1: Assume thea0 policy function is weakly monotonic in

a, i.e., a1 ≤a2 =⇒ a0(a1, e)≤a0(a2, e) for all e.

iii. opt=2: Assume thea0policy function is weakly monotone and also that the objective function is concave in a0.

(3)

5. Create a main.f90 with a program called main. Inside, place nothing for now.

6. Download mod plot.f90 and test plot.f90 from https://sites. google.com/site/greygordon/code. Compile the test program using the instructions on the website and make sure that you can produce a basic plot. You’ll have to have gnuplot installed. I put a link to gnuplot and some instructions about installing it in the teaching section of my website.

Note: my code has no built in option to save the plot to file. This is because for all my serious plotting needs I save the variables to files, load them into Matlab, and do the plotting there. When I request you to plot things below, you can use a very basic technique—a “screen grab”— to save the objects to file. To learn how to do a screen grab, just google screen grab and your OS. You’ll have to figure out a better way to do your plots in the future (either you can become more proficient with gnuplot than I am or you can do what I do and plot in Matlab/Octave).

Theoretical Setup

You will apply the above code to solve the neoclassical growth model with inelastic labor supply:

max

X

t=0

βtu(ct) (1)

subject to

ct+it =F(zt, kt)

kt+1 =it+ (1−δ)kt

ct≥0, kt≥0,

logzt=ρlogzt−1+σεt,

k0 given, z0 given, εt∼ N(0,1)

(2)

Assume the following preferences and technology:

u(c, l) = c

1−γ

1−γ(with γ = 1 log) F(z, k) =zkα.

(4)

Theoretical Section

Questions

1. What are the nonstochastic (i.e. σ = 0) steady state values of ct

yt,

it

yt,

kt

yt, zt, yt :=F(zt, kt), ct,it, and kt? NOTE: you need not give explicit

formulas for each, but can instead show how to solve for each starting with only parameter values.

2. What is the recursive formulation? Do not use time indices, but rather the recursive prime (’) notation.

3. Taking FOCs and applying the Benveniste-Scheinkman theorem, derive the Euler equation.

Empirical Section

For the remaining questions, letβ =.99,δ=.025,ρ=.95,σ =.007,α=.36,

γ = 2. Place these parameters as variables with the parameter attribute in

mod param. Also, place variableskSS,cSS,... giving the steady state values of common variables. Finally, place integer parametervariablesnK=250 and

nZ=7(these give the number of capital grid points and discretized TFP shocks respectively).

Questions

Write a program that computes the solution to (1). Let the grid for capital (preferably called K orgK) be linearly-spaced with a support of (1±.3)kSS.

You should use linspace to do this.

1. Using your Tauchen procedure, discretize the zt process. Use a

cover-age of ±3 unconditional standard deviations (i.e., let the support be

±3σ/p1−ρ2). Report the log(z),z, and F(z0|z

) states and transition matrix.

2. Plot the policy function k0(k, z)—use k on the horizontal axis. Is the support of the capital grid large enough to containing the ergodic set of capital (i.e. is .7kSS less than the endogenous lower bound for capital

and 1.3kSS greater than the endogenous upper bound)? Why or why

(5)

3. Plot the value functionV(k, z) and the consumption policyc(k, z). For what values of k does V have the greatest amount of curvature? How about for z?

4. How long does it take to compute the solution?

More Questions

Now that you have computed the solution to (1), compute the ergodic dis-tribution φ(k, z). This can be done as follows:

• Let i= 1 and choose an arbitrary distribution (mass density function)

φ0(k, z).

• Compute

φi(k0, z0) =

X

k,z

1[k0 =k0(k, z)]F(z0|z)φi−1(k, z)

for each k0, z0.

HINT: check that |P

k,zφi−1(k, z)− 1| < 10

−10 at each step in the

iteration process. If it’s not, you have a bug.

NOTE: to do this, the above formula should not be implemented in your computation. Rather, you should

– Set φi(k0, z0) = 0 ∀k0, z0

– Loop through all k, z, z0 and do

φi(k0(k, z), z0) = φi(k0(k, z), z0) +F(z0|z)φi−1(k, z)

This computes the same thing but is much faster since there is no loop over k0.

ASIDE: an even faster alternative is to not loop over z0 but rather do

– Set φi(k0, z0) = 0 ∀k0, z0

– Loop through all k, z doing

φi(k0(k, z), z) =φi(k0(k, z), z) +φi−1(k, z)

(6)

• Check whether maxk,z|φi(k, z) − φi−1(k, z)| is small (say, less than

10−10). If it is, treat φ

i as the ergodic distribution and stop.

Oth-erwise, increment i and go to 2.

Now, do/answer the following:

1. Plot the marginal distributions φk =Pzφ(k, z) and φz =Pkφ(k, z).

2. In words, what is the shape of φz?

3. As for φk, where is most of the mass concentrated?

4. How much mass is at the tails of the φk distribution? the φz

distribu-tion?

5. What is average capital, Ek=P

k,zkφ(k, z)? Is this greater or smaller

than the steady state capital level? What is the interpretation of it being smaller or larger?

6. What is the average level ofz? How does this compare with the theo-retical mean of the AR1 process in (2)?

7. OPTIONAL: Compute and plot histograms of the ergodic distribu-tion for consumpdistribu-tion, labor, and investment. For instance, partidistribu-tion say [.1cSS,1.9cSS) inton bins and compute for each bin [ci, ci+1) what

P

k,z1[c(k, z) ∈ [ci, ci+1)]φ(k, z) is. Where are the means of the c, l,

and idistributions and what are there shapes (bimodal, single peaked, fat tailed)?

What is larger, the standard deviation of consumption or of investment? (NOTE: these can be computed as, e.g.,qP

k,z(c(k, z)2 −(Ec)2)φ(k, z)

with Ec= P

k,zc(k, z)φ(k, z).) Is this in agreement with US business

cycle facts? (PREVIOUS ERROR:qP

k,z(c(k, z)−Ec)φ(k, z))

Yet More Questions

You have now computed the solution to (1) and the ergodic distribution associated with it.

1. Compute the Euler equation error (EEE) as a function of (k, z) and plot it for all z (in one graph). The EEE is defined as

(7)

A value of EEE equal to -3 means a one dollar mistake is made for every 103 dollars spent.

2. Where is the EEE the greatest, and where is it the least?

3. What is the maximum EEE and what is its interpretation?

4. What is the average EEE (i.e. P

EEE(k, z)φ(k, z))?

5. Briefly, are these EEE acceptable? Would they be in some situations but not others?

Now, double the number of capital grid points, and recompute the solution and ergodic distibution.

6. Recompute the EEE and plot it.

7. Where is the EEE the greatest, and where is it the least?

8. What is the maximum EEE? the average EEE?

9. How long does it take to compute the solution? How much faster is this than with the original number of gridpoints?

Last Questions

This section asks you to compare running times and also check the validity of your program.

1. Fill in the following table:

Run Time (s) Ek (3 decimals) E(EEE)

(8)

2. Debug your program until all the opt values give the same average cap-itals and Euler errors!!! They should give exactly the same numbers since, if you give a weakly concave initial guess for the value function, the policy functions should be exactly the same.

Note: you will be able to reuse sub bellman discrete in the future if you can get it to work properly, so be sure to do this.

3. For opt==0, how do run times increase when nK is doubled and how does this differ whennZ is doubled (NOTE: both double the size of the state space)? Why does this discrepancy exist?

4. How is your answer to the above different when opt==1and also when

References

Related documents

single grid point and whose dependent degrees of freedom are specified at an arbitrary number of grid points. Format

Figure 8.4: Scalability plot for different number of cells of a shallow water simulation on a dynamically adaptive grid [BBS12]..

Ideally, grid clustering can be implemented in conditional space around the stoichiometric mixture fraction to greatly reduce the number of grid points present, decrease

Plot the ordered pairs as points on a graph with Number of hexagons on the horizontal axis and Number of toothpicks on the vertical axis.. Can you join the points on

Another important factor to consider when choosing grid spacing is the computational cost. The relationship between the number of grid points and grid spacing is governed by

Nothing should be different, including material of the window (usually wood), grid pattern (no change in the number of divided lights), window style (usually double-hung), grid

Figure 7 shows the front view of the quadrotor rotors-only complete grid system, including the NB and OB volume grids.. The total number of points reaches 311 million grid points,

Takahashi, On the existence of fixed points and ergodic retractions for Lipschitzian semigroups in Hilbert spaces, Nonlinear Anal.. Oka, Nonlinear ergodic theorems for