Code for replicating the empirical results in Section of "Constrained Conditional Moment Restriction Models"
===========================================================================================================

The .zip file contains the following items needing to replicate the analysis in Section 2.
-------------------------------------------------------------------------------------------

The following files are contained in the "Data Processing" folder.

1) m_d_806.mat: A matlab data file containing the 1980 Census Public Use Micro Sample used in the analysis. 
The data was originally employed in Angrist and Evans (American Economic Review, 1998) and Angrist and Fernandez-Val (Advances in Economics and Econometrics, 2013). 
This fie was downloaded in .dat format from Ivan Fernandez-Val's website https://sites.bu.edu/ivanf/research/ and converted to .mat format

2) ProcessAE.m: Matlab code for processing m_d_806.mat and extracting a subset of variables needed for our analysis. The ouput is a data file called ProcAE.mat saved in the same folder where code is ran.

3) ConvertCell.m: An auxiliary function called on by ProcessAE.m that convertes cells into numbers

-------------------------------------------------------------------------------------------

The following files are contained in the "Main Code" folder. All code should be run in the same directory in which ProcAE.mat is located.

1) ProcAE.mat: The matlab data file containing the processed data created by ProcessAE.m

-------------------------------

Code used to generate Figure 1:

2) InferenceLATEInd.m: The main file used to create Figure 1 in the paper. 
Given a set of linear (in)equality constraints, this file: (i) Computes the restricted estimator; (ii) Tests whether the linear constraints are satisfied; (iii) Obtains CIs for LATE(X) imposing the constraints.
The default specification is to impose only monotonicity. To add the nonpostivity constraints as well, set the NonPos variable to 1 at top of file (see comments in code).

3) TestPoint.m: An auxiliary function called on by InferenceLATEInd.m.
The function returns the p-value of our test when testing for linear inequality and equality constraints.

-------------------------------

Code used to generate Figure 2:

4) InferenceATEInd.m: The main file used to create Figure 2 in the paper.
Given a set of linear inequality constraints, this file: (i) Computes the restricted estimator and its implied values for ATE(X); (ii) Tests whether the linear constraints are satisfied; (iii) Obtains CIs for ATE(X) imposing the constraints.
The default specfiication is to only impose logical bounds on each subgroup (compliers, always takers, and never takers). 
To additionally impose monotonicity constraints set the SubMon variable to one, and to add the nonpostivity constraint set the SubPos variable to 1 (see comments in code).

5) TestPointIndATE.m: An auxiliary function called on by InferenceATEInd.m 
The function returns the p-value of our test for testing whether ATE(X) equals a hypothesized value (a nonlinear constraint) subject to other linear constraints holding.

6) f_ATEobj.m: An auxiliary function called on by TestPointIndATE.m. 
This function returns the objective function minimized in order to compute the test statistic.

7) f_ATEcon.m: An auxiliary function called on by TestPointIndATE.m.
This function returns the nonlinear constraint imposed when computing the test statistic.

8) f_BootATEobj.m: An auxiliary function called on by TestPointIndATE.m.
This function returns the objective function minimized in order to compute the bootstrap statistic.

9) f_BootATEcon.m: An auxiliary function called on by TestPointIndATE.m.
This function returns the nonlinear constraint imposed when computing the bootstrap statistic.

------------------------------

Code used to generate Table 1:

10) InferenceATEAgg.m: The main file used to create Table 1 in the paper.
Given a set of linear (in)equality constraints, this file: (i) Tests whether the linear constraints are satisfied; (ii) Obtains restricted estimator for the aggregate ATE among subgroups; (iii) Obtains CIs for the aggregate ATE among subgroups.
The default specification is to only impose logical bounds on each subgroup (compliers, always takers, and never takers). 
To additionally impose monotonicity constraints set the SubMon variable to one, and to add the nonpostivity constraint set the SubPos variable to 1 (see comments in code).

11) TestPointAggATE.m: An auxiliary function called on by InferenceATEAgg.m.
The function returns the p-value of our test for testing whether aggregate ATE equals a hypothesized value (a nonlinear moment) subject to other linear constraints holding.
Line 17 in the file allows us to select the algorithm used by the nonlinear optimizer. The default is "interior-point," which was used to create Table 1. For the Mon+Neg specification we found "sqp" algorithm to be more stable but gives almost identical answers.
 
12) f_AggATEobj.m: An auxiliary function called on by TestPointAggATE.m.
The function returns the criterion function that needs to be minimized in order to compute the test statistic.

13) f_GetATE.m: An auxiliary function called on by InferenceATEAgg.m, TestPointAggATE.m, and f_AggATEobj.m
The function computes the vector of ATE(X) (as a function of X) corresponding to the parameters entering the moment condition.