help for sepscatter

Scatter (or other twoway) plots separated by a third variable

sepscatter
yvar
xvar
[weight]
[if]
[in]
,
separate(varname)
[
missing
{
mylabel(varname)
|
mynumeric(varname)
}
graph_options
]

Weights are supported if and as allowed by the twoway plot requested.

Description

sepscatter produces a scatter or other twoway plot
for yvar versus xvar. Points, or as recast lines, are
portrayed separately according to the distinct values of a third
variable, which must be specified through the separate() option.

Options

separate() specifies a variable used to classify points or lines
on the plot. Typically, the variable consists of two or more categories,
and points or lines will be shown distinctly according to those
categories, say by using different markers. The default is to show only
observations for which the variable specified is non-missing. This is a
required option.

missing specifies that observations that are missing on the
variable specified in separate() should be included in the plot.

mylabel() specifies a variable which will be used for marker
labels for each category shown. Commonly, this will be the variable
itself. For example, showing distinct values 1 to 5 may be preferred to
showing arbitrary markers representing 1 to 5. With this option marker
symbols themselves will be suppressed. Alternatively, you may wish to
use a variable created for the purpose.

mynumeric() specifies a variable which will be used for marker
labels for each category shown. Commonly, this will be the variable
itself. For example, showing distinct values 1 to 5 may be preferred to
showing arbitrary markers representing 1 to 5. With this option marker
symbols themselves will be suppressed. Alternatively, you may wish to
use a variable created for the purpose. This option resembles mylabel()
but differs in insisting that any value labels of a numeric variable be
ignored and the numeric values be used instead. Thus with the foreign
variable of the auto dataset, the value labels "Domestic" and "Foreign" would
be informative, but create a messy graph with much overlap.
mynumeric(foreign) would insist that the underlying numeric values be
shown, in this case 0 and 1.

Only one of mylabel() and mynumeric() may be specified.

graph_options are options allowed with scatter.
Note in particular that addplot() is supported.

Particular attention is drawn to recast(), which
specifies a twoway plottype that may be used to plot some yvar
versus some xvar. Possibilities include line and
connected.

Examples

. sysuse auto, clear

. sepscatter mpg weight, separate(foreign)

. gen myforeign = substr("df", foreign + 1, 1)

. sepscatter mpg weight, separate(foreign) mylabel(myforeign)

. sepscatter mpg weight, separate(foreign) mynumeric(myforeign)

. sepscatter mpg weight, separate(rep78) mylabel(rep78)

. sepscatter mpg weight, separate(rep78) missing legend(ring(0) pos(1) col(1))

. webuse grunfeld, clear

. sepscatter mvalue time, separate(company) recast(connect) ysc(log) yla(5000 2000 1000 500 200 100) legend(pos(3) col(1))

. sepscatter mvalue time, separate(company) recast(connect) ysc(log) yla(5000 2000 1000 500 200 100) legend(pos(3) col(1))

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk

Acknowledgments

Vince Wiggins suggested adding recast() examples to the help and flagged a small bug.
Alfonso Sánchez-Peñalver posed the problem addressed by the
mynumeric() option.

References

Cox, N.J. 2005.
Classifying data points on scatter plots.
Stata Journal 5: 604-606.
http://www.stata-journal.com/sjpdf.html?articlenum=gr0023

Also see

On-line: help for scatter, help for twoway