help for subsetplot

Plots for each subset with rest of the data as backdrop

subsetplot
command
yvarlist
xvar
[if]
[in]
,
by(byvar)
[
subset(twoway_options)
backdrop(twoway_command)
graph_options
ends[(graph_options)]
extremes[(graph_options)]
combine(combine_options)
]

Description

subsetplot produces an array of scatter or other
twoway plots for yvarlist versus xvar according to a
further variable byvar. There is one plot for observations
for each distinct subset
of byvar in which data for that subset are highlighted and the rest
of the data shown as backdrop. Graphs are drawn individually and then
combined with graph combine.

Remarks

This approach was discussed in Cox (2010). See also Schwabisch (2014)
for an example. Readers knowing interesting or useful examples or
discussions, especially early in date or comprehensive in detail, are
welcome to email the author.

Options

by() specifies a numeric or string variable byvar defining
the distinct subsets being plotted. This is a required option.

subset(twoway_options) specifies options of twoway
used to highlight observations in each distinct subset.

backdrop(command) specifies a twoway command to
show the rest of the data. This option is needed if and only if it is
desired to use a different command from that specified immediately after
the subsetplot command.

graph_options are options of twoway used to display
observations for the rest of the data in each plot.

ends[(twoway_options)] specifies that end values
(for the lowest and highest x value in each subset) be flagged
graphically. Options may be specified to tune how this is done.

extremes[(twoway_options)] specifies that extreme
values (for the lowest and highest y value in each subset) be flagged
graphically. Options may be specified to tune how this is done. (Note:
if two or more variables are specified as yvarlist, only the first
variable is so treated.)

combine() specifies options allowed with graph combine.

Examples

. set scheme s1color

. sysuse auto, clear

. subsetplot scatter mpg weight, by(rep78)

. subsetplot scatter mpg weight, subset(ms(none) mla(rep78) mlabsize(*1.5) mlabpos(0) mlabcolor(blue)) by(rep78)

. webuse grunfeld

. subsetplot line invest year, by(company) ysc(log) yla(1 10 100 1000)

. gen invest2 = round(invest)

. subsetplot line invest year, by(company) ends(mla(invest2)) plotregion(margin(l+5 r+4)) combine(imargin(vsmall)) ysc(log) yla(1 10 100 1000)

Author

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

n.j.cox@durham.ac.uk

Acknowledgments

Stefan Gawrich reported a bug, on which Daniel Klein commented helpfully.

References

Cox, N.J. 2010. Graphing subsets.
Stata Journal 10: 670-681.

Schwabish, J.A. 2014. An economist's guide to visualizing data.
Journal of Economic Perspectives 28: 209-234.

Also see

On-line: help for twoway, help for graph matrix,
help for graph combine