Stata 15 help for twoway_rcap

[G-2] graph twoway rcap -- Range plot with capped spikes


twoway rcap y1var y2var xvar [if] [in] [, options]

options Description ------------------------------------------------------------------------- vertical vertical spikes; the default horizontal horizontal spikes

line_options change look of spike and cap lines msize(markersizestyle) width of cap

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.)


A range plot has two y variables, such as high and low daily stock prices or upper and lower 95% confidence limits.

twoway rcap plots a range, using capped spikes (I-beams) to connect the high and low values.


vertical and horizontal specify whether the high and low y values are to be presented vertically (the default) or horizontally.

In the default vertical case, y1var and y2var record the minimum and maximum (or maximum and minimum) y values to be graphed against each xvar value.

If horizontal is specified, the values recorded in y1var and y2var are plotted in the x direction, and xvar is treated as the y value.

line_options specify the look of the lines used to draw the spikes and their caps, including pattern, width, and color; see [G-3] line_options.

msize(markersizestyle) specifies the width of the cap. Option msize() is in fact twoway scatter's marker_option that sets the size of the marker symbol, but here msymbol() is borrowed to set the cap width. See [G-4] markersizestyle for a list of size choices.

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 Advanced use 2

Typical use

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

. sysuse sp500

. list date high low close in 1/5 +-----------------------------------------+ | date high low close | |-----------------------------------------| 1. | 02jan2001 1320.28 1276.05 1283.27 | 2. | 03jan2001 1347.76 1274.62 1347.56 | 3. | 04jan2001 1350.24 1329.14 1333.34 | 4. | 05jan2001 1334.77 1294.95 1298.35 | 5. | 08jan2001 1298.35 1276.29 1295.86 | +-----------------------------------------+

We will use the first 37 observations from these data:

. twoway rcap high low date in 1/37 (click to run)

Advanced use

twoway rcap works well when combined with a horizontal line representing a base value:

. sysuse sp500, clear

. generate month = month(date)

. sort month

. by month: egen lo = min(volume)

. by month: egen hi = max(volume)

. format lo hi %10.0gc

. summarize volume

Variable | Obs Mean Std. Dev. Min Max -------------+-------------------------------------------------------- volume | 248 12320.68 2585.929 4103 23308.3

. by month: keep if _n==_N

. twoway rcap lo hi month, xlabel(1 "J" 2 "F" 3 "M" 4 "A" 5 "M" 6 "J" 7 "J" 8 "A" 9 "S" 10 "O" 11 "N" 12 "D") xtitle("Month of 2001") ytitle("High and Low Volume") yaxis(1 2) ylabel(12321 "12,321 (mean)", axis(2) angle(0)) ytitle("", axis(2)) yline(12321, lstyle(foreground)) msize(*2) title("Volume of the S&P 500", margin(b+2.5)) note("Source: Yahoo!Finance and Commodity Systems Inc.") (click to run)

Advanced use 2

twoway rcap also works well when combined with a scatterplot to produce hi-lo-middle graphs. Returning to the first 37 observations of the S&P 500 used in the first example, we add a scatterplot of the closing value:

. sysuse sp500, clear

. twoway rcap high low date || scatter close date (click to run)

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