Code

Code for papers


calibration.zip

Tools for "A Practical Approach to Testing Calibration Strategies" with Yongquan Cao. This code includes both the Fortran MPI routine for computing simulated moments in parallel and the Stata code for analyzing the resulting output.

mod_binarymono.f90

Fortran companion module for "A Divide and Conquer Algorithm for Exploiting Policy Function Monotonicity." It solves

  1. V(i) = max_{i' in {1,...,n'}} f(i,i') ----- discrete problems with monotonicity in one-state variable

  2. V(i,j) = max_{i' in {1,...,n'}} f(i,j,i') ----- discrete problems with monotonicity in two-state variables

  3. V(b) = max_{b' in [lo,hi]} u(z(b) - x(b')) + W(b') ----- continuous problems (or, optionally, discrete) with monotonicity in one-state variable.

The reproduction code, available here, also has mod_binmono_disc_sort.f90 that can also solve V(i) = max_{i' in {1,...,n'}} u(z(i) - x(i')) + W(i') for arbitrary z, x, and W. It's not included in mod_binarymono.f90 to keep the module free of dependencies. Note that most Bellman equations fit one or more of these forms (see the paper for details, especially for how to map cases where the feasible choice set depends on the state into this framework). If g is monotone, the very fast method we present can be used. If f is concave, the method can be combined with other Heer and Maußner's binary concavity algorithm (which is also coded). Note that many problems in the default literature have monotone policy functions but non-concave value functions.

smolyak.zip

(This code was decent when written, but note that there's a full featured Sparse Grid software with many interfaces including Fortran here: https://tasmanian.ornl.gov/index.html)

Matlab code for "Computing Dynamic Heterogeneous-Agent Economies: Tracking the Distribution"

This Matlab code performs Smolyak Interpolation in three steps.

(1) smolyakapprox_step1 : this provides collocation points and a structure which is basically a template for constructing the polynomial.

(2) smolyakapprox_step2 : given the function values and the structure from (1), this constructs the polynomial coefficients placing them in a new structure.

(3) smolyakapprox_step3 : given the structure from (2), this evaluates the polynomial at arbitrary points in the state space.


Additional code


mod_csv.f90 and matlab programs

Export or import fortran arrays using .csv files. They can be opened directly with Excel or imported into Matlab via the included matlab m-files.

MINPACK, mod_rootNdim.f90, and test.f90

The zip file contains all the source files for MINPACK, as well as my own mod_rootNdim.f90 (for n-dimensional root-finding) and a small test program test.f90. The README in the zip file explains how to compile the test program if you are using a Mac or Linux. Unfortunately, I don't have a Windows machine to test it on but I did include speculative instructions in the README.

mod_root1dim.f90

A module for solving f(x)=0 where f:R->R. There are only two routines, sub_bisect (implementing the bisection method) and sub_brent (implementing Brent's 1973 zero-finding method). There is also a small test routine module you can use.

mod_plot.f90 and test_plot.f90

Basic line plotting and histogram plots (the histogram plots are VERY basic plots to terminal). The line plots call gnuplot. To compile, one must link with the openmp libraries. If using gfortran instead of ifort, one line must be commented out from mod_plot.f90 (see the description inside mod_plot.f90). To compile the test program, one can do the following:

ifort mod_plot.f90 test_plot.f90 -openmp -warn all

gfortran mod_plot.f90 test_plot.f90 -fopenmp -Wall (after commenting the one line)

NOTE:

(1) gnuplot must be on the OS path for these to work.

(2) I have tested this code in Mac and Linux, and it works. It also works in Windows, but every new plot replaces the old one.

mod_myhdf5.f90

Wrapper for some hdf5 routines.

orderpack.f90

Combines the routines available from http://www.fortran-2000.com/rank/ into one module