Skip to content. | Skip to navigation

Personal tools

Graphics

Creating simple graphs to visualize your data

Stata Corp. completely rewrote their graphics commands for version 8 and enhanced their speed in version 9. Stata now produces publication-quality graphs that can be modified to fit publishers' formats, and schemes (templates) are available for many journals to automate this process.

This page gives a few examples of graphs that you might want to create, but it by no means does justice to the broad capability of Stata graphics. In addition to the Stata Graphics manual and the online help, other sources of information include A Visual Guide to Stata Graphics by Michael Mitchell (available from Stata Press), the drop-down Graphics menu in the Windows version of Stata, and a couple of online learning aids:

Each of the commands below creates an example of a commonly used graph. Use the Tanzania 1999 facility data file, then run the following commands to see the examples. Note that you need to be patient, since Stata can be a bit slow generating graphics.


clear
use "t:\statatut\exampfac.dta"

/* Create Government vs Non-govt authority */

gen govt= .
replace govt= 1 if authorit == 1
replace govt= 0 if authorit > 1 & !missing(authorit)
label define g 0 "Non-govt" 1 "Govt"
label value govt g

/* Count FP staff-hours/week at each facility */

gen fphrs= 0
foreach v of varlist fphour* {
   replace fphrs= fphrs + `v'  if !missing(`v')
}

/* Count FP methods available at each facility */

gen methods= 0
foreach v of varlist pill-natural {
   replace methods= methods + 1  if `v' == 1
}

/* Histogram of number of methods with normal curve superimposed */

histogram methods, normal

/* Box plot of methods by whether govt or non-govt facility */

graph box methods, by(govt)

/* Scatter plot of FP hours by number of methods */

scatter fphrs methods

/* Add a linear regression line to the scatter plot */

twoway (scatter fphrs methods) (lfit fphrs methods)

exit



Another topic?


Questions or comments? If you are affiliated with the Carolina Population Center, send them to Phil Bardsley or Dan Blanchette.