*! version 1.1.2 25oct2017
help npivcv (SJ18-4: st0547)

Title

npivcv -- Nonparametric instrumental-variable regression with cross-validation

Syntax

Nonparametric instrumental-variable (NPIV) regression with a B-spline basis and cross-validated numbers of knots

npivcv depvar expvar inst [exovar] [if] [in]
[, options]

NPIV regression with a polynomial basis and cross-validated powers

npivcv depvar expvar inst [exovar] [if] [in]
[, polynomial options]

NPIV regression with an increasing shape restriction and cross-validated numbers of knots

npivcv depvar expvar inst [exovar] [if] [in]
[, increasing options]

NPIV regression with a decreasing shape restriction and cross-validated numbers of knots

npivcv depvar expvar inst [exovar] [if] [in]
[, decreasing options]

options

power_exp(integer) degree of the power of the basis
function for the endogenous regressor; default is power_exp(2)

power_inst(integer) degree of the power of the basis
function for the instrument; default is power_inst(3)

maxknot(integer) number of knots to be evaluated in
cross-validation; if maxknot(k) is typed and N is the sample size, the
cross-validation procedure evaluates the performance of
NPIV estimator with numbers of knots from 3 to max(N^(1/5), k) and executes NPIV regression
with the optimal number of knots; if polynomial is used, then
maxknot()
specifies maximum power to be evaluated; default is maxknot(5)

pctile(integer) domain over which the nonparametric sieve estimator is evaluated; default is pctile(5)

polynomial specify the type of both bases p(x) and q(w) to
be power polynomials

increasing impose that the NPIV estimator is an
increasing
function of the endogenous regressor

decreasing impose that the NPIV estimator is a
decreasing function of the endogenous regressor

expvar is an endogenous regressor, inst an instrument, and exovar a list of exogenous covariates.

exovar may contain factor variables; see fvvarlist.

Description

npivcv is built upon npiv and provides NPIV models with the
optimal numbers of knots. npivcv constrains the two numbers of knots
for expvar and inst to be equal and then uses cross-validation to
choose them in a data-driven fashion. Under the default setup, npiv runs
series instrumental-variable regression on a B-spline basis with no shape restriction.

npivcv requires community-contributed commands bspline and
polyspline to be installed from Statistical Software Components.

npivcv with polynomial uses a polynomial basis instead of a
B-spline basis. Options power_exp() and power_inst() are unnecessary
and are ignored if they are specified by the user because the
cross-validation procedure automatically chooses the optimal powers.

npivcv with increasing (or decreasing) imposes an increasing
(or decreasing) shape restriction on the nonparametric function g(X). A
monotone shape restriction may significantly improve the performance of the
NPIV estimator (Chetverikov and Wihelm 2017).

npivcv stores the fitted values of g(X) in the Stata
variable npest. Other results are stored in e().

Options

power_exp(integer) specifies a positive integer for the degree of the
spline basis for the endogenous regressor. The default is power_exp(2).
The user need not specify this option if polynolmial is used.

power_inst(integer) specifies a positive integer for the degree of the
spline basis for the instrument. power_inst() must be equal to or
larger than power_exp(). The default is power_inst(3). The user
need not specify this option if polynolmial is used.

maxknot(integer) is a positive integer for the maximum number of knots to be
considered in the cross-validation procedure. With a sample size N and the
option maxknot(k), the cross-validation procedure evaluates the
performance of the NPIV estimator with numbers of knots from 3 to max(N^{1/5},
k) and executes the NPIV regression with the optimal number of knots from that
range. If the option polynomial is used, then maxknot() specifies
the maximum power of the polynomial to be considered. The default is
maxknot(5).

pctile(integer) specifies the domain of the endogenous regressor over
which the NPIV estimator of g is to be computed. pctile(integer) must be a positive integer smaller than 50. For a given value of k, the NPIV
estimator is computed at fine grid points within the kth and the (100-k)th
percentiles of the empirical distribution of X. The default is
pctile(5).

polynomial specifies the type of both bases p(x) and q(w) to be power
polynomials. Choices of numbers of knots are ignored under this option.
Shape restrictions cannot be imposed for this basis, and an error message is
generated if this option is used together with decreasing or
increasing.

increasing imposes that the NPIV estimator is an increasing function of
the endogenous regressor. If this option is specified, the basis p(x) is
forced to be quadratic B-spline, and the option power_exp(integer) is not
used. An error occurs when this option is used together with one of the
options decreasing or polynomial. The basis q(w) for the
instrument is also restricted to be a B-spline, but the power and number of
knots can be freely chosen through power_inst(integer) and
num_inst(integer).

decreasing imposes that the NPIV estimator is a decreasing function of
the endogenous regressor. The same restrictions as for increasing apply
to this option.

Examples

Setup - Y = price, X = mpg, W = trunk, Z = weight

. sysuse auto

NPIV regression with cross-validation under a default setting

. npivcv price mpg trunk

NPIV regression with a cubic B-spline for X, a quintic B-spline
for W, and cross-validated number of knots

. npivcv price mpg trunk, power_exp(3) power_inst(5)

NPIV regression with a polynomial basis cross-validated power

. npivcv price mpg trunk, polynomial

NPIV regression imposing increasing shape with a cubic B-spline
for X and a quintic B-spline for W and cross-validated number of knots

. npivcv price mpg trunk, power_exp(3) power_inst(5) increasing

Default setup regression without Z and plot the fitted value with data

. npivcv price mpg trunk

. scatter price mpg || line npest grid

Stored results

npivcv stores the following in e():

Scalars

e(N) number of observations

e(powerexp) power of basis for endogenous regressor

e(powerinst) power of basis for instrument

e(numexp) number of knots of basis for endogenous regressor

e(numinst) number of knots of basis for instrument

e(pct) value specified by pctile() option

e(xmin) minimum of endogenous regressor

e(xmax) maximum of endogenous regressor

e(wmin) minimum of instrument

e(wmax) maximum of instrument

e(gmin) minimum of grid on which g is evaluated

e(gmax) maximum of grid on which g is evaluated

e(optknot) optimal number of knots found by cross-validation

e(maxknot) maximum number of knots (or power for polynomial) to be evaluated

Macros

e(cmd) npivcv

e(depvar) name of outcome

e(expvar) name of endogenous regressor

e(inst) name of instrument

e(exovar) list of exogenous covariates

e(basis) type of spline basis

e(title) NPIV regression with cross-validation

e(shape) type of imposed shape restriction

Matrices

e(b) coefficient vector

Remarks

This is a first and preliminary version. Please feel free to share your
comments, reports of bugs, and propositions for extensions.

If you use this command in your work, please cite Chetverikov and Wilhelm
(2017) and Chetverikov, Kim, and Wilhelm (2018).

References

Chetverikov, D., D. Kim, and D. Wilhelm. 2018.
Nonparametric instrumental-variable estimation.
Stata Journal 18: 937-950.

Chetverikov, D., and D. Wilhelm. 2017. Nonparametric instrumental variable
estimation under monotonicity. Econometrica 85: 1303-1320.

Authors

Denis Chetverikov

Department of Economics

University of California, Los Angeles

Los Angeles, CA

chetverikov@econ.ucla.edu

Dongwoo Kim

Department of Economics

University College London

London, UK

dongwoo.kim.13@ucl.ac.uk

Daniel Wilhelm

Department of Economics

University College London

London, UK

d.wilhelm@ucl.ac.uk

Also see

Article: Stata Journal, volume 18, number 4: st0547