# Re: st: Doubt about Stata quantile regression code re: endogeneity

 From "Brian P. Poi (StataCorp)" To statalist@hsphsun2.harvard.edu Subject Re: st: Doubt about Stata quantile regression code re: endogeneity Date Fri, 26 Sep 2003 20:55:37 -0500 (CDT)

```On Fri, 26 Sep 2003, Chih-Mao Hsieh wrote:

> Dear Statalisters,
>
> Myself and a co-author are stuck on how to do the programming mentioned
> by the Stata econometrician below... I thought this Statalist might
> help. Can anybody provide some insight (or better yet, a few lines of
> code as a potential guide!) on the dilemma outlined below between *****?
>
>
> Chihmao.
>
> Dear Sergio,
>
> ***** The easiest way to get standard errors for the 2SLAD model is to
> use the bootstrap. Note that you will want to bootstrap both
> stages of estimation, not just the second stage. Therefore, when
> you use -bootstrap- or -bstrap-, you will need to write a program
> that estimates your entire model.
> A seminal paper in this area is Amemiya (1982, Econometrica). There,
> among other things he shows that even though you use quantile regress-
> ion in the second stage, you should still use OLS in the first stage;
> this is what he calls the 2SLAD model. He also derives the asymptotic
> standard errors for this model, though my guess is that using the
> bootstrap is easier. *****
>

Chihmao and Sergio are referring to a method to estimate a quantile
regression that contains an endogenous variable.  For concreteness,
suppose we wish to estimate the following model using least absolute
deviations:

(1)   mpg = a + b*foreign + c*price + error

We suspect that "price" may be correlated with the error term, and so we
need to use an instrumental variables estimator.  We have two variables,
"weight" and "length", that are correlated with "price" but not the error
term.

A simple two-stage estimator proceeds as follows:

1.  Regress "price" on "weight", "length", and "foreign" using OLS
and calculate the fitted values; call them "phat"
2.  Estimate equation (1) with "phat" in place of "price" using
quantile regression (-qreg-)

As is usually the case, the standard errors from the second-stage
regression are incorrect because they ignore the fact that "phat" is
itself estimated.  Chihmao would like to know how to use the bootstrap to
obtain standard errors.  The following code does just that:

sysuse auto, clear

program bootit
version 8.0

// Stage 1
regress price foreign weight length
predict double phat, xb

// Stage 2
qreg mpg foreign phat
end

bootstrap "bootit" _b, reps(1000) dots

Whenever one bootstraps an estimator that uses iteration to find the
optimal parameters (as -qreg- does), there is a chance that for some
bootstrap samples the algorithm does not converge.  If Chihmao runs into
that problem with his model, I'll be happy to help him out if he sends his
dataset and dofile to stata@stata.com or to me privately.

-- Brian
bpoi@stata.com

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```