help qqplot3

Title

qqplot3 -- plot the unweighted and weighted quantiles of one variable against the corresponding quantiles of another variable (Q-Q plot)

Syntax

qqplot3 varname1 varname2 [if] [in] [weight] ,
[ generate(newvar1 newvar2) ]

qqplot3 varname [if] [in] [weight] ,
by(groupvar) [ generate(newvar1 newvar2) ]

Main
* by(groupvar)
specifies a group variable to specify precisely two
groups of varname. by() may be only be specified with a single variable name.

Options
generate(newvar1 newvar2) specifies two new variable names to hold
the quantiles.

* by(groupvar) must be specified when only one varname is provided.

fweights, aweights, and pweights are allowed
(see [U] 11.1.6 weight).

Description

qqplot3 generates a quantile-quantile plot (Q-Q plot), in which the quantiles of one variable are plotted
against the quantiles of another. qqplot3 holds three advantages over qqplot. First and most importantly,
qqplot3 allows the user to specify weights. This enables visual inspection of unadjusted and weighted baseline
covariates to assess balance, a necessary condition for causal inference. This similarly makes Q-Q plots
accessible to investigators with complex survey designs using sampling weights. Second, unlike qqplot, qqplot3
provides a "by" option for a grouping variable (such as treatment assignment) - a convenience factor for the user.
And third, qqplot3 provides the option of saving the quantiles generated by the program, which may be useful for
conducting additional analyses.

qqplot3 draws heavily on the code used in cquantile, a user-written program by Nicholas J. Cox (downloadable from SSC).
However, qqplot3 relies on pctile for calculating the quantiles, using the default method, which inverts the empirical distribution
function by using averages, where the function is flat (this is the same method used by summarize; see [R] summarize). This method differs
somewhat from the interpolation method used in cquantile and qqplot (see Methods and formulas
in [D] pctile). qqplot3 uses the default method because weights cannot be specified in pctile when the interpolation method
(altdef) is used. That said, the quantiles generated between the two methods are quantitatively similar.

fixsort, another program written by Nicholas J. Cox (downloadable from SSC), must be installed in order for qqplot3 to
run (an error message will appear, otherwise).

Examples

Testing for covariate balance in reweighted data

Load example data

. webuse cattaneo2, clear

Estimate propensity score for the binary treatment mbsmoke and generate inverse probability of treatment weights (IPTW)

. logit mbsmoke mmarried c.mage##c.mage fbaby medu

. predict pscore, pr

. gen iptw = cond(mbsmoke, 1/pscore, 1/(1-pscore))

Inspect balance in the distributions of mother's age (mage) by smoking status (mbsmoke) - before and after IPTW adjustment

. qqplot3 mage, by(mbsmoke)

. qqplot3 mage [pw=iptw], by(mbsmoke)

Survey with sampling weights

Load example data

. use http://www.stata-press.com/data/r13/nhanes2b.dta, clear

Inspect the distributions of systolic blood pressure (bpsystol) by (female) - without and with sampling weights, and save the quantiles

. qqplot3 bpsystol, by(female) gen(bp0 bp1)

. qqplot3 bpsystol [pw=finalwgt], by(female) gen(bpw0 bpw1)

Saved results

qqplot3 stores the following result in r():

Scalar

r(nq) the number of quantiles used to compute percentiles. This value will always be equal to the variable with the smallest N, + 1

Citation of mmws

qqplot3 is not an official Stata command. It is a free contribution
to the research community, like a paper. Please cite it as such:

Linden, Ariel. 2014.
qqplot3: Stata module for plotting unweighted and weighted Q-Q plots.

Author

Ariel Linden

President, Linden Consulting Group, LLC

Ann Arbor, MI, USA

alinden@lindenconsulting.org

http://www.lindenconsulting.org

Acknowledgments

I wish to thank Nicholas J. Cox for his support while developing qqplot3 and to Kit Baum for suggesting the name qqplot3,
and recommending the error capturing code. Finally, I would like to thank Chuck Huber at StataCorp for his insights that led me to
develop the program.

Also see

Online: qqplot, pctile, separate, cquantile (if installed), fixsort (if installed)