Other Twoway Plot Types by using Stata

In addition to basic line plots and scatterplots, the graph twoway command can draw a wide variety of other types. This section illustrates several more; type help graph twoway for a complete list.

Earlier, in Figures 3.10 and 3.11, we used graph twoway lfit (linear fit) to draw a simple regression line. A similar command, graph twoway qfit, draws a quadratic or second-order polynomial regression curve. Figure 3.17 illustrates using another variable from the Arctic9.dta dataset, sea ice volume. Volume is measured in cubic kilometers, so ASCII character 179 here provides the superscript for km3. Writing {superscripts} would also have worked.

The quadratic curve together with a horizontal line drawn at y = 0 (yline(0)) emphasize that mean September ice volume has been falling toward the floor. A linear model would not capture its accelerating trajectory, but in some respects the quadratic mode is unrealistic too. The curve in Figure 3.17 shows a slight but counterfactual slight rise in the early years, and if extrapolated to future years it would predict ice volumes below zero. In Chapter 8 we return to these data and consider a more plausible curve.

Figure 3.18 takes a different look at the same volume time series, this time using a range-area plot, graph twoway rarea, to show 95% uncertainty limits of plus or minus 1.35 thousand km3 (Schweiger et al. 2011). The range-area or rarea command looks for two y variables — in this example, volumehi and volumelo — that define the upper and lower bounds of an area to be shaded. A line plot of volume itself is drawn with a thick line (lwidth(thick)) and overlaid on top of the rarea plot so it can be seen over the shading.

The graph command drawing Figure 3.18 also specifies colors for both the rarea and line plots. color(gs13) assigns the rarea bands a gray scale color of13, closer to white (gs16) than to black (gs0). The line plot overlaid on these bands is colored green. Controlling the colors (instead of going with their defaults) does little for an image published in black and white, but has obvious value for other media. Type help colorstyle to see a list of colors available for the elements of Stata graphics.

Figure 3.19 overlays two other graph twoway types to make a different image from the same Arctic ice volume information. In this image the volume estimates themselves are drawn by graph twoway bar, while the uncertainty bands appear as range spikes (rspike) instead of the range area (rarea) we saw in Figure 3.18. The bars have a medium gray color (color(gs10)). Note that Figure 3.18 overlays the volume line on top of the uncertainty range area, whereas Figure 3.19 overlays the uncertainty range spikes on top of the volume bars. The order in both cases is required for visibility. You can experiment with similar commands to see how that works.

graph twoway bar should not be confused with graph bar, a different command introduced in the next section. twoway bar is basically a y-versus-x plot that assumes two measurement variables, and shares features with other twoway types such as y and x axis labeling and the possibility of overlays.

Stata offers more than 40 different graph twoway types, too many to catalog here. Later chapters demonstrate several others; type help graph twoway for the complete list, with links to the syntax of individual commands.

Source: Hamilton Lawrence C. (2012), Statistics with STATA: Version 12, Cengage Learning; 8th edition.

Leave a Reply

Your email address will not be published. Required fields are marked *