Stata 15 help for twoway dropline

[G-2] graph twoway dropline -- Twoway dropped-line plots


twoway dropline yvar xvar [if] [in] [, options]

options Description ------------------------------------------------------------------------- vertical vertical dropped-line plot; the default horizontal horizontal dropped-line plot base(#) value to drop to; default is 0

marker_options change look of markers (color, size, etc.) marker_label_options add marker labels; change look or position line_options change look of dropped lines

axis_choice_options associate plot with alternative axis

twoway_options titles, legends, axes, added lines and text, by, regions, name, aspect ratio, etc. ------------------------------------------------------------------------- All explicit options are rightmost, except vertical and horizontal, which are unique; see repeated options.


Graphics > Twoway graph (scatter, line, etc.)


twoway dropline displays numeric (y,x) data as dropped lines capped with a marker. twoway dropline is useful for drawing plots in which the numbers vary around zero.


vertical and horizontal specify either a vertical or a horizontal dropped-line plot. vertical is the default. If horizontal is specified, the values recorded in yvar are treated as x values, and the values recorded in xvar are treated as y values. That is, to make horizontal plots, do not switch the order of the two variables specified.

In the vertical case, dropped lines are drawn at the specified xvar values and extend up or down from 0 according to the corresponding yvar values. If 0 is not in the range of the y axis, lines extend up or down to the x axis.

In the horizontal case, dropped lines are drawn at the specified xvar values and extend left or right from 0 according to the corresponding yvar values. If 0 is not in the range of the x axis, lines extend left or right to the y axis.

base(#) specifies the value from which the lines should extend. The default is base(0), and in the above description of options vertical and horizontal, this default was assumed.

marker_options specify the look of markers plotted at the data points. This look includes the marker symbol and its size, color, and outline; see [G-3] marker_options.

marker_label_options specify if and how the markers are to be labeled; see [G-3] marker_label_options.

line_options specify the look of the dropped lines, including pattern, width, and color; see [G-3] line_options.

axis_choice_options associate the plot with a particular y or x axis on the graph; see [G-3] axis_choice_options.

twoway_options are a set of common options supported by all twoway graphs. These options allow you to title graphs, name graphs, control axes and legends, add lines and text, set aspect ratios, create graphs over by() groups, and change some advanced settings. See [G-3] twoway_options.


Remarks are presented under the following headings:

Typical use Advanced use Cautions

Typical use

We have daily data recording the values for the S&P 500 in 2001:

. sysuse sp500

. list date close change in 1/5 +---------------------------------+ | date close change | |---------------------------------| 1. | 02jan2001 1283.27 . | 2. | 03jan2001 1347.56 64.29004 | 3. | 04jan2001 1333.34 -14.22009 | 4. | 05jan2001 1298.35 -34.98999 | 5. | 08jan2001 1295.86 -2.48999 | +---------------------------------+

In [G-2] graph twoway bar we graphed the first 57 observations of these data by using bars. Here is the same graph presented as dropped lines:

. twoway dropline change date in 1/57, yline(0, lstyle(foreground)) (click to run)

In the above, we specified yline(0) to add a line across the graph at 0, and then we specified yline(, lstyle(foreground)) so that the line would have the same color as the foreground. We could have instead specified yline(, lcolor()). For an explanation of why we chose lstyle() over foreground(), see Advanced use: Overlaying in [G-2] graph twoway bar.

Advanced use

Dropped-line plots work especially well when the points are labeled. For instance,

. sysuse lifeexp, clear

. keep if region==3

. generate lngnp = ln(gnppc)

. quietly regress le lngnp

. predict r, resid

. twoway dropline r gnp, yline(0, lstyle(foreground)) mlabel(country) mlabpos(9) ylab(-6(1)6) subtitle("Regression of life expectancy on ln(gnp)" "Residuals:" " ", pos(11)) note("Residuals in years; positive values indicate" "longer than predicted life expectancy") (click to run)


See Cautions in [G-2] graph twoway bar, which applies equally to twoway dropline.

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index