Authors : Dongwoo Kim and Daniel Wilhelm
This project provides two Stata commands for nonparametric estimation of instrumental variable (NPIV) models with or without imposing monotonicity restrictions on the function of interest. The command npiv implements the estimators with user-chosen tuning parameters and npivcv with tuning parameters chosen by cross-validation.
More detailed description of the commands, their syntax, and examples can be found in Chetverikov, Kim, and Wilhelm (2017).
Files contained in this package:
- The file
npiv.adocontains thenpivcommand. - The file
npivcv.adocontains thenpivcvcommand. - The file
2-step-estimation.docontains code for a simulation experiment illustrating how to accommodate exogenous covariates with thenpivcommand. - The file
mcsimulation.docontains code for a simulation experiment that illustrates the relative performance of NPIV estimators with and without imposing shape restrictions. - The files
mcsimulation_shape.adoandmcsimulation_shape.adoare used inmcsimulation.do.
-
Download the package.
-
Install the
bsplineandpolysplinefunctions from ssc by opening STATA and typingssc install bspline ssc install polyspline -
Change into the directory containing this package.
-
Use the commands
npivandnpivcvas described below.
The commands npiv and npivcv estimate the function g(x) in the NPIV model
Y = g(X) + Z'γ + e E[e | Z, W] = 0
where
- Y is a scalar dependent variable (
depvar) - X is a scalar endogenous variable (
expvar) - W is a scalar instrument (
inst) - Z is a vector of exogeneous covariats (
exovar) - optional (need not be included), and
Syntax:
npiv depvar expvar inst [exovar] [if] [in] [, power_exp(#) power_inst(#) num_exp(#) num_inst(#) polynomial increasing decreasing]
npivcv depvar expvar inst [exovar] [if] [in] [, power_exp(#) power_inst(#) maxknot(#) polynomial increasing decreasing]
where
power_expis the power of basis functions for X (default = 2).power_instis the power of basis functions for W (default = 3).num_expis the number of knots for X (default = 2) when using a B-spline basis.num_instis the number of knots for W (default = 3) when using a B-spline basis.maxknotis the maximum number of knots upto which cross-validation is executed. (default = 5)- adding the
polynomialoption makes the estimator use a polynomial spline basis (default is B-spline basis). - adding the
increasingoption makes the estimator impose the constraint that the estimator of g(x) is increasing in x. - adding the
decreasingoption makes the estimator impose the constraint that the estimator of g(x) is decreasing in x.
In the current version of the code, shape restrictions can only be imposed with the B-spline basis. The code will produce an error when attempting to impose shape restrictions with a polynomial basis. When imposing a shape constraint, the current code also imposes the power of the B-spline for X to be 2.
Users can freely modify the power and the type of basis functions and the number of knots when shape restrictions are not imposed.
If options are left unspecified, the command runs on the default settings.
The command npivcv estimates the function g(x) in the NPIV model using cross-validation to find the optimal number of knots (setting num_exp=num_inst).
The commands npiv and npivcv save their estimates of g(x) over a grid of values for x in the variable npest. In addition, the commands are of the e-class so other results such as the coefficient vector are stored in e().
NPIV estimation with default options:
npiv y x w z
NPIV estimation with B-spline bases of powers 2 and 3, and 3 and 4 knots (for X and W, respectively):
npiv y x w z, power_exp(2) power_inst(3) num_exp(3) num_inst(4)
NPIV estimation with B-spline bases of powers 2 and 3, and 3 and 4 knots (for X and W, respectively), imposing that the estimator of g(x) is increasing:
npiv y x w z, power_exp(2) power_inst(3) num_exp(3) num_inst(4) increasing
NPIV estimation using cross-validation to determine the optimal number of knots, imposing that the estimator of g(x) is increasing:
npivcv y x w z, power_exp(2) power_inst(3) increasing