Tuesday, December 20, 2011

Stata Code Snippets: Plotting Multiple Series with Different Colors and Customized Legend for Different Observations

Here are some Stata code snippets for plotting multiple series. An example using the auto dataset that comes with Stata:

sysuse auto
twoway (scatter price weight if foreign == 1, mcolor(`f0')) (scatter price weight if foreign == 0, mcolor(`f1')),legend(lab(1 "Foreign") lab(2 "Domestic"))

The resulting graph shows domestic cars in the late 70s tend to be heavier for various price points.

image

Reference: st: RE: –twoway scatter- different colors for different observations [Statalist: The Stata Listserver], Stata Learning Module Graphics: Combining Twoway Scatterplots [UCLA Academic Technology Services]