0% found this document useful (0 votes)
152 views

Cheat Sheet: With Stata 14.1

This document provides a cheat sheet for creating various types of plots and graphs using Stata software. It outlines the basic syntax for creating histograms, scatter plots, line graphs, bar charts, and other visualizations for one, two, or three variables. Options are presented for customizing the appearance, axes, titles, legends, and other elements of the plots. The cheat sheet also provides examples of combining plot types and using plots for regression analyses and summary statistics.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Cheat Sheet: With Stata 14.1

This document provides a cheat sheet for creating various types of plots and graphs using Stata software. It outlines the basic syntax for creating histograms, scatter plots, line graphs, bar charts, and other visualizations for one, two, or three variables. Options are presented for customizing the appearance, axes, titles, legends, and other elements of the plots. The cheat sheet also provides examples of combining plot types and using plots for regression analyses and summary statistics.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Data Visualization BASIC PLOT SYNTAX: graph <plot type>

variables: y first
y1 y2 … yn x [in]
plot-specific options
[if], <plot options>
facet
by(var)
annotations
xline(xint) yline(yint) text(y x "annotation")
with Stata 14.1 Cheat Sheet titles axes
For more info see Stata’s reference manual (stata.com) title("title") subtitle("subtitle") xtitle("x-axis title") ytitle("y axis title") xscale(range(low high) log reverse off noline) yscale(<options>)
ONE VARIABLE sysuse auto, clear custom appearance plot size save
<marker, line, text, axis, legend, background options> scheme(s1mono) play(customTheme) xsize(5) ysize(4) saving("myPlot.gph", replace)
CONTINUOUS
histogram mpg, width(5) freq kdensity kdenopts(bwidth(5)) TWO+ CONTINUOUS VARIABLES
histogram
bin(#) • width(#) • density • fraction • frequency • percent • addlabels y1 graph matrix mpg price weight, half twoway pcspike wage68 ttl_exp68 wage88 ttl_exp88
addlabopts(<options>) • normal • normopts(<options>) • kdensity scatter plot of each combination of variables Parallel coordinates plot (sysuse nlswide1)
kdenopts(<options>) y2
half • jitter(#) • jitterseed(#) vertical, • horizontal
kdensity mpg, bwidth(3) y3 diagonal • [aweights(<variable>)]
smoothed histogram
bwidth • kernel(<options> main plot-specific options; twoway scatter mpg weight, jitter(7) twoway pccapsym wage68 ttl_exp68 wage88 ttl_exp88
normal • normopts(<line options>) see help for complete set Slope/bump plot
scatter plot (sysuse nlswide1)
jitter(#) • jitterseed(#) • sort • cmissing(yes | no) vertical • horizontal • headlabel
DISCRETE connect(<options>) • [aweight(<variable>)]
graph bar (count), over(foreign, gap(*0.5)) intensity(*0.5) THREE VARIABLES
bar plot graph hbar draws horizontal bar charts
(asis) • (percent) • (count) • over(<variable>, <options: gap(*#) • 23 twoway scatter mpg weight, mlabel(mpg) twoway contour mpg price weight, level(20) crule(intensity)
relabel • descending • reverse>) • cw •missing • nofill • allcategories • 20 scatter plot with labelled values 3D contour plot
percentages • stack • bargap(#) • intensity(*#) • yalternate • xalternate ccuts(#s) • levels(#) • minmax • crule(hue | chue| intensity) •
17 jitter(#) • jitterseed(#) • sort • cmissing(yes | no) scolor(<color>) • ecolor (<color>) • ccolors(<colorlist>) • heatmap
graph bar (percent), over(rep78) over(foreign) 2 10 connect(<options>) • [aweight(<variable>)] interp(thinplatespline | shepard | none)
grouped bar plot graph hbar ...
(asis) • (percent) • (count) • over(<variable>, <options: gap(*#) • twoway connected mpg price, sort(price)
relabel • descending • reverse>) • cw •missing • nofill • allcategories • regress price mpg trunk weight length turn, nocons
a b c percentages • stack • bargap(#) • intensity(*#) • yalternate • xalternate scatter plot with connected lines and symbols matrix regmat = e(V) ssc install plotmatrix
jitter(#) • jitterseed(#) • sort see also line plotmatrix, mat(regmat) color(green)
DISCRETE X, CONTINUOUS Y connect(<options>) • cmissing(yes | no) heatmap mat(<variable) • split(<options>) • color(<color>) • freq
graph bar (median) price, over(foreign) graph hbar ...
bar plot (asis) • (percent) • (count) • (stat: mean median sum min max ...) twoway area mpg price, sort(price) SUMMARY PLOTS
over(<variable>, <options: gap(*#) • relabel • descending • reverse line plot with area shading
sort(<variable>)>) • cw • missing • nofill • allcategories • percentages twoway mband mpg weight || scatter mpg weight
sort • cmissing(yes | no) • vertical, • horizontal plot median of the y values
stack • bargap(#) • intensity(*#) • yalternate • xalternate base(#)
bands(#)
graph dot (mean) length headroom, over(foreign) m(1, ms(S))
dot plot (asis) • (percent) • (count) • (stat: mean median sum min max ...) twoway bar price rep78
over(<variable>, <options: gap(*#) • relabel • descending • reverse binscatter weight mpg, line(none) ssc install binscatter
sort(<variable>)>) • cw • missing • nofill • allcategories • percentages bar plot plot a single value (mean or median) for each x value
linegap(#) • marker(#, <options>) • linetype(dot | line | rectangle) vertical, • horizontal • base(#) • barwidth(#)
dots(<options>) • lines(<options>) • rectangles(<options>) • rwidth medians • nquantiles(#) • discrete • controls(<variables>) •
linetype(lfit | qfit | connect | none) • aweight[<variable>]
graph hbox mpg, over(rep78, descending) by(foreign) missing
box plot graph box draws vertical boxplots twoway dot mpg rep78 FITTING RESULTS
over(<variable>, <options: total • gap(*#) • relabel • descending • reverse dot plot vertical, • horizontal • base(#) • ndots(#) twoway lfitci mpg weight || scatter mpg weight
sort(<variable>)>) • missing • allcategories • intensity(*#) • boxgap(#) dcolor(<color>) • dfcolor(<color>) • dlcolor(<color>)
medtype(line | line | marker) • medline(<options>) • medmarker(<options>) calculate and plot linear fit to data with confidence intervals
dsize(<markersize>) • dsymbol(<marker type>) level(#) • stdp • stdf • nofit • fitplot(<plottype>) • ciplot(<plottype>) •
vioplot price, over(foreign) ssc install vioplot dlwidth(<strokesize>) • dotextend(yes | no) range(# #) • n(#) • atobs • estopts(<options>) • predopts(<options>)
violin plot over(<variable>, <options: total • missing>)>) • nofill •
vertical • horizontal • obs • kernel(<options>) • bwidth(#) •
twoway dropline mpg price in 1/5 twoway lowess mpg weight || scatter mpg weight
barwidth(#) • dscale(#) • ygap(#) • ogap(#) • density(<options>) calculate and plot lowess smoothing
bar(<options>) • median(<options>) • obsopts(<options>) dropped line plot
vertical, • horizontal • base(#) bwidth(#) • mean • noweight • logit • adjust

Plot Placement twoway qfitci mpg weight, alwidth(none) || scatter mpg weight
JUXTAPOSE (FACET) twoway rcapsym length headroom price calculate and plot quadriatic fit to data with confidence intervals
twoway scatter mpg price, by(foreign, norescale) range plot (y1 ÷ y2) with capped lines level(#) • stdp • stdf • nofit • fitplot(<plottype>) • ciplot(<plottype>) •
range(# #) • n(#) • atobs • estopts(<options>) • predopts(<options>)
total • missing • colfirst • rows(#) • cols(#) • holes(<numlist>) vertical • horizontal see also rcap
compact • [no]edgelabel • [no]rescale • [no]yrescal • [no]xrescale
[no]iyaxes • [no]ixaxes • [no]iytick • [no]ixtick [no]iylabel
REGRESSION RESULTS
[no]ixlabel • [no]iytitle • [no]ixtitle • imargin(<options>) regress price mpg headroom trunk length turn
SUPERIMPOSE twoway rarea length headroom price, sort coefplot, drop(_cons) xline(0) ssc install coefplot
range plot (y1 ÷ y2) with area shading Plot regression coefficients
graph combine plot1.gph plot2.gph... vertical • horizontal • sort baselevels • b(<options>) • at(<options>) • noci • levels(#)
combine 2+ saved graphs into a single plot cmissing(yes | no) keep(<variables>) • drop(<variables>) • rename(<list>)
horizontal • vertical • generate(<variable>)
scatter y3 y2 y1 x, marker(i o i) mlabel(var3 var2 var1) regress mpg weight length turn
plot several y values for a single x value margins, eyex(weight) at(weight = (1800(200)4800))
twoway rbar length headroom price
graph twoway scatter mpg price in 27/74 || scatter mpg price /* range plot (y1 ÷ y2) with bars marginsplot, noci
*/ if mpg < 15 & price > 12000 in 27/74, mlabel(make) m(i) vertical • horizontal • barwidth(#) • mwidth Plot marginal effects of regression
combine twoway plots using || msize(<marker size>) horizontal • noci

Laura Hughes ([email protected]) • Tim Essam ([email protected]) inspired by RStudio’s awesome Cheat Sheets (rstudio.com/resources/cheatsheets) geocenter.github.io/StataTraining updated February 2016
follow us @flaneuseks and @StataRGIS Disclaimer: we are not affiliated with Stata. But we like it. CC BY 4.0

You might also like