help for multiline

Multiple panel line plots

multiline
yvars
xvar
[if exp]
[in range]
[
,
missing
by(by_options)
recast(twoway_command)
{{
separate
|
sepby(varname)
}
mylabels(labelspec)
twoway_options
saving(filespec)
]

Description

multiline by default plots yvars against xvar as a
series of line plots in separate panels. A common application is to
multiple time series, especially those measured in different units
and/or on very different scales.

multiline works with a temporarily restructured dataset in which
different yvars are stacked into one. The graph then is
based on use of twoway line, by(). The original variable labels
(or, if labels are not defined, variable names) become the value labels
of the stacking variable.

It is not assumed that the data have been tsset or xtset.
However, if a panel variable has been declared, an attempt is made to
avoid spurious connections across panels.

The recast() option opens the door to using the same design for
other kinds of plots, such as scatter or connected plots. Note that
as connect(L) is the default it must be switched off explicitly
if you do not wish to connect data points.

Options

Data shown

missing specifies that observations with some missing values on
yvars should be included in the sample. The default is to ignore
observations with any missing values.

Graph appearance

by() specifies options of the by() option. The
defaults are cols(1) yrescale note(""). Note that _stack
produced temporarily by the program is already wired in as varlist
for this option.

recast() specifies that the graph be recast to another
twoway type. See help on advanced options.

separate specifies that the yvars be plotted differently.
The default is to use the same style for all. With separate a legend will
spring into being, which you should usually suppress.
The line and marker defaults for your scheme might not be to your liking,
so you can change those as usual.

sepby() specifies that data be shown differently according to
the distinct values of the variable named. There is then scope for
specifying different marker symbols, marker colours, and so forth.

separate and sepby() may not be combined.

sepby() or separate are allowed with recast(), but
your risk is that the code may not be general enough to cope with your request.

mylabels() allows control of labels used to describe each panel.
Most commonly, this option is used to modify original variable labels
and/or to stack them vertically into shorter segments. New labels should
be bound in double quotes if they contain spaces and in compound double
quotes if they are to extend over multiple lines. Such labels have
no lasting effect on the dataset used.

twoway_options are other options of twoway.
Note that the defaults are
ytitle("") yla(, ang(h)) c(L) subtitle(, pos(9) bcolor(none) nobexpand place(e)). In particular note that subtitle(, orient(vertical)) may be preferred.

Saving data

savedata() specifies that data used to produce the graph be
saved as a separate dataset. The axis variable will be named _y if
that name is available. _rank. separate or sepby() is ignored for this
purpose.

Examples

. webuse grunfeld, clear

. multiline invest mvalue kstock year, name(ML1, replace)

. multiline invest mvalue kstock year if company == 1, name(ML2, replace)

. multiline invest mvalue kstock year if company == 1, recast(connected) name(ML3, replace)

. multiline invest mvalue kstock year if company == 1, recast(connected) mylabels(`" `" "Gross" "investment" "' `" "Market" "value" "' `" "Plant and" "equipment value" "' "') name(ML4, replace)

. multiline invest mvalue kstock year if company == 1 , xtitle("") recast(connected) separate name(ML5, replace)

. multiline invest mvalue kstock year if company == 1 , xtitle("") recast(connected) separate by(legend(off)) ms(O D T) lc(black orange blue) mc(black orange blue) name(ML6, replace)

. sysuse auto, clear

. multiline mpg weight length displacement price, recast(scatter) c(none) by(col(2)) ms(Oh) subtitle(, orient(vertical)) name(ML7, replace)

. multiline mpg weight length displacement price, recast(scatter) c(none) by(col(2)) ms(Oh) subtitle(, orient(vertical)) sepby(foreign) ms(Oh +) name(ML8, replace)

Author

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

n.j.cox@durham.ac.uk

Acknowledgments

Questions on Statalist led to improvements. The separate option arises from a question by Zeeshan Fareed. A bug fix was triggered by a problem reported by Shem Shen.

Also see

On-line: help for line, tsline, xtline, multidot (if installed), sparkline (if installed)