Dynamic Discrete Choice Models: Methods, Matlab Code, and Exercises

Jaap H. Abbring§Tobias J. Klein

This version: June 7, 2011

This document supports the first Matlab computing sessions in our PhD elective course Empirical Industrial Organization II in CentER Tilburg's Research Master in Economics program (230323) and in the Finnish Doctoral Programme in Economics (SEIO11). It contains some notes on the theory of dynamic discrete choice models and on methods for their computation and estimation. It is centered around some basic Matlab code for solving, simulating, and empirically analyzing a simple dynamic discrete choice model. Student exercises ask students to extend this code to apply different and more advanced computational and econometric methods to a wider range of models.


Thanks to Jeffrey R. Campbell for text on and help with Comments++ and to Nan Yang for comments.
§CentER, Department of Econometrics & OR, Tilburg University, P.O. Box 90153, 5000 LE Tilburg, The Netherlands. E-mail: j.h.Abbring@uvt.nl. http://jabbring.home.xs4all.nl.
CentER, Department of Econometrics & OR, Tilburg University.


Viewing and Using this File

This file (DynamicDiscreteChoice.m.html) documents how you can run the script DynamicDiscreteChoice.m with Matlab to specify, simulate, and estimate an empirical discrete-time version of the model of firm entry and exit under uncertainty in Dixit (1989). These computations will use, and therefore exemplify the use of, various tailor-made Matlab functions that are documented in this file. Thus, this file also is a guide to these functions and the way they can be adapted and used in your own exercises.

This file was generated by applying the Comments++ tool of Campbell and Peters (2010) to the Matlab script DynamicDiscreteChoice.m and the functions it calls. This script and these functions are all written as “literate programs” that embed their own documentation in a formatting language similar to LaTeX.

This is an image.

Figure 1: An Example of Displayed Code from this Document

Below, working code is displayed in areas formatted with “bars” similar to those on “old-style” computer paper for dot-matrix printers. Figure 1 shows a screen shot of a few lines of code from this document. The source file name is to the left, and the line number from the source file preceeds each line. In this example, Line 54 is highlighted blue because the mouse was hovering over it when screen shot was taken.

This is an image.

Figure 2: Switching Styles in Firefox

You can change this document to show only the working code. Figure 2 shows how to do this in Firefox.1 The default value for Page Style is Display All. Changing this to Display Only Code hides the documentation.

Printing this File

So that the displayed line numbers match with the actual line numbers, your browser preserves all line breaks in the displayed source code. That is, a long line cannot break into multiple lines after you resize your browser window. The same principle applies to printing. If a line of code is too long to be displayed on the page, its right end will be cut off. For this reason, this document is best printed in landscape mode.2

Software Requirements

Running the code documented in this file requires Matlab version 2008a or up, with its Optimization Toolbox and, ideally, the Knitro libraries. You can substitute a standard optimization function from the Optimization Toolbox, like fmincon, for Knitro's ktrlink if you do not have access to the Knitro libraries. However, note that a basic student version of these libraries is available from Ziena Optimization for free.

Road Map

The remainder of this document proceeds as follows. The next section covers two functions that define the decision problem, flowpayoffs and Psi. The versions of these functions handed out to the students, and documented here, define a very basic entry and exit problem with sunk costs and ongoing uncertainty. By changing these functions, different and more extensive decision problems can be studied with the procedures documented in later sections. Section 2B discusses FixedPointPsi, which solves for the optimal choice-specific expected discounted values (and therewith for the optimal decision rule) by finding the unique fixed point of the contraction defined by Psi. Section 3C documents how SimulateDP can be used to simulate data for the decision problem set up by flowpayoffs and Psi. Section 4D documents functions for estimating the transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and for computing the log partial likelihood for conditional choice data. Section 5E documents the script that uses these functions to set up the model, simulate data, and estimate the model with Rust (1987)'s nested fixed point (NFXP) maximum likelihood method. Section 6F contains a range of student exercises. Appendix 1A provides mathematical background by discussing some theory of contractions. Appendix 2B documents procedures that are called by the main routines, but that are of limited substantial interest, such as RandomDiscr.

1AA Firm Entry and Exit Problem

Consider a simple, discrete-time version of the model of firm entry and exit under uncertainty in Dixit (1989). At each time small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , a firm can choose to either serve a market (choice 1) or not (choice 0). The payoffs from either choice depend on the firm's choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in the previous period, because the firm may have to incur a sunk cost to enter or exit the market (for definiteness, suppose that the firm is initially inactive, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ). They also depend on externally determined (choice-independent) observed scalar state variables small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , as well as unobserved state variables small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that are revealed to the firm before it makes its choice in period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Specifically, in period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , its flow profits from choice 0 are

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and its flow profits from choice 1 are

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

Note that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are exit and entry costs that the firm only pays if it changes state. Gross of these costs, an active firm makes profits small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and an inactive firm has profits small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

The state variable small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image has finite support small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . From its random initial value small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , it follows a first-order Markov chain with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image transition probability matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , independently of the firm's choices. The profits shocks small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are independent of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , across time small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and choices small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with type I extreme value distributions centered around 0. Note that the firm controls the evolution of the state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image only through its choice of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , as small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are “exogenous” state variables of which the evolution is externally specified.

The firm has rational expectations about future states and choices. It chooses the action small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that maximizes its expected flow of profits, discounted at a factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

Two functions, flowpayoffs and Psi, together code up this simple model. If you wish to experiment with other functional forms for the flow profits, you should edit flowpayoffs.m. The model's dynamic specification can be changed in Psi.m.

1A.1Flow Payoffs

The function flowpayoffs computes the mean (over small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) flow payoffs, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , for each profit and past choice pair small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

flowpayoffs.m7function [u0,u1] = flowpayoffs(calX,beta,delta)

It requires the following input arguments:

calX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector with the support points of the profit state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (the elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , consistently ordered with the Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image );
beta
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector that contains the intercept ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) and profit state slope ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) of the net payoffs to choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; and
delta
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector that contains the firm's exit ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) and entry ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) costs.

It returns

u0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and
u1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

That is, the rows correspond to the support points of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and the columns to the choice in the previous period, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

The function flowpayoffs first stores the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of elements of calX in a scalar K.

flowpayoffs.m24K = size(calX,1);

Then, it constructs a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix u0 with the value of

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix u1 with the value of

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

flowpayoffs.m55u0 = [zeros(K,1) -delta(1)*ones(K,1)];
flowpayoffs.m56u1 = [ones(K,1) calX]*beta*[1 1]-delta(2)*ones(K,1)*[1 0];

You can change the specification of the flow profits by editing these two lines of code.

1A.2Bellman Operator

The expected discounted profits net of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image immediately following choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image at time small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , satisfy a recursive system small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image or, with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , simply small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (see e.g. Rust (1994)). Here, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a Bellman-like operator that embodies the model's dynamic specification and that depends on the flow payoffs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , the Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and the discount factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Its elements are the operators small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image implicitly defined by the right hand side of

(1)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

where small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is McFadden (1981)'s social surplus for the binary choice problem with utilities small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . The first term in the right-hand side of (1) equals period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image 's flow profits following choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , net of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . The second term equals the expected discounted profits from continuing into period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (note that, given the choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , these continuation payoffs do not depend on the past choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ). The (mean-zero) extreme value assumptions on small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image implies that

(2)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

The function Psi applies the operator small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image once to input values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and returns small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

Psi.m15function [capU0,capU1] = Psi(capU0,capU1,u0,u1,Pi,rho)

It requires the following input arguments:

capU0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
capU1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
u0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
u1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
Pi
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; and
rho
a scalar with the value of the discount factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

It returns

capU0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
capU1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;

To this end, Psi first computes the surpluses small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in (2) for all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and stacks these in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vectors R0 and R1.

Psi.m33R0 = log(exp(capU0(:,1))+exp(capU1(:,1)));
Psi.m34R1 = log(exp(capU0(:,2))+exp(capU1(:,2)));

Then, it applies (1) to compute new values of capU0 and capU1.

Psi.m38capU0 = u0 + rho*Pi*R0*[1 1];
Psi.m39capU1 = u1 + rho*Pi*R1*[1 1];

Here, the conditional expectation over small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in (1) is taken by premultiplying the vectors R0 and R1 by the Markov transition matrix Pi. The vectors R0 and R1 are postmultiplied by [1 1] because the surpluses, and therefore the continuation payoffs, are independent of the past choice that indexes the columns of capU0 and capU1.

The logit assumption only affects the operator small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and therefore the function Psi, through the specification of the surpluses small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in (2). If you want to change the logit assumption, you should change the computation of R0 and R1 (and make sure to adapt the computation of choice probabilities and inverse choice probabilities elsewhere as well).

2BSolving the Decision Problem

The function FixedPointPsi computes the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of the Bellman-like operator small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , using the method of successive approximations. It is easy to show that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction, so that the method of successive approximations converges linearly and globally to a point within a positive maximum absolute distance tFP (see Appendix 1A.3).

FixedPointPsi.m8function [capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,Psi,capU0,capU1)

It requires the following input arguments:

u0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
u1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
Pi
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
rho
a scalar with the value of the discount factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
tFP
a scalar tolerance level that is used to determine convergence of the successive approximations;
Psi
the handle of the function [U0,U1]=Psi(Uin0,Uin1,u0,u1,Pi,rho) that iterates once on small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
capU0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is a starting value for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (optional; set to [] to select default starting value);
capU1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is a starting value for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (optional; set to [] to select default starting value);

It returns

capU0
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; and
capU1
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;

The function FixedPointPsi first stores the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of elements of calX in a scalar K.

FixedPointPsi.m28K = size(Pi,1);

The starting values for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are set to small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image if the input arguments capU0 and capU1 are empty.

FixedPointPsi.m32if isempty(capU0)
FixedPointPsi.m33 capU0 = zeros(K,2);
FixedPointPsi.m34end
FixedPointPsi.m35if isempty(capU1)
FixedPointPsi.m36 capU1 = zeros(K,2);
FixedPointPsi.m37end

The small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrices Uin0 and Uin1 store the value of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that is fed into the operator small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , for comparison with the value of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that is subsequently stored in capU0 and capU1. They are initialized to deviate from capU0 and capU1 by more than tFP, so that the while statement allows at least one iteration of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and stops as soon as small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image no longer exceeds the tolerance level in tFP.

FixedPointPsi.m41Uin0 = capU0+2*tFP;
FixedPointPsi.m42Uin1 = capU1+2*tFP;
FixedPointPsi.m43while (max(max(abs(Uin0-capU0)))>tFP) || (max(max(abs(Uin1-capU1)))>tFP);
FixedPointPsi.m44 Uin0 = capU0;
FixedPointPsi.m45 Uin1 = capU1;
FixedPointPsi.m46 [capU0,capU1] = Psi(Uin0,Uin1,u0,u1,Pi,rho);
FixedPointPsi.m47end

You can replace FixedPointPsi by another function if you want to use alternative methods, such as Newton methods, for computing the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , or if you want to work with finite horizon problems.

3CData Simulation

Suppose that we have computed small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , using e.g. flowpayoffs and FixedPointPsi, and that we have specified the Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Then, the function SimulateDP can be used to simulate small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image independent histories small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , taking small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image as given and drawing small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image from the stationary distribution of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

SimulateDP.m7function [A,iX] = SimulateDP(DeltaU,Pi,T,N)

The function SimulateDP requires the following input arguments:

DeltaU
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of which the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th entry is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
Pi
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
T
the scalar number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of time periods to simulate data for; and
N
the scalar number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of firms to simulate data for.

It returns

A
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with simulated choices, with each each column containing an independent simulation of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; and
iX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with simulated states, with each each column containing the indices (in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) of an independent simulation of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . For example, if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for some firm, then 3, not small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , is stored in iX.

The function SimulateDP first stores the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of elements of calX in a scalar K.

SimulateDP.m23K = size(Pi,1);

Next, it assumes that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is ergodic and initializes the simulation by drawing small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image independent times, from the stationary distribution of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . To this end, it first computes the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with the stationary probabilities small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image using

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and stores it in Pinf.

SimulateDP.m39oneminPi = eye(K)-Pi';
SimulateDP.m40Pinf = inv([oneminPi(1:K-1,:);ones(1,K)])*[zeros(K-1,1);1];

Then, it uses the auxiliary function RandomDiscr (see Appendix 2B) and the values stored in Pinf to simulate a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector of values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image from the stationary distribution small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and stores their indices in iX.

SimulateDP.m44iX = RandomDiscr(Pinf*ones(1,N));

Using these small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image simulated values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image simulated values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image which are stored in Depsilon, it simulates small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image values of the first choice by using that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image otherwise. These are stored in the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector A.

SimulateDP.m48Depsilon = random('ev',zeros(1,N),ones(1,N))-random('ev',zeros(1,N),ones(1,N));
SimulateDP.m49A = DeltaU(iX,1)' > Depsilon;

Finally, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are simulated, using the transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and RandomDiscr, and their indices added as a row to the bottom of the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix iX; and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are simulated, using that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image otherwise, and stored as a row at the bottom of the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix A; recursively for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

SimulateDP.m53for t = 2:T
SimulateDP.m54 iX = [iX;RandomDiscr(Pi(iX(end,:),:)')];
SimulateDP.m55 Depsilon = random('ev',zeros(1,N),ones(1,N))-random('ev',zeros(1,N),ones(1,N));
SimulateDP.m56 A = [A;(DeltaU(iX(end,:)+K*A(end,:)) > Depsilon)];
SimulateDP.m57end

4DEstimation

Suppose that we have a random sample small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image from the population of state and choice histories small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Following Rust (1994), we provide functions for implementing a two-stage procedure in which, first, the state transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is estimated directly from observed state transitions and, second, the remaining parameters are estimated by maximizing the partial likelihood for the observed choices.

4D.1First Stage: State Transitions

The function estimatePi computes a frequency estimate of the Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image from state transition data.

estimatePi.m7function Pihat = estimatePi(iX,K)

It requires the following input arguments:

iX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with indices of observed states small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (for example, if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , then the first element of iX is 3, not small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image );
K
the scalar number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of support points of the profit state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (the number of elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image )

and returns

Pihat
an estimate small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image equal to the sample frequency of transitions to state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image among all transitions from state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

The function estimatePi first stores the number of time periods small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in a scalar T.

estimatePi.m20T=size(iX,1);

Then, for each pair small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , it estimates the probability small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image by the appropriate sample frequency, the number of transitions from small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image to small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image divided by the total number of transitions from small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in the data iX.

estimatePi.m24for i=1:K
estimatePi.m25 for j=1:K
estimatePi.m26 Pihat(i,j)=sum(sum((iX(2:T,:)==j)&(iX(1:T-1,:)==i)))/sum(sum((iX(1:T-1,:)==i)));
estimatePi.m27 end
estimatePi.m28end

Note that estimatePi requires a positive number of transition observations from each state. More generally, the frequency estimator that it implements only performs well with samples that are large relative to the state space. With relatively small samples, the frequency estimator should be replaced by one that smooths across observations.

4D.2Second Stage: Choices

The function NegLogLikCCP computes minus the log partial likelihood for the conditional choice part of the data. Optionally, it also returns the corresponding score vector and an estimate of the information matrix for the parameter (sub)vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (the scores are specific to the estimation example in Section 5E's script and should be adapted for inference on other parameters).

NegLogLikCCP.m7function [nll grad gradgrad] = NegLogLikCCP(A,iX,calX,Pi,beta,delta,rho,flowpayoffs,Psi,FixedPointPsi,tFP)

The function NegLogLikCCP requires the following input arguments:

A
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with choice observations small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
iX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with indices of observed states small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (for example, if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , then the first element of iX is 3, not small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image );
calX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector with the support points of the profit state small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (the elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , consistently ordered with the Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image );
Pi
the (possibly estimated) small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
beta
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector that contains the intercept ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) and profit state slope ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) of the flow payoffs to choice small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
delta
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector that contains the firm's exit ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) and entry ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ) costs.
rho
a scalar with the value of the discount factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
flowpayoffs
a handle of a function [u0,u1]=flowpayoffs(calX,beta,delta) that computes the mean flow payoffs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
Psi
a handle of a function [U0,U1]=Psi(Uin0,Uin1,u0,u1,Pi,rho) that iterates once on small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
FixedPointPsi
a handle of a function [U0,U1]=FixedPointPsi(u0,u1,Pi,rho,tFP,Psi,U0,U1) that computes the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; and
tFP
a scalar tolerance level that is used to determine convergence of the successive approximations of the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

It returns

nll
a scalar with minus the log partial likelihood for the conditional choices

and optionally

grad
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector with minus the partial likelihood score for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and
gradgrad
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with the sum of the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image outer products of the individual contributions to the score for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

The function NegLogLikCCP first stores the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of elements of calX in a scalar K.

NegLogLikCCP.m34K = size(calX,1);

Next, it computes the flow payoffs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (u0) and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (u1), the choice-specific net expected discounted values small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (capU0) and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (capU1), their contrast small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (DeltaU), and the implied probabilities small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of not serving the market (pexit) for the inputted parameter values. Note that this implements the NFXP procedure's inner loop.

NegLogLikCCP.m38[u0,u1] = flowpayoffs(calX,beta,delta);
NegLogLikCCP.m39[capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,Psi,[],[]);
NegLogLikCCP.m40DeltaU = capU1-capU0;
NegLogLikCCP.m41pexit = 1./(1+exp(DeltaU));

Log Partial Likelihood

The contribution to the likelihood of firm small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image 's choice in period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is the conditional choice probability

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . The function NegLogLikCCP first computes these probabilities for each firm small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and period small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and stores them in a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix p. Then, it returns minus the sum of their logs, the log partial likelihood for the conditional choices, in nll.

NegLogLikCCP.m48Alag = [zeros(1,size(A,2));A(1:end-1,:)];
NegLogLikCCP.m49p = A + (1-2*A).*pexit(iX+K*(Alag));
NegLogLikCCP.m50nll = -sum(sum(log(p)));

Score

If two or more output arguments are demanded from NegLogLikCCP, it computes and returns minus the partial likelihood score for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (the derivative of minus the log partial likelihood with respect to small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ), in grad.

NegLogLikCCP.m56if nargout>=2

Firm small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image 's contribution to the score equals

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

Its calculation requires that we compute small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Recall that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and therewith small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , is only implicitly given by small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Note that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is defined on a set with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image points, so that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image can be represented by a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image by a mapping from small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image into small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Specifically, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image can be represented by the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that lists the values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image on their domain,

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and that satisfies

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image an appropriately rearranged version of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (note that we made its dependence on small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image explicit). With this alternative representation of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in place, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image follows from (see also Rust (1994), p.3110)

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

where small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image unit matrix;

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

with

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of zeros; and

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

The function NegLogLikCCP first computes small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (D00), small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (D01), small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (D10), small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (D11) and constructs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (dPsi_dUbar).

NegLogLikCCP.m115 D00 = rho*Pi*diag(pexit(:,1));
NegLogLikCCP.m116 D01 = rho*Pi*diag(pexit(:,2));
NegLogLikCCP.m117 D10 = rho*Pi-D00;
NegLogLikCCP.m118 D11 = rho*Pi-D01;
NegLogLikCCP.m119 dPsi_dUbar = [[D00;D00;zeros(2*K,K)] [zeros(2*K,K);D01;D01] [D10;D10;zeros(2*K,K)] [zeros(2*K,K);D11;D11]];

It then computes small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (dPsi_dpar; note that the following line is the only code in NegLogLikCCP that needs to be changed if other parameters that those in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are estimated).

NegLogLikCCP.m124 dPsi_dpar = [[zeros(2*K,1);ones(2*K,1)] [zeros(2*K,1);calX;calX] [zeros(2*K,1);-ones(K,1);zeros(K,1)]];

Next, it computes small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (dUbar_dpar) and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (dDeltaU_dpar).

NegLogLikCCP.m128 dUbar_dpar = inv(eye(4*K)-dPsi_dUbar)*dPsi_dpar;
NegLogLikCCP.m129 dDeltaU_dpar = dUbar_dpar(2*K+1:4*K,:)-dUbar_dpar(1:2*K,:);

Finally, it computes the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for each small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , stacks these individual (minus) score contributions in the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix indgrad, and sums them to compute minus the score vector, grad.

NegLogLikCCP.m133 npar = size(dUbar_dpar,2);
NegLogLikCCP.m134 indgrad = repmat((1-2*A).*(1-p),[1 1 npar]);
NegLogLikCCP.m135 for i=1:npar
NegLogLikCCP.m136 indgrad(:,:,i) = indgrad(:,:,i).*dDeltaU_dpar(iX+K*Alag+2*(i-1)*K);
NegLogLikCCP.m137 end
NegLogLikCCP.m138 indgrad=squeeze(sum(indgrad,1));
NegLogLikCCP.m139 grad = sum(indgrad)';
NegLogLikCCP.m140end

Information Matrix

If three output arguments are demanded, NegLogLikCCP computes the sum of the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image outer products of the individual score contributions,

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

and returns it in gradgrad.

NegLogLikCCP.m149if nargout==3
NegLogLikCCP.m150 gradgrad = zeros(npar,npar);
NegLogLikCCP.m151 for n=1:size(indgrad,1)
NegLogLikCCP.m152 gradgrad = gradgrad + indgrad(n,:)'*indgrad(n,:);
NegLogLikCCP.m153 end
NegLogLikCCP.m154end

When evaluated at an estimate of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , this provides an estimate of the expected partial likelihood information matrix for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . This estimate can in turn be used to estimate the variance-covariance matrix, and thus the standard errors, of the maximum partial likelihood estimator small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

5EThe Script that Puts It All Together

The script in DynamicDiscreteChoice.m simulates data and computed maximum likelihood estimates using the nested fixed point (NFXP) method of Rust (1987) and Rust (1994). It takes small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image to be known, either takes small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image to be known or estimates it in a first stage, and focuses on maximum partial likelihood estimation of the remaining parameters; small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; from conditional choice probabilities.

Simulating Data

First, we set the number of time periods (T) and firms (N) that we would like to have in our sample.

DynamicDiscreteChoice.m93T = 100
DynamicDiscreteChoice.m94N = 1000

We also set the tolerance tFP on the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image that we will use to determine the simulation's entry and exit rules. This same tolerance will also be used when solving the model in the inner loop of the NFXP procedure.

DynamicDiscreteChoice.m98tFP = 1e-10

Next, we specify the values of the model's parameters used in the simulation:

K
the scalar number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
calX
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with the support points of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
Pi
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image Markov transition matrix small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , with typical element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
beta
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with the parameters of the flow profit of active firms;
delta
the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector of exit and entry costs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;
rho
the scalar discount factor small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ;

DynamicDiscreteChoice.m110K = 5;
DynamicDiscreteChoice.m111calX = (1:K)'
DynamicDiscreteChoice.m112Pi = 1./(1+abs(ones(K,1)*(1:K)-(1:K)'*ones(1,K)));
DynamicDiscreteChoice.m113Pi = Pi./(sum(Pi')'*ones(1,K))
DynamicDiscreteChoice.m114beta = [-0.1*K;0.2]
DynamicDiscreteChoice.m115delta = [0;1]
DynamicDiscreteChoice.m116rho = 0.95

For these parameter values, we compute the flow payoffs small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (u0) and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (u1), the choice-specific expected discounted values small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (U0) and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (U1), and their contrast small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (DeltaU).

DynamicDiscreteChoice.m120[u0,u1] = flowpayoffs(calX,beta,delta);
DynamicDiscreteChoice.m121[capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,@Psi,[],[]);
DynamicDiscreteChoice.m122DeltaU = capU1-capU0;

With small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image computed, and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image specified, we proceed to simulate a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of choices A and a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix of states iX (recall from Section 3C that iX contains indices that point to elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image rather than those values themselves).

DynamicDiscreteChoice.m126[A,iX] = SimulateDP(DeltaU,Pi,T,N);

Nested Fixed Point Maximum Likelihood Estimation

First, set useKnitro to 1 if Knitro should be used for the outer (likelihood maximization) loop of the NFXP algorithm, and to 0 otherwise. Also, set the tolerances tc and tp for outer loop convergence (recall that the inner loop tolerance is already set in tFP).3

DynamicDiscreteChoice.m132useKnitro = 0;
DynamicDiscreteChoice.m133tc = 1E-6
DynamicDiscreteChoice.m134tp = 1E-6

Next, we specify a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector startvalues with starting values for the parameters to be estimated, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

DynamicDiscreteChoice.m138startvalues = [-1;-0.1;0.5];

We continue with setting a lower bound (lb) of 0 on the third parameter, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and (nonbinding) lower bounds of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image on the other two parameters. There is no need to specify upper bounds.4

DynamicDiscreteChoice.m142lb = -Inf*ones(size(startvalues));
DynamicDiscreteChoice.m143lb(3) = 0;

First, suppose that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is known. We use NegLogLikCCP to specify an objective function objfun to be minimized in the outer loop by ktrlink and fmincon. This step is needed because ktrlink and fmincon require an objective function that only depends on the arguments of the minimization.

DynamicDiscreteChoice.m147objfun = @(par)NegLogLikCCP(A,iX,calX,Pi,par(1:2),[delta(1);par(3)],rho,@flowpayoffs,@Psi,@FixedPointPsi,tFP)

We are now ready to run the NFXP maximum likelihood procedure. If useKnitro equals 1, ktrlink will be called; otherwise, the Matlab procedure fmincon will be used.

DynamicDiscreteChoice.m151if useKnitro
DynamicDiscreteChoice.m152 options = optimset('Display','iter','GradObj','off','AlwaysHonorConstraints', ...
DynamicDiscreteChoice.m153 'bounds','TolFun',tc,'TolX',tp);
DynamicDiscreteChoice.m154 [parMLE,fval,flag] = ktrlink(objfun,startvalues,[],[],[],[],lb,[],[],options);
DynamicDiscreteChoice.m155else
DynamicDiscreteChoice.m156 options = optimset('Algorithm','interior-point','Display','iter','GradObj', ...
DynamicDiscreteChoice.m157 'on','AlwaysHonorConstraints','bounds','TolFun',tc,'TolX',tp,'DerivativeCheck','on');
DynamicDiscreteChoice.m158 [parMLE,fval,flag] = fmincon(objfun,startvalues,[],[],[],[],lb,[],[],options);
DynamicDiscreteChoice.m159end

This gives maximum partial likelihood estimates of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . To calculate standard errors, we call NegLogLikCCP once more to estimate the corresponding Fisher information matrix and store this in gradgrad. Its inverse is an estimate of the maximum likelihood estimator's asymptotic variance-covariance matrix.

DynamicDiscreteChoice.m164[nll grad gradgrad] = NegLogLikCCP(A,iX,calX,Pi,parMLE(1:2),[delta(1);parMLE(3)],rho,@flowpayoffs,@Psi,@FixedPointPsi,tFP);
DynamicDiscreteChoice.m165Vcov=inv(gradgrad)
DynamicDiscreteChoice.m166ses=sqrt(diag(Vcov))

The resulting parameter estimates and standard errors are displayed (third and fourth columns), together with the parameters' true (first column) and starting values (second column).

DynamicDiscreteChoice.m170disp([[beta;delta(2)] startvalues parMLE ses]);

Extension to an Unknown Markov Transition Matrix for the State

Finally, consider the more realistic case that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is not known. In this case, Rust (1994) suggests a two-stage procedure. In the first stage, we estimate small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image using estimatePi and store the results in a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix Pihat.

DynamicDiscreteChoice.m175Pihat=estimatePi(iX,K)

In the second stage, maximum partial likelihood estimates of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image can be computed using the NFXP procedure, with Pihat replacing Pi. This, with the question how the first-stage sampling error affects the precision of the second-stage estimator of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , is left for the exercises.

6FStudent Exercises

Excercises to Work on

The exercises typically ask you to modify the code so that it can handle alternative econometric procedures and models. This often requires that you adapt the analytic computation of the derivatives of the log likelihood. It may be convenient to first work with numerical derivatives by setting the option "GradObj" in fmincon or ktrlink to "off"; this would allow you to find the estimates, but not to compute their standard errors. Once you have coded up the analytical derivatives, you are advised to verify them against numerical derivatives, for example by setting the option "DerivativeCheck" in fmincon or ktrlink to "on".

  1. Extend the script in DynamicDiscreteChoice.m with a single simulation to a Monte Carlo experiment in which estimates are computed for a sequence of simulated data sets. Keep track of the estimates and report statistics such as their means and standard deviations. Note that you can also use this Monte Carlo setup in later questions to study the finite-sample performance of the various procedures studied.
  2. Implement the MPEC approach to maximum likelihood estimation of our structural model, as advocated by Judd and Su (2008).
    • First, extend NegLogLikCCP so that it can be used to compute the log (partial) likelihood as a function of not only the parameters of interest but also the (finite number of) values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . For example, allow for optional arguments capU0 and capU1 and, if these arguments are not empty, directly compute the choice probabilities from the implied values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , rather than computing small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image by solving the model.
    • Then, extend the script in DynamicDiscreteChoice.m so that it alternatively maximizes the log likelihood with respect to both the parameters of interest and the values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , subject to the constraint that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (which can be specified using the function Psi).
    Would you expect the NFXP and MPEC approaches to give the same estimates of the parameters of interest (up to numerical precision)? How is the relative numerical performance of both procedures?
  3. Implement a simulation-based two-step estimator along the lines of Hotz et al. (1994), Rust (1994), and Bajari, Benkard, and Levin (2007).
    • Add a new function for nonparametrically estimating the choice probabilities small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image over the support of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (with enough data and a finite state space, you can simply use the conditional sample frequency).
    • Add (to this same function or in a new function) a procedure for estimating small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image by inverting the estimated choice probabilities (as proposed by Hotz and Miller (1993) and Hotz et al. (1994)).
    • Extend NegLogLikCCP (or add functions) so that it optionally takes nonparametric estimates of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image as inputs, computes the corresponding estimates of the entry and exit rules, and uses these estimates and the model to forwardly simulate small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and then small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , for each point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in the sample. As the objective to be minimized, either specify a weighted distance between the nonparametric estimates of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and the simulated values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , or minus a log pseudo-likelihood based on the choice probabilities implied by the simulated values of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .
    • Finally, extend the script in DynamicDiscreteChoice.m so that it successively calls these functions to implement a two step procedure for estimating the model, as in Hotz and Miller (1993) and Hotz et al. (1994).
    See the course slides for a brief and general description of this procedure and Rust (1994) for a detailed algorithm, with discussion. Note that the algorithm described in Rust (1994) is similar to that of Bajari, Benkard, and Levin (2007) for games that we will discuss later in the course. Both build on the ideas of Hotz et al. (1994), who use the special logit structure to simplify the simulation (see the discussion in Bajari, Benkard, and Levin (2007)).
  4. Extend the code for simulation and estimation so that it can handle a finite number of unobserved types, as in the work of Eckstein and Wolpin (1990), Keane and Wolpin (1997), and Eckstein and Wolpin (1999). Specifically, suppose that there are two types in the population, one with entry cost small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and the other with entry cost small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . The firms are distributed across both unobserved entry cost types independently from all other variables in the model. We would like to estimate small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and the share of agents with entry cost small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . To this end:
    • Extend SimulateDP so that it randomly draws an entry cost from a distribution with two points of support, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and simulates choice data corresponding to the entry cost drawn, for each firm, independently across firms.
    • Extend NegLokLikCCP so that it computes each firm's likelihood contribution as the mixture (expectation) of the likelihood contributions for each entry cost type (which are given by the current specification of the likelihood for homogeneous firms) over the distribution of these two types in the population of firms.
    • Finally, extend the script in DynamicDiscreteChoice.m so that it successively calls these functions. Check whether you can recover the entry cost distribution, and the other parameters, well.

Additional Exercises

  1. Prove that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction.
  2. For the case of estimating the demand for differentiated products using NFXP maximum likelihood, as in Berry, Levinsohn, and Pakes (1995), Dub\'e, Fox, and Su (2008) claim that it is important to carefully balance the convergence tolerances used in the inner (contraction) loop and the outer (likelihood maximization) loop. In particular, they argue that the inner loop needs to be computed at a much higher precision than the tolerance used in the outer loop. Experiment with the values of tFP on the one hand and tc and tp on the other hand to investigate this issue in the context of this package's firm entry and exit problem.
  3. Show the equivalence of policy iteration and the Newton-Kantorovich method for solving small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (see Appendix 1A.3). Extend FixedPointPsi so that it has the option to compute small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image using the Newton-Kantorovich method (or a hybrid method, as in Rust (1987)). Note that, with a finite state space as in our example, the Newton-Kantovorich method reduces to the Newton-Raphson method and requires the Jacobian small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image computed in an intermediate step of NegLogLikCCP.
  4. Compare the asymptotic standard errors to Monte Carlo standard errors.
  5. Compute the two-stage estimates of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for the case that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is not known. Are the estimators of the standard errors that assume small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image known consistent if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is estimated instead? If not, extend the code so that it computes consistent standard error estimates for the case that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is estimated. See Rust (1994).
  6. Is small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image identified in the example model? What about small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ? To the extent that these are identified, extend your numerical experiments to include their estimation. See Abbring (2010) for results and references.
  7. Extend flowpayoffs.m and Psi.m so that they allow for models with different functional forms and a larger (but finite) number of choices and experiment with estimating these models.

1AContractions and Dynamic Programming

See e.g. Stokey, Lucas, and Prescott (1989) and Judd (1998) for a rigorous and comprehensive treatment of the topics in this appendix and their economic applications.

1A.1Definitions

A metric space is a set small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with a metric small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that, for any small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ,

  1. small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image if and only if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ,
  2. small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , and
  3. small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (triangle inequality).

A Cauchy sequence in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a sequence small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that, for each small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , there exists some small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

A metric space small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is complete if every Cauchy sequence in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image converges to a point in small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

A map small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction with modulus small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image if small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

1A.2Contraction Mapping (Banach Fixed Point) Theorem

If small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a complete metric space and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction, then there exists a unique small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Furthermore, for any small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , the sequence small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , converges to small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

Sketch of Proof

Suppose small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image are such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Then, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for some small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Consequently, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

Because small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction, any small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image it generates is a Cauchy sequence. Because small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is complete, it converges to some small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Because contractions are continuous, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

1A.3Computing the Fixed Point of a Contraction

The method of successive approximations directly applies the Contraction Mapping Theorem and approximates the fixed point small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of a contraction small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with the sequence small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image generated from small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image on a finitely discretized state space. This method has global but linear convergence.

The Newton-Kantorovich method searches a zero of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; it approximates small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image with the sequence generated from

(0)

small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image the Fr\'echet derivative of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image at small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image (with a discrete state space, this is simply the linear map defined by the appropriate finite dimensional Jacobian, as in NegLogLikCCP).

1A.4Blackwell's Sufficient Conditions for a Contraction

Let small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image be the space of functions small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ( small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image bounded), with metric small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Suppose that, for some small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image satisfies

  1. (monotonicity) small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and
  2. (discounting) small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image

for all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image and all small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Then, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a contraction with modulus small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

Sketch of Proof

Let small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image be such that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Note that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , so that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image by monot. & discounting. Similarly, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image . Thus, small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

1A.5Application to Dynamic Programming

The choice-specific value function small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image is a fixed point of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , which satisfies Blackwell's sufficient conditions with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image equal to the discount factor.

2BMiscellaneous Utilities

This section documents some miscellaneous utilities that are called by the main functions. At this point, it only includes RandomDiscr.

The function RandomDiscr returns a random draw from the distribution of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ; with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image independently distributed with (not necessarily identical) disctributions on small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for some small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

RandomDiscr.m7function iX = RandomDiscr(P)

It requires one input argument:

P
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

It returns

iX
a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image vector with a random draw small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image from small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

The function RandomDiscr first stores the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of support points in a scalar K and the number small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image of random variables in a scalar N.

RandomDiscr.m19K = size(P,1);
RandomDiscr.m20N = size(P,2);

Then, it creates a small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix ru with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image identical rows, containing small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image independent draws from a standard uniform distribution, and computes the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image matrix cumP with small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th element small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image .

RandomDiscr.m24ru = ones(K-1,1)*random('unif',zeros(1,N),ones(1,N));
RandomDiscr.m25cumP = cumsum(P);

Finally, for each small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image , it sets small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image equal to 1 plus the number of elements of small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image } that are weakly smaller than the uniform random draw in the small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image th column of ru.

RandomDiscr.m29iX = sum([ones(1,N);cumP(1:K-1,:)<=ru]);


1A similar option is available on Microsoft Internet Explorer. We use Cascading Style Sheets (CSS2) for all formatting. Since IE implements this standard poorly, we cannot guarantee that it will display this document well.
2We have successfully printed this using Firefox for the Macintosh and Firefox for Linux. Sadly, not all browsers are so cooperative. This document apparently triggers a bug in Safari that causes multiple blank pages to be printed after each actual page.
3Please see the manual for the Matlab-Knitro function ktrlink or the Matlab function fmincon to learn about the tolerances and other input arguments to the minimization function used in the outer loop of the NFXP procedure.
4Note that both ktrlink and fmincon allow the user to specify bounds on parameters; if another function is used that does not allow for bounds on the parameters, you can use an alternative parameterization to ensure that parameters only take values in some admissible set (for example, you can specify small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image for small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image to ensure that small image LARGE image footnotesize image Large image scriptsize image large image tiny image Huge image huge image normalsize image ). The functions ktrlink and fmincon also allow you to impose more elaborate constraints on the parameters; you will need this option when implementing the MPEC alternative to NFXP of Judd and Su (2008) (see Section 6F).
DynamicDiscreteChoice.m93T = 100
DynamicDiscreteChoice.m94N = 1000
DynamicDiscreteChoice.m98tFP = 1e-10
DynamicDiscreteChoice.m110K = 5;
DynamicDiscreteChoice.m111calX = (1:K)'
DynamicDiscreteChoice.m112Pi = 1./(1+abs(ones(K,1)*(1:K)-(1:K)'*ones(1,K)));
DynamicDiscreteChoice.m113Pi = Pi./(sum(Pi')'*ones(1,K))
DynamicDiscreteChoice.m114beta = [-0.1*K;0.2]
DynamicDiscreteChoice.m115delta = [0;1]
DynamicDiscreteChoice.m116rho = 0.95
DynamicDiscreteChoice.m120[u0,u1] = flowpayoffs(calX,beta,delta);
DynamicDiscreteChoice.m121[capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,@Psi,[],[]);
DynamicDiscreteChoice.m122DeltaU = capU1-capU0;
DynamicDiscreteChoice.m126[A,iX] = SimulateDP(DeltaU,Pi,T,N);
DynamicDiscreteChoice.m132useKnitro = 0;
DynamicDiscreteChoice.m133tc = 1E-6
DynamicDiscreteChoice.m134tp = 1E-6
DynamicDiscreteChoice.m138startvalues = [-1;-0.1;0.5];
DynamicDiscreteChoice.m142lb = -Inf*ones(size(startvalues));
DynamicDiscreteChoice.m143lb(3) = 0;
DynamicDiscreteChoice.m147objfun = @(par)NegLogLikCCP(A,iX,calX,Pi,par(1:2),[delta(1);par(3)],rho,@flowpayoffs,@Psi,@FixedPointPsi,tFP)
DynamicDiscreteChoice.m151if useKnitro
DynamicDiscreteChoice.m152 options = optimset('Display','iter','GradObj','off','AlwaysHonorConstraints', ...
DynamicDiscreteChoice.m153 'bounds','TolFun',tc,'TolX',tp);
DynamicDiscreteChoice.m154 [parMLE,fval,flag] = ktrlink(objfun,startvalues,[],[],[],[],lb,[],[],options);
DynamicDiscreteChoice.m155else
DynamicDiscreteChoice.m156 options = optimset('Algorithm','interior-point','Display','iter','GradObj', ...
DynamicDiscreteChoice.m157 'on','AlwaysHonorConstraints','bounds','TolFun',tc,'TolX',tp,'DerivativeCheck','on');
DynamicDiscreteChoice.m158 [parMLE,fval,flag] = fmincon(objfun,startvalues,[],[],[],[],lb,[],[],options);
DynamicDiscreteChoice.m159end
DynamicDiscreteChoice.m164[nll grad gradgrad] = NegLogLikCCP(A,iX,calX,Pi,parMLE(1:2),[delta(1);parMLE(3)],rho,@flowpayoffs,@Psi,@FixedPointPsi,tFP);
DynamicDiscreteChoice.m165Vcov=inv(gradgrad)
DynamicDiscreteChoice.m166ses=sqrt(diag(Vcov))
DynamicDiscreteChoice.m170disp([[beta;delta(2)] startvalues parMLE ses]);
DynamicDiscreteChoice.m175Pihat=estimatePi(iX,K)
flowpayoffs.m7function [u0,u1] = flowpayoffs(calX,beta,delta)
flowpayoffs.m24K = size(calX,1);
flowpayoffs.m55u0 = [zeros(K,1) -delta(1)*ones(K,1)];
flowpayoffs.m56u1 = [ones(K,1) calX]*beta*[1 1]-delta(2)*ones(K,1)*[1 0];
Psi.m15function [capU0,capU1] = Psi(capU0,capU1,u0,u1,Pi,rho)
Psi.m33R0 = log(exp(capU0(:,1))+exp(capU1(:,1)));
Psi.m34R1 = log(exp(capU0(:,2))+exp(capU1(:,2)));
Psi.m38capU0 = u0 + rho*Pi*R0*[1 1];
Psi.m39capU1 = u1 + rho*Pi*R1*[1 1];
FixedPointPsi.m8function [capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,Psi,capU0,capU1)
FixedPointPsi.m28K = size(Pi,1);
FixedPointPsi.m32if isempty(capU0)
FixedPointPsi.m33 capU0 = zeros(K,2);
FixedPointPsi.m34end
FixedPointPsi.m35if isempty(capU1)
FixedPointPsi.m36 capU1 = zeros(K,2);
FixedPointPsi.m37end
FixedPointPsi.m41Uin0 = capU0+2*tFP;
FixedPointPsi.m42Uin1 = capU1+2*tFP;
FixedPointPsi.m43while (max(max(abs(Uin0-capU0)))>tFP) || (max(max(abs(Uin1-capU1)))>tFP);
FixedPointPsi.m44 Uin0 = capU0;
FixedPointPsi.m45 Uin1 = capU1;
FixedPointPsi.m46 [capU0,capU1] = Psi(Uin0,Uin1,u0,u1,Pi,rho);
FixedPointPsi.m47end
SimulateDP.m7function [A,iX] = SimulateDP(DeltaU,Pi,T,N)
SimulateDP.m23K = size(Pi,1);
SimulateDP.m39oneminPi = eye(K)-Pi';
SimulateDP.m40Pinf = inv([oneminPi(1:K-1,:);ones(1,K)])*[zeros(K-1,1);1];
SimulateDP.m44iX = RandomDiscr(Pinf*ones(1,N));
SimulateDP.m48Depsilon = random('ev',zeros(1,N),ones(1,N))-random('ev',zeros(1,N),ones(1,N));
SimulateDP.m49A = DeltaU(iX,1)' > Depsilon;
SimulateDP.m53for t = 2:T
SimulateDP.m54 iX = [iX;RandomDiscr(Pi(iX(end,:),:)')];
SimulateDP.m55 Depsilon = random('ev',zeros(1,N),ones(1,N))-random('ev',zeros(1,N),ones(1,N));
SimulateDP.m56 A = [A;(DeltaU(iX(end,:)+K*A(end,:)) > Depsilon)];
SimulateDP.m57end
estimatePi.m7function Pihat = estimatePi(iX,K)
estimatePi.m20T=size(iX,1);
estimatePi.m24for i=1:K
estimatePi.m25 for j=1:K
estimatePi.m26 Pihat(i,j)=sum(sum((iX(2:T,:)==j)&(iX(1:T-1,:)==i)))/sum(sum((iX(1:T-1,:)==i)));
estimatePi.m27 end
estimatePi.m28end
NegLogLikCCP.m7function [nll grad gradgrad] = NegLogLikCCP(A,iX,calX,Pi,beta,delta,rho,flowpayoffs,Psi,FixedPointPsi,tFP)
NegLogLikCCP.m34K = size(calX,1);
NegLogLikCCP.m38[u0,u1] = flowpayoffs(calX,beta,delta);
NegLogLikCCP.m39[capU0,capU1] = FixedPointPsi(u0,u1,Pi,rho,tFP,Psi,[],[]);
NegLogLikCCP.m40DeltaU = capU1-capU0;
NegLogLikCCP.m41pexit = 1./(1+exp(DeltaU));
NegLogLikCCP.m48Alag = [zeros(1,size(A,2));A(1:end-1,:)];
NegLogLikCCP.m49p = A + (1-2*A).*pexit(iX+K*(Alag));
NegLogLikCCP.m50nll = -sum(sum(log(p)));
NegLogLikCCP.m56if nargout>=2
NegLogLikCCP.m115 D00 = rho*Pi*diag(pexit(:,1));
NegLogLikCCP.m116 D01 = rho*Pi*diag(pexit(:,2));
NegLogLikCCP.m117 D10 = rho*Pi-D00;
NegLogLikCCP.m118 D11 = rho*Pi-D01;
NegLogLikCCP.m119 dPsi_dUbar = [[D00;D00;zeros(2*K,K)] [zeros(2*K,K);D01;D01] [D10;D10;zeros(2*K,K)] [zeros(2*K,K);D11;D11]];
NegLogLikCCP.m124 dPsi_dpar = [[zeros(2*K,1);ones(2*K,1)] [zeros(2*K,1);calX;calX] [zeros(2*K,1);-ones(K,1);zeros(K,1)]];
NegLogLikCCP.m128 dUbar_dpar = inv(eye(4*K)-dPsi_dUbar)*dPsi_dpar;
NegLogLikCCP.m129 dDeltaU_dpar = dUbar_dpar(2*K+1:4*K,:)-dUbar_dpar(1:2*K,:);
NegLogLikCCP.m133 npar = size(dUbar_dpar,2);
NegLogLikCCP.m134 indgrad = repmat((1-2*A).*(1-p),[1 1 npar]);
NegLogLikCCP.m135 for i=1:npar
NegLogLikCCP.m136 indgrad(:,:,i) = indgrad(:,:,i).*dDeltaU_dpar(iX+K*Alag+2*(i-1)*K);
NegLogLikCCP.m137 end
NegLogLikCCP.m138 indgrad=squeeze(sum(indgrad,1));
NegLogLikCCP.m139 grad = sum(indgrad)';
NegLogLikCCP.m140end
NegLogLikCCP.m149if nargout==3
NegLogLikCCP.m150 gradgrad = zeros(npar,npar);
NegLogLikCCP.m151 for n=1:size(indgrad,1)
NegLogLikCCP.m152 gradgrad = gradgrad + indgrad(n,:)'*indgrad(n,:);
NegLogLikCCP.m153 end
NegLogLikCCP.m154end
RandomDiscr.m7function iX = RandomDiscr(P)
RandomDiscr.m19K = size(P,1);
RandomDiscr.m20N = size(P,2);
RandomDiscr.m24ru = ones(K-1,1)*random('unif',zeros(1,N),ones(1,N));
RandomDiscr.m25cumP = cumsum(P);
RandomDiscr.m29iX = sum([ones(1,N);cumP(1:K-1,:)<=ru]);