Home

Products

  • Overview of Stata
  • Why buy Stata?
  • Stata Journal
  • Stat/Transfer
  • Prices

    Australia

  • New purchases
  • Upgrade
  • Bookshop
  • GradPlan


  • New Zealand

  • New purchases
  • Upgrade
  • Bookshop
  • GradPlan
  • Support

  • Starting Stata
  • Stata tips
  • Technical
  • Stata Courses & Training


  • Order form

    Contact us

    User written Stata graph commands

    Below are some of the many user written graph that can be produced in Stata.
    Other user written graph sites can be found at:
    http://www.ats.ucla.edu/stat/stata/faq/graph/atsplot.htm
    http://www.ats.ucla.edu/stat/stata/faq/graph/njcplot.htm

    Interesting use of Stata Graphs.



    
    
    
    
    violin plot
    Requires: vioplot To download vioplot type the following on the Stata command line: ssc install vioplot
    To run the example: copy the following into a do file and run sysuse auto, clear vioplot mpg, over(rep78) horizontal name(myplot) /// title("Violin Plot of Mileage") subtitle("By repair record") /// ytitle(Repair Record) ylab(, angle(horiz)) scheme(s2mono)
     
    

    sequence plot

    Requires: sq
    To download sq type the following on the Stata command line:
    ssc install sq

    To run the example: copy the following into a do file and run

    use http://www.wzb.eu/~kohler/ado/youthemp.dta, clear
    reshape long st, i(id) j(order)
    sqset st id order
    sqindexplot, scheme(vg_palec)



    asciiplot

    Requires: asciiplot
    To download asciiplot type the following on the Stata command line:
    ssc install asciiplot

    To run the example: copy the following into a do file and run

    asciiplot


    strippplot

    Requires: stripplot
    To download stripplot type the following on the Stata command line:
    ssc install stripplot

    To run the example: copy the following into a do file and run

    sysuse census, clear

    local abbrev ///
    AK AL AR AZ CA CO CT DE FL GA HI IA ///
    ID IL IN KS KY LA MA MD ME MI MN MO ///
    MS MT NC ND NE NH NJ NM NV NY OH OK ///
    OR PA RI SC SD TN TX UT VA VT WA WI WV WY
    gen abbrev = ""
    tokenize "`abbrev'"
    qui forval i = 1/50 {
    replace abbrev = "``i''" in `i'
    }
    set scheme s1color

    stripplot medage, stack ms(Sh) msize(*3.5) width(0.5) ///
    mla(abbrev) mlabpos(0) mlabsize(*.9) ysc(off) plotregion(lstyle(none))


    Venn diagram


    Requires: venndiag
    To download venndiag type the following on the Stata command line:
    ssc install venndiag

    To run the example below copy the following into a do file and run

    clear
    input hayfever eczema asthma freq
    1 0 0 31088
    1 1 0 9863
    0 1 0 43522
    0 1 1 9258
    0 0 1 35299
    1 0 1 11024
    1 1 1 6200
    0 0 0 345262
    end
    list
    expand freq
    venndiag asthma eczema hayfever


    triplot

    Plots 3 variables (proportions or percentages) the total of each to equal either 1 or 100

    Requires: triplot
    to download venndiag type the following on the Stata command line:
    ssc install triplot

    To run the example below copy the following into a do file and run

    clear
    input a1 a2 a3 str10 name
    20 20 80 John
    80 10 10 Fred
    25 25 50 Jane
    90 5 5 Helen
    0 0 100 Ed
    50 25 25 Kate
    20 60 20 Michael
    25 25 50 Darren
    5 90 5 Samar
    end
    list

    triplot a1 a2 a3 , mlab(name) mlabcolor(black) mcolor(blue) ///
    mlabsize(*0.9) max(100) title("Opinion a1 a2 a3")



    catplot


    Plots categorical variables

    Requires: catplot
    Plot categorical variables
    To download catplot type the following on the Stata command line:
    ssc install catplot

    To run the example below copy the following into a do file and run

    sysuse auto, clear

    catplot bar rep78, by(foreign) percent(foreign)



    tabplot


    Plots categorical variables in the from of a table


    Requires: tabplot
    to download catplot type the following on the Stata command line:
    ssc install tabplot

    To run the example below copy the following into a do file and run

    sysuse auto, clear

    tabplot for rep78, percent(foreign) showval(offset(0.05) format(%2.1f))



    spine

    Plots width proportional to frequency

    Requires: spineplot
    to download spineplot type the following on the Stata command line:
    ssc install spineplot

    To run the example below copy the following into a do file and run

    sysuse auto, clear
    spineplot foreign rep78, xti(frequency, axis(1)) ///
    xla(0(10)60, axis(1)) xmti(1/69, axis(1))




    cycleplot

    Plots the values for each period vertically

    Requires: cycleplot
    to download cycleplot type the following on the Stata command line:
    ssc install cycleplot

    For the example below get the data (Co2 data) from: http://cdiac.ornl.gov/ftp/ndp001/maunaloa.co2

    To run the example below copy the following into a do file and run

    mvdecode m1-m12 , mv(-99.99=.)
    reshape long m, i(year) j(month)
    cycleplot m month year, mylabels(`c(Months)') xlabel(, angle(45))




    sliceplot

    Spreads out the graph over a number of rows; to aid reading the graph

    Requires: sliceplot
    to download sliceplot type the following on the Stata command line:
    ssc install sliceplot

    For the example below get the data (Co2 data) from: http://cdiac.ornl.gov/ftp/ndp001/maunaloa.co2

    To run the example: copy the following into a do file and run

    mvdecode m1-m12 , mv(-99.99=.)
    reshape long m, i(year) j(month)
    sliceplot line month year, slices(4)




    cpyxplot

    Plots the cross product of the variables indicted in command


    Requires: cpyxplot
    to download cpyxplot type the following on the Stata command line:
    ssc install cpyxplot

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    cpyxplot for \rep78 mpg turn length, graphregion(color(ltblue))




    beamplot

    The seasaw way of looking at the data

    Requires: beamplot
    to download beamplot type the following on the Stata command line:
    ssc install beamplot

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    beamplot mpg, by(foreign) over(rep78)




    surface

    3d plot

    Requires: surface
    to download surfacet type the following on the Stata command line:
    ssc install surface

    To run the example: copy the following into a do file and run

    use surf3,clear
    set more off
    surface x y z, orient(xzy) saving(s3d)




    hangroot

    Distribution checking graph

    Requires: hangroot
    to download hangroot type the following on the Stata command line:
    ssc install hangroot

    To run the example: copy the following into a do file and run

    sysuse nlsw88, clear
    gen ln_w = ln(wage)
    reg ln_w grade age ttl_exp tenure
    predict resid, resid
    hangroot resid, bar




    byhist

    Draws a binary variable next to each other for each bin width

    Requires: byhist
    to download byhist type the following on the Stata command line:
    ssc install byhist

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    byhist mpg, by(foreign)




    bihist

    Draws a binary variable; one going up and the other going down, for each bin width

    Requires: byhist
    to download bihist type the following on the Stata command line:
    ssc install bihist

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    byhist mpg, by(foreign)




    plotmatrix

    Display the values of a matrix using twoway area

    Requires: plotmatrix
    to download plotmatrix type the following on the Stata command line:
    ssc install plotmatrix

    To run the example: copy the following into a do file and run

    sysuse auto
    reg price mpg trunk weight length turn, nocons
    mat regmat = e(V)
    plotmatrix, m(regmat) c(red) ylabel(,angle(0))




    full_palette

    Displays a palette of Stata's graph colors, along with their names and RGB numbers

    Requires: full_palette
    to download full_palette type the following on the Stata command line:
    ssc install full_palette

    To run the example: copy the following into a do file and run

    full_palette




    parea

    (Windows only) Allows the use of patterns to fill in areas under graphs

    Requires: parea
    to download parea type the following on the Stata command line:
    ssc install parea

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    twoway parea d w, sort pattern(pattern9) || ///
    parea l w if w<=3600, sort pattern(pattern6) || ///
    parea l w if w>=3600, sort pattern(pattern4) ,legend(rows(1))





    spkde

    Requires: spgrid, spkde & spmap
    to download these programs type the following on the Stata command line (if not already loaded):
    ssc install spgrid
    and then
    ssc install spkde
    and then
    ssc install spmap

    Also remember to download the following dataset:
    Italy-OutlineCoordinates.dta
    (from where spmap is downloaded) or use the following
    net get spmap.pkg


    Italy-DataPoints.dta
    (from where spkde is downloaded) or use the following
    net get spkde.pkg


    To run the example: copy the following into a do file and run

    set more off

    spgrid using "Italy-OutlineCoordinates.dta", ///
    resolution(w10) unit(kilometers) ///
    cells("GridCells.dta") ///
    points("GridPoints.dta") ///
    replace compress dots

    use "Italy-DataPoints.dta", clear

    spkde dcvd95 pop95 using "GridPoints.dta", ///
    xcoord(xcoord) ycoord(ycoord) ///
    bandwidth(fbw) fbw(100) dots ///
    saving("Kde.dta", replace)

    use "Kde.dta", clear

    generate ratio = dcvd95_lambda / pop95_lambda * 1000

    spmap ratio using "GridCells.dta", ///
    id(spgrid_id) clnum(20) ///
    fcolor(Rainbow) ocolor(none ..) ///
    legend(off)




    
    Density Plot
    
    
    Requires: spgrid, spkde, spmap & mylabels 
    to download these programs type the following 
    on the Stata command line (if not already loaded):
    
    ssc install spgrid
    and then
    ssc install spkde
    and then
    ssc install spmap
    and then
    ssc install mylabels
    
    *------------------------------------------------
    
    
    * 1. Normalize variables in the range [0,1]	
    
    sysuse "auto.dta", clear
    set more off
    
    summarize price mpg
    clonevar x = mpg
    clonevar y = price
    replace x = (x-0) / (50-0)
    replace y = (y-0) / (20000-0)
    mylabels 0(10)50, myscale((@-0) / (50-0)) local(XLAB)
    mylabels 0(5000)20000, myscale((@-0) / (20000-0)) local(YLAB)
    
    keep x y
    save "xy.dta", replace
    
    * 2. Generate a 100x100 grid
    
    spgrid, shape(hexagonal) xdim(100) ///
    xrange(0 1) yrange(0 1)               ///
    dots replace                          ///
    cells("2D-GridCells.dta")             ///
    points("2D-GridPoints.dta")
    
    * 3. Estimate the bivariate probability density function
    
    spkde using "2D-GridPoints.dta", ///
    xcoord(x) ycoord(y)                 ///
    bandwidth(fbw) fbw(0.1) dots        ///
    saving("2D-Kde.dta", replace)
    
    * 4. Draw the density plot
    
    use "2D-Kde.dta", clear
    recode lambda (.=0)
    spmap lambda using "2D-GridCells.dta",  ///
    id(spgrid_id) clnum(20) fcolor(Rainbow) ///
    ocolor(none ..) legend(off)             ///
    point(data("xy.dta") x(x) y(y))         ///
    freestyle aspectratio(1)                ///
    xtitle(" " "Mileage (mpg)")             ///
    xlab( `XLAB')                           ///
    ytitle(" " "Price ({c S|}US)")          ///
    ylab(`YLAB', angle(0))
    
    exit
    
    		 
    

    eclplot
    Plot estimates with confidence limits
    Requires: eclplot, parmby & sencode
    to download these programs type the following on the Stata command line (if not already loaded):
    ssc install eclplot
    and then
    ssc install parmby
    and then
    ssc install sencode

    To run the example: copy the following into a do file and run

    sysuse auto, clear

    tabulate rep78, gene(rep78_)

    parmby "regress mpg rep78_*, noconst", by(foreign) label norestore

    sencode label if parm!="_cons", gene(parmlab)
    label var parmlab "Repair record 1978"

    label var estimate "Mean mileage (mpg)"
    eclplot estimate min95 max95 parmlab, eplot(bar) estopts(barwidth(0.25)) ///
    supby(foreign, ///
    spaceby(0.25)) xscale(range(0 6)) xlabel(1(1)5, angle(30))





    Radar Plot

    Requires: radar
    to download this program type the following on the Stata command line (if not already loaded):
    ssc install radar

    To run the example: copy the following into a do file and run

    sysuse auto, clear

    radar make turn mpg trunk if foreign, title(Nice Radar graph) ///
    lc(red blue green) lw(*1 *2 *4) r(0 12 14 18 50)




    Batplot
    Produces a Bland-Altman plot when there is a relationship between paired differences and their average

    Requires: batplot
    to download this program type the following on the Stata command line (if not already loaded):
    ssc install batplot

    To run the example: copy the following into a do file and run

    sysuse auto, clear

    batplot mpg turn, title(Agreement between mpg and turn) ///
    info valabel(make) notrend xlab(26(4)38) moptions(mlabp(9))




    Chernoff faces

    Requires: chernoff
    to download this program type the following on the Stata command line (if not already loaded):
    net install gr0038

    To run the example: copy the following into a do file and run

    sysuse auto, clear
    drop if rep78==.

    keep in 41/55

    chernoff, isize(rep78) hdark(mpg) hslant(mpg) fline(weight) ///
    order(foreign price) saving(c:/face1)

    chernoff, isize(rep78,0) hdark(mpg) hslant(mpg) fline(weight) ///
    nose(price) legend(2 nolabel) cols(3) rhalf saving(c:/face2)

    generate s = 1+runiform()

    chernoff, isize(rep78,. 6) hdark(mpg) hslant(mpg) fline(weight) ///
    bvert(_null_) inote(make) iscale(s) saving(mygraph, replace)





    Trellis plot

    Requires: trellis
    to download this program type the following on the Stata command line (if not already loaded):
    ssc install trellis

    To run the example: copy the following into a do file and run

    webuse nhanes2f, clear

    trellis,by(health region) f(graph box copper zinc iron) fopt(legend(off) ///
    ylab(50 175 300) yscale(r(50,310))) sr(2) sc(2) ///
    singleopt(legend(on ring(0) pos(1) col(1) bm(tiny) ///
    symx(*0.2) keyg(*0.2) region(m(zero) lw(none))) ///
    yscale(r(50,310))) name(trellis)





    grcomb
    Combines graphs

    Requires: grcomb
    to download this program type the following on the Stata command line (if not already loaded):
    ssc install grcomb

    To run the example: copy the following into a do file and run

    webuse nhanes2f, clear

    grcomb graph box copper zinc iron , v(1)





    pieplot
    Makes it easier to draw pie charts of categorical frequencies

    Requires: plieplot
    to download this program type the following on the Stata command line (if not already loaded):
    ssc install pieplot

    To run the example: copy the following into a do file and run

    sysuse auto, clear

    pieplot rep78 foreign, sum plabelsubopts(size(*2)) ///
    pie(1, color(red*2)) pie(2, color(red)) ///
    pie(3, color(red*0.7)) pie(4, color(red*0.5)) ///
    pie(5, color(red*0.3)) legend(row(1)) name(pieplot)





    
    
    sixplot
    Displays six diagnostic and descriptive graphs for a single variable Requires: sixplot to download this program type the following on the Stata command line (if not already loaded): ssc install sixplot To run the example: copy the following into a do file and run sysuse uslifeexp.dta
    sixplot le_male
    
    
    zmap
    zmap graphs (or maps) binned values of a variable z with respect to two variables x and y treated as Cartesian coordinates. Requires: zmap to download this program type the following on the Stata command line (if not already loaded): ssc install zmap To run the example: copy the following into a do file and run
    webuse nlswork, clear egen mean = mean(ln_wage), by(age grade) egen tag = tag(age grade) label variable mean "mean ln wage" summarize ln_wage if !missing(age, grade), detail zmap mean age grade if tag, breaks(.993 1.166 1.361 1.641 /// 1.964 2.275 2.456) ms(S ..) ysc(on) xsc(on) yla(0/18, ang(h)) /// ytitle(`: var label grade') mxla(15(5)45) note("") /// color(blue blue*0.5 orange*0.5 orange)
    
    
    netplot
    An important part of what makes social network analysis so fascinating to broad audiences is the possibility of visualization of networks. netplot produces a network plot Requires: netplot to download this program type the following on the Stata command line (if not already loaded): ssc install netplot To run the example: copy the following into a do file and run //create a random network with 10 nodes //(code adopted from the helpfile of stata2pajek) clear set obs 200 gen i=int(uniform()*10)+1 gen j=int(uniform()*10)+1 contract i j, freq(strength) drop if i==j sort i j drop if strength <3 // --> keep only the "stronger" links // Draw the network netplot i j, type(circle) label
    
    
    
    cmogram
    cmogram graphs the means, medians, frequencies, or proportions 
    of yvar, conditional on xvar.
    
    Requires: cmogram
    to download this program type the following on the Stata command 
    line (if not already loaded):
    ssc install cmogram
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
    
    cmogram mpg weight, histopts(bin(5)) lfit cutpoint(3250) ///
    lineat(3000 3250 3500) controls(price)
    
    
    
    
    
    
    
    ellip
    ellip calculates a confidence ellipse from the elliptically 
    distributed variables yvar and xvar, and then graphs the 
    confidence ellipse using graph twoway line.
    
    
    Requires: ellip
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install ellip
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
    
    
    ellip mpg weight, by(foreign, total legend(off)) ///
    total tlabel(Total as a by-group) plot(scatter mpg weight)
    
    
    
    
    
    
    
    
    drarea
    Multiple graphics are produced in Stata by the rule "last drawn
    first seen". So the objects that are drawn last are the ones
    that are observed. The implication of this principle is that
    when overlapping two rarea graphs the overlapping area is hidden
    by the second rarea graph.  This command drarea overlays two
    range area plots by merging the two colours and hence highlighting
    the true overlap.
    
    Requires: drarea
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install drarea
    
    To run the example: copy the following into a do file and run
    
    
    
    sysuse sp500, clear
    
    generate high2 = high+15*uniform()
    
    generate low2 = low+15*uniform()
    
    drarea high low high2 low2 date in 1/20
    
    
    
    
    
    
    
    
    linkplot
    linkplot plots yvarlist versus xvar such that data points are 
    linked (i.e. connected) within groups defined by distinct values of
    linkvar. For example, with paired data it might be desired to 
    link each pair, or with panel data it might be desired to link
    observations within each panel.
    
    Requires: linkplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install linkplot
    
    To run the example: copy the following into a do file and run
    
    
    
    clear
    input ///
           A          B         id
          13.2       14.0          1
           8.2        8.8          2
          10.9       11.2          3
          14.3       14.2          4
          10.7       11.8          5
           6.6        6.4          6
           9.5        9.8          7
          10.8       11.3          8
           8.8        9.3          9
          13.3       13.6         10
    end
    
    rename A wearA
    rename B wearB
    reshape long wear, string i(id) j(j)
    encode j, gen(material)
    
    linkplot material wear, link(id) yla(1 2, valuelabel) ///
    ysc(r(0.5 2.5)) yla(, ang(h))