KEMBAR78
StataCheatSheet Analysis | PDF | Histogram | Scatter Plot
0% found this document useful (0 votes)
124 views1 page

StataCheatSheet Analysis

This document provides a cheat sheet for creating various types of plots and graphs using Stata software. It outlines the basic syntax for plots, including options for titles, axes, appearance, sizing, and saving plots. Various plot types are described for one variable (e.g. histograms), two or more continuous variables (e.g. scatter plots), three variables (e.g. contour plots), discrete x and continuous y variables (e.g. bar plots), and summary plots. Additional details on specific plot options are available in Stata's reference manual.

Uploaded by

sgoranks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
124 views1 page

StataCheatSheet Analysis

This document provides a cheat sheet for creating various types of plots and graphs using Stata software. It outlines the basic syntax for plots, including options for titles, axes, appearance, sizing, and saving plots. Various plot types are described for one variable (e.g. histograms), two or more continuous variables (e.g. scatter plots), three variables (e.g. contour plots), discrete x and continuous y variables (e.g. bar plots), and summary plots. Additional details on specific plot options are available in Stata's reference manual.

Uploaded by

sgoranks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
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 y2 scatter plot of each combination of variables Parallel coordinates plot (sysuse nlswide1)
kdenopts(<options>) half • jitter(#) • jitterseed(#) vertical, • horizontal
y3 diagonal • [aweights(<variable>)]
kdensity mpg, bwidth(3)
smoothed histogram twoway pccapsym wage68 ttl_exp68 wage88 ttl_exp88
bwidth • kernel(<options> main plot-specific options; twoway scatter mpg weight, jitter(7) Slope/bump plot (sysuse nlswide1)
normal • normopts(<line options>) see help for complete set scatter plot vertical • horizontal • headlabel
jitter(#) • jitterseed(#) • sort • cmissing(yes | no)
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 23 twoway scatter mpg weight, mlabel(mpg)
(asis) • (percent) • (count) • over(<variable>, <options: gap(*#) •
twoway contour mpg price weight, level(20) crule(intensity)
20 scatter plot with labelled values 3D contour plot
relabel • descending • reverse>) • cw •missing • nofill • allcategories • 17 jitter(#) • jitterseed(#) • sort • cmissing(yes | no)
percentages • stack • bargap(#) • intensity(*#) • yalternate • xalternate ccuts(#s) • levels(#) • minmax • crule(hue | chue| intensity) •
2 10 connect(<options>) • [aweight(<variable>)] scolor(<color>) • ecolor (<color>) • ccolors(<colorlist>) • heatmap
graph bar (percent), over(rep78) over(foreign) interp(thinplatespline | shepard | none)
grouped bar plot graph hbar ... regress price mpg trunk weight length turn, nocons
(asis) • (percent) • (count) • over(<variable>, <options: gap(*#) • twoway connected mpg price, sort(price)
relabel • descending • reverse>) • cw •missing • nofill • allcategories • scatter plot with connected lines and symbols matrix regmat = e(V) ssc install plotmatrix
a b c percentages • stack • bargap(#) • intensity(*#) • yalternate • xalternate jitter(#) • jitterseed(#) • sort see also line plotmatrix, mat(regmat) color(green)
connect(<options>) • cmissing(yes | no) heatmap mat(<variable) • split(<options>) • color(<color>) • freq
DISCRETE X, CONTINUOUS Y
graph bar (median) price, over(foreign) graph hbar ...
twoway area mpg price, sort(price)
SUMMARY PLOTS
bar plot (asis) • (percent) • (count) • (stat: mean median sum min max ...) twoway mband mpg weight || scatter mpg weight
over(<variable>, <options: gap(*#) • relabel • descending • reverse line plot with area shading
sort(<variable>)>) • cw • missing • nofill • allcategories • percentages 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 binscatter weight mpg, line(none) ssc install binscatter
over(<variable>, <options: gap(*#) • relabel • descending • reverse
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(#) medians • nquantiles(#) • discrete • controls(<variables>) •
dots(<options>) • lines(<options>) • rectangles(<options>) • rwidth linetype(lfit | qfit | connect | none) • aweight[<variable>]
graph hbox mpg, over(rep78, descending) by(foreign) missing FITTING RESULTS
box plot graph box draws vertical boxplots twoway dot mpg rep78
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>) calculate and plot linear fit to data with confidence intervals
medtype(line | line | marker) • medline(<options>) • medmarker(<options>) 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 lowess mpg weight || scatter mpg weight
barwidth(#) • dscale(#) • ygap(#) • ogap(#) • density(<options>) twoway dropline mpg price in 1/5 calculate and plot lowess smoothing
bar(<options>) • median(<options>) • obsopts(<options>) dropped line plot bwidth(#) • mean • noweight • logit • adjust
vertical, • horizontal • base(#)
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
level(#) • stdp • stdf • nofit • fitplot(<plottype>) • ciplot(<plottype>) •
twoway scatter mpg price, by(foreign, norescale) range plot (y1 ÷ y2) with capped lines 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 REGRESSION RESULTS
[no]iyaxes • [no]ixaxes • [no]iytick • [no]ixtick [no]iylabel
[no]ixlabel • [no]iytitle • [no]ixtitle • imargin(<options>) regress price mpg headroom trunk length turn
coefplot, drop(_cons) xline(0) ssc install coefplot
SUPERIMPOSE twoway rarea length headroom price, sort
Plot regression coefficients
range plot (y1 ÷ y2) with area shading
graph combine plot1.gph plot2.gph... vertical • horizontal • sort
baselevels • b(<options>) • at(<options>) • noci • levels(#)
combine 2+ saved graphs into a single plot keep(<variables>) • drop(<variables>) • rename(<list>)
cmissing(yes | no) 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 twoway rbar length headroom price margins, eyex(weight) at(weight = (1800(200)4800))
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 (lhughes@usaid.gov) • Tim Essam (tessam@usaid.gov) inspired by RStudio’s awesome Cheat Sheets (rstudio.com/resources/cheatsheets) geocenter.github.io/StataTraining updated January 2016
Disclaimer: we are not affiliated with Stata. But we like it. CC BY NC

You might also like