help mata mm_qr()

Title

mm_qr() -- Quantile regression

Syntax

Simple syntax

b =
mm_qrfit(y [, X, w, p, cons, b_init, relax])

y: real colvector containing dependent variable

X: real matrix containing predictors

w: real colvector containing weights; specify 1 for unweighted results

p: evaluation probability; default is 0.5 (median regression); may type . to select the default

cons: whether to include a constant; default is 1; specify 0 to omit the constant

b_init: real colvector containing starting values; may type . to select default starting values

relax: whether to return error in case of non-convergence; default is 0; specify 1 to bypass error

Advanced syntax

Initialize a new mm_qr() object

class mm_qr scalar S
or
S = mm_qr()

Provide data

S.data(y [, X, w, cons])

y: real colvector containing dependent variable

X: real matrix containing predictors; may specify . or J(0,0,.) to omit X

w: real colvector containing weights; specify 1 for unweighted results

cons: whether to include a constant; default is 1; specify 0 to omit the constant

Specifying S.data() clears any results and starting values that may already exist in S.

Retrieve results

b = S.b() fitted coefficients (column vector)

xb = S.xb([X]) linear predictions; may specify custom X; default
is to use X from S.data()

sdev = S.sdev() sum of weighted absolute deviations

conv = S.converged() 1 if converged, 0 else

iter = S.iter() number of iterations

gap = S.gap() duality gap

n = S.n() number of observations (rows in y)

N = S.N() number of observations (sum of weights)

cons = S.cons() 1 if model has a constant, 0 else

k = S.k() number of predictors

K = S.K() number of parameters (S.k()+S.cons())

k_omit = S.k_omit() number of omitted terms

omit = S.omit() column vector flagging omitted terms (0/1)

ymean = S.ymean() mean of y

means = S.means() means of X (row vector)

Specifying S.b(), S.converged(), S.iter(), S.xb(), S.sdev(),
or S.gap() will trigger estimation, if not already carried out.

Settings

S.p(p) evaluation probability; default is 0.5 (median regression)

S.b_init(b_init) real colvector containing starting values for the coefficients; the
default is to use a least-squares fit; may specify .z to clear starting values

S.tol(tol) convergence tolerance; default is 1e-8

S.maxiter(maxiter) maximum number of iterations; default is as set by set maxiter

S.beta(beta) step length of the Frisch-Newton algorithm; default is 0.99995

S.qd(qd) whether to use quad precision; default is 1; specify 0 for double precision

S.demean(demean) whether to use demeaning; default is 1; specify 0 to skip demeaning

S.collin(collin) whether to identify collinear terms; default is 1; specify 0 to skip

S.log(log) whether to display information on estimation progress; default is 0 (no display); specify
1 for an iteration log, 2 for progress dots (including line break at end), or 3 for progress dots
(without line break)

Settings can be changed at any time, but note that changing a setting will clear the
estimated results (but not the data). An exception is S.log() which does not
clear anything. Furthermore, S.b_init() is only allowed if S.data() has
already been applied.

All functions for settings can be used without argument to retrieve a setting. For
example, type b_init = S.b_init() to retrieve the vector of starting
values. The functions do not clear results if used in this form.

Description

mm_qr() fits a quantile regression model using an interior point (Frisch-Newton)
algorithm (Portnoy and Koenker 1997). It solves the same estimation
problem as official Stata's qreg (which is based on the linear
programming technique), although results may be slightly different
due to the optimization problem being a step-function (meaning that multiple acceptable
solutions may exist). See qrprocess (Chernozhukov, Fernandez-Val, and
Melly 2020) for a Stata implementation of quantile regression based on the
interior point algorithm. Note that the interior point algorithm tends to be
faster than the linear programming technique in large datasets.

mm_qr() uses quad precision and demeaning (unless the
constant is excluded) when computing cross products. Specifying quad=0 and/or
demean=0 will make mm_qr() faster, but possibly less precise. demean=0 is
potentially more harmful than quad=0 (and typically less effective in terms of
speed gains). Use quad=0 and demean=0 only if your data is well-behaved (reasonable
means, not much collinearity). For models without constant (cons=0), argument demean has no
effect. This is because mean-deviation formulas are not applicable in this case
(meaning that models without constant will generally be affected by precision
issues if the data is not well-behaved).

mm_qr() takes special action to identify collinear predictors and excludes
them during estimation. The coefficients for these terms will be set to 0 in the
resulting coefficient vector. If collinear predictors have already been removed
from X you can specify collin=0 to skip these extra computations (the
additional cost for these computations is only small; it is essentially zero if no
starting values are provided).

Examples

If you are only interested in the coefficients, you can use
mm_qrfit() (simple syntax) to obtain a quick quantile regression fit without much typing:

. sysuse auto
. qreg price weight length foreign
. mata:
: y = st_data(., "price")
: X = st_data(., "weight length foreign")
: mm_qrfit(y, X)
: end

In this example, the solution by mm_qrfit() is somewhat different from
the solution by qreg. Both solutions, however, are equally valid as they
both minimize the sum of absolute deviations. This can be seen in the next
example

For more sophisticated applications, use the advanced syntax. Example:

. mata:
: S = mm_qr() // initialize object
: S.data(y, X) // declare data
: S.p(0.5) // request median regression
: S.b() // compute result
: S.iter() // number of iterations?
: S.sdev() // sum of weighted absolute deviations?
: S.p(0.25) // request 0.25-quantile regression using same data
: S.log(1) // turn iteration log on
: S.b() // compute result
: end

Diagnostics

Missing values in y, X, or w will lead to error or invalid
results.

To preserve memory, mm_qr() does not store a copy of the data in S
(it only stores pointers). Modifying y, X or
w after S.data() has been applied will change the data used
by mm_qr(), but it will not clear existing results in S. This may lead to
inconsistent results. It is best not to modify y, X and w as
long as S exists.

Reference

Chernozhukov, V., I. Fernandez-Val, B. Melly. 2020. QRPROCESS: Stata module
for quantile regression: fast algorithm, pointwise and uniform inference.
Statistical Software Components S458763. Available from
http://ideas.repec.org/c/boc/bocode/s458763.html.

Portnoy, S., R. Koenker. 1997. The Gaussian hare and the Laplacian
tortoise: computability of squared-error versus absolute-error
estimators. Statistical Science 12(4):279-300.

Source code

mm_qr.mata

Author

Ben Jann, University of Bern, ben.jann@soz.unibe.ch

Blaise Melly, University of Bern, blaise.melly@vwi.unibe.ch

Also see

Online: help for
moremata, mm_ls(), qreg, qrprocess (from SSC)