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 - General
  • Stata tips - Graphs
  • Stata tips - Tables
  • 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/njcplot.htm

    Dispay of official Stata graphs:
    http://www.ats.ucla.edu/stat/stata/faq/graph/atsplot.htm
    http://www.stata.com/support/faqs/graphics/gph/statagraphs.html

    Also see:
    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))

    strippplot
    Another example of the use of striplot. 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 auto, clear gen pipe = "|" stripplot price, over(rep78) box(barw(0.3)) ms(none) mla(pipe) boffset(0.3) From the Statalist: Nick cox 15/10/2010
    
    
    strippplot
    Another example of the use of striplot. 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 auto, clear gen pipe = "|" stripplot mpg, ms(none) mlabpos(0) mlabel(pipe) mlabsize(*2) stack From striplot help: Nick cox
    
    
    strippplot
    Another example of the use of striplot. 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 auto, clear stripplot mpg, over(rep78) stack h(0.5) bar(lcolor(red)) From striplot help: Nick cox
    
    
    strippplot
    Another example of the use of striplot. Requires: stripplot To download stripplot type the following on the Stata command line: ssc install stripplot The data (Challenger shuttle O-ring damage) can be obtained from: http://www.stata.com/bookstore/swsdl.html To run the example: copy the following into a do file and run
    use shuttle.dta, clear logit damage temp predict pre stripplot pre, over(temp) stack ms(sh) height(0.4) /// title("Challenger shuttle O-ring damage") ylabel(,alt labsize(2)) /// addplot(mspline temp pre, bands(20)) From striplot help: Nick cox
    
    
    strippplot
    Another example of the use of striplot. 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 bplong, clear egen group = group(age sex), label stripplot bp*, bar over(when) by(group, compact col(1) note("")) /// ysc(reverse) subtitle(, pos(9) ring(1) nobexpand bcolor(none) /// placement(e)) ytitle("") xtitle(Blood pressure (mm Hg)) From striplot help: Nick cox
    
    

    Venn diagram using venndiag


    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

    Venn diagram - using pvenn


    Requires: pvenn
    To download pvenn type the following on the Stata command line:
    ssc install pvenn
    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 pvenn 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)


    
    
     catplot
    Plots categorical variables -  
    
    
    Requires: catplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install catplot
    
    To run the example: copy the following into a do file and run
    
    
    
     sysuse auto, clear
     
    catplot  rep78, over(for) stack asyvars  perc(for)	///
    blabel(bar, position(center) format(%3.1f)) ///
    legend(off)
    
    
    
    
    
     catplot
    Plots categorical variables -  
    
    
    Requires: catplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install catplot
    
    To run the example: copy the following into a do file and run
    
    
    
    clear	all
    set more off
    
    input quest str25 q      a1 a2 a3 a4 a5 a6
    1 "Question 1"           0  2  37 45 12 4
    1 "Benchmark Q1"         2  5  25 47 17 4
    2 "Question 2"           1  37  2 40 17 3
    2 "Benchmark Q2"         2  5  25 47  4 17
    3 "Question 3"           1  2  40 37 17 3
    3 "Benchmark Q3"         2  5  25 47 17 4
    4 "Question 4"           1  2  37  17 3 40
    4 "Benchmark Q4"         2  5  47 25 17 4
    end	
    
    sort quest q
    gen q_sum=_n
    
    label define kk 1 q1 2 b1 3 q2 4 b2 5 q3 6 b3 7 q4 8 b4 
    label value q_sum kk
    
    reshape long a, i(quest q) j(data)
    label var data "Question No."
    
    expand a 
    
    split q
    
    replace q2=substr(q2,2,1) if length(q2)>1
    
    catplot  data, over(q1, gap(40) label(labgap(5)))               ///
    over(q2 )  stack asyvars perc(q)	                            ///
    blabel(bar, size(1) position(center)orient(vert) format(%4.1f)) ///
    legend(                                                         ///
    label(1 "Missing")                                              ///
    label(2 "Never")                                                ///
    label(3 "Rarely")                                               ///
    label(4 "Occasionaly")                                          ///
    label(5 "Mostly")                                               ///
    label(6 "Always") rows(1) keygap(0) symxsize(7) bexpand         ///
    span size(small))                                               ///
    ytitle("Percentage")
    
    exit
    
    
    

    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))


    
    
    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 replace rep78=0 if missing(rep78) bysort foreign rep78 : gen N = _N bysort foreign : gen Na1 = (N/_N)*100 by foreign : gen N1 = string(Na1,"%5.2f") +"%" label define kk 0 "missing", label values rep78 kk spineplot rep78 foreign, bar1(bcolor(gs14)) /// percent missing /// bar2(bcolor(gs11)) /// bar3(bcolor(gs8)) /// bar4(bcolor(gs5)) /// bar5(bcolor(gs2)) /// bar6(bcolor(red)) text(N1)


    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))
    
    
    
    
    
    
    
    
    
    tddens
    Bivariate kernel density graphs over a grid
    
    Requires: tddens
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install tddens
    
    To run the example: copy the following into a do file and run
    
    
    
    sysuse auto, clear
    
    tddens price mpg, s b
    
    
    
    
    
    
    
    Lexis diagram
    Two dimensional diagram that is used to represent events 
    (such as births or deaths) that occur to individuals belonging 
    to different cohorts.
    
    Requires: evhistplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install evhistplot
    
    To run the example: copy the following into a do file and run
    
    
    
    clear
    webuse set ///
    "http://oldsite.soziologie-blossfeld.de/eha/stata/do_files/Data/"  
    
    webuse rrdat1.dta
    
    * Convert event times to dates. Are arbitrarily set to fifteenth 
    day of month. 
    
    foreach var of varlist tstart tb te tmar ti tfin {
      gen `var'date = mdy(mod(`var' - 1, 12) + 1, 15, (`var' - 1) / 12 + 1900)
      local labvar : variable label `var'
      la var `var'date "`labvar'"
      format %d `var'date
    }
    
    * replace with missing where observation is actually right censored
    replace tmardate = . if tmar == 0
    la var tmardate "Date of marriage"
    replace tfindate = . if tfin == ti
    
    
    * Lexis plot with date of marriage and job starts labelled
    * according to rank
    
    evhistplot tstartdate tmardate, id(id) start(1jan1940) ///
    end(31dec1981) birth(tbdate) evtype(noj) nsub(20) xtitle(Calendar time)
    
    
    
    
    
    
    
    
    Deviation plots
    Plots each data point relative to some appropriate mean with a marker 
    symbol and a spike connecting marker and mean.
    
    Requires: devnplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install devnplot
    
    To run the example: copy the following into a do file and run
    
    
    
    webuse systolic, clear
    
    version 9: anova systolic drug disease drug*disease
    predict predict
    predict residual, residual
    
    devnplot systolic drug disease, level(predict) superplines
    
    
    
    
    
    
    Statplot
    Statplot is an alternative to graph hplot, graph hbar and graph dot.
    It allows grouping on the axis and other options.  
    
    
    Requires: statplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install statplot
    
    To run the example: copy the following into a do file and run
    
    
    
    webuse systolic, clear
    
    sysuse census, clear
    statplot marriage divorce, over(region) s(sum) xpose varnames
    
    
    
    
    
    
    
     mm_plot
    mm_plot is a user written Mata graph command that allow you 
    to plot a Mata matrix.  
    
    
    Requires: moremata
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install moremata
    
    To run the example: copy the following into a do file and run
    
    
    
    set more off
    mata:
    
    for(i=0;i<=2*pi()*1000; i++) {
    
      a=(i/1000)*cos(i/1000)
      a1=(i/1000)*sin(i/1000)
    
    if(i==0) {
      za=a
      za1=a1
    }
    else {
      za=za\a
      za1=za1\a1
    }
      c=za,za1
    }
    
    mata: mm_plot(c)
    
    
    end
    
    
    
    
    
    
    
     cdfplot
    cdfplot plots the sample cumulative distribution function. 
    Distributions can be compared within subgroups defined by 
    a second variable. The best fitting normal (Gaussian) 
    model may be superimposed over the sample c.d.f.
    
    
    
    Requires: cdfplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install cdfplot
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto,replace
    cdfplot length [fw=rep78], by(foreign) norm saving(mygraph,replace)
    
    
    
    
    
     riskplot
    The riskplot is a graphical aid to the investigation
    of the contributions of risk factors on outcomes of interest.
    (see SJ Vol 10 No 1)
    
    
    Requires: riskplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install risk,all
    (The all option ensures that the data (data_riskplot.dta) 
    will also be downloaded)
    
    To run the example: copy the following into a do file and run
    
    
    use c:/data/data_riskplot.dta, clear  //path may need to be changed  
    set scheme sj
    
    riskplot depr1995 sex sclass if Idep91==1 [pw=wg], path obs        /* 
       */ thick(20) c(. red)  title(Risk plot for subjects with mild   /*
       */ or severe depression at baseline) subtitle((results using    /*
       */ sampling weights), margin(b+5)) scale(0.9) ytitle(depression /*
       */ score 1995) saving(riskplotWG, replace)
    
    
    
    
    
     aaplot
    aaplot graphs a scatter plot for yvar versus xvar with linear
    and/or quadratic fit superimposed.  The equation(s) and 
    R-square statistics of the fits shown are also shown at the
    top of the graph. 
    
    
    Requires: aaplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install aaplot
    
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
    gen gpm = 1000 / mpg
    label var gpm "Gallons per thousand miles"
    
    aaplot gpm weight, name(g1) 
    
    
    
    
    
     hull plot
    cvxplot makes a scatterplot and draw convex hulls of a group of
    points in two-dimensional space. Each hull is defined by two lines
    joining the bottom-left point to the top-right point.
    
    
    
    Requires: cvxplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install cvxhull
    
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
     
     gen foreign1=foreign
     label define for 1 For 0 Dom
     label values  foreign1 for
     
     cvxhull  mpg weight, group(foreign) hulls(2) ///
               scat(mlab(foreign1) mlabpos(c) msym(i) ysc(r(0,60)))
    
    
    
    
    
     Pareto plot
    pdplot produces a Pareto dot plot 
    
    
    
    Requires: pdplot
    to download this program type the following on the Stata command
    line (if not already loaded):
    ssc install pdplot
    
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
    pdplot mpg
    
    
    
    
     Centred bar plots
    Centred bar plots shows absolute or relative frequencies of 
    yvar as centred bar plots.
    
    Centred bar plots are often used in archaeology to show 
    frequencies of different kinds of artefact at different 
    levels or ages, sometimes under the title of battleship 
    curves or battleship diagrams. 
    
    
    Requires: cbarplot
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install cbarplot
    
    
    To run the example: copy the following into a do file and run
    
    
    clear
    input levels freqcores freqblanks freqtools
        25 21 32 70
        24 36 52 115
        23 126 650 549
        22 159 2342 1633
        21 75 487 511
        20 176 1090 912
        19 132 713 578
        18 46 374 266
        17 550 6182 1541
        16 76 846 349
        15 17 182 51
        14 4 51 14
        13 29 228 130
        12 135 2227 729
     end
    reshape long freq, i(levels) j(kind) string
     
    cbarplot levels kind [fw=freq], percent(levels) mlabsize(*.6)
    
    
    
    
    
     heatmap
    Graphs a heatmap.
    
    
    Requires: cbarplot
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install hmap
    
    
    To run the example: copy the following into a do file and run
    
    
       // producing the data
           clear all
           set obs 64
           generate n=int(uniform()*10)
           generate x=1+int((_n-1)/8)
           generate y=1+mod((_n-1),8)
           label define xlab 1 "one" 2 "two" 7 "seven" 8 "eight"
           label define ylab 3 "three" 4 "four" 5 "five" 6 "six"
           label value x xlab
           label value y ylab
           table y x [fw=n]
       
       hmap x y n
    
    
    
    
    
    simpplot
    // Plot describing p-values from a simulation by comparing 
    //nominal significance levels with the coverages
    
    
    
    
    Requires: simpplot
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install simpplot
    
    
    
    
    
    
    
    program drop _all
        program define sim, rclas
            drop _all
            set obs 500
            gen x = rchi2(2)
            
            ttest x=2 in 1/50
            return scalar p50 = r(p)
            
            ttest x=2 
            return scalar p500 = r(p)
        end
    
        set seed 12345
        simulate p50=r(p50) p500=r(p500), ///
                 reps(5000) : sim 
    
        label var p50 "N=50"
        label var p500 "N=500"
            
        simpplot p50 p500, main1opt(mcolor(red)) ///
                           main2opt(mcolor(blue))
    
    
    
    
    
    Fractal
    // Generates fractals 
    
    
    Requires: fractal
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install fractal
    
    
    
    
    clear
    
    fractal  ,hs(0,.2,.3,.40,.5,.618,.75,.85,1.0)   ///
    vs(0,.25,.2,.35,.25,.516,.366,.42,.2) hr(0 100) ///
    vr(0 200) iter(3) savegraph
    
    graph combine _frctl1.gph _frctl2.gph _frctl3.gph 
    
    
    
    
    
    Motion Chart
    A "Motion Chart" is a scatter plot for time-series data.  
    You can hit "play" and see how the points move over time.  
    They were made famous, for example, by Hans Rosling's 
    internet videos: http://www.gapminder.org/
    
    "Example of motion graph for code below"
    
    Requires: motionchart
    to download this program:
    Open Stata viewer
    type the following in:
    net describe motionchart, from(http://kk-adofiles.googlecode.com/hg)
    
    type help motionchart
    
    Read the pharagraph on setting the Adobe Flash Player
    
    
    sysuse bplong.dta , clear
    generate year = 2007+when
    decode sex , gen(gender)
    
    motionchart patient year bp sex using "my_test.html" in 115/125 ,   ///
    replace title("Blood Pressure")                                     ///
    subtitle("Example motionchart: created in Stata with motionchart.ado")
    
    
    
    
    
    
    binscatter
    binscatter generates binned scatterplots, and is optimized for 
    speed in large datasets.
    
    Binned scatterplots provide a non-parametric way of visualizing the 
    relationship between two variables. With a large number of observations, 
    a scatterplot that plots every data point would become too crowded to 
    interpret visually.  binscatter groups the x-axis variable into 
    equal-sized bins, computes the mean of the x-axis and y-axis variables 
    within each bin, then creates a scatterplot of these data points.
    
    Requires: binscatter 
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install binscatter
    
    
    clear all
    
    sysuse nlsw88, clear
    
    keep if inrange(age,35,44) & inrange(race,1,2)
    
    scatter wage tenure ,  title("Graph produced by Scatter") name(g1)
            
    // The scatter was too crowded to be easily interpetable. The binscatter
       is cleaner, try a quadratic fit.
    
    binscatter wage tenure, line(qfit) xscale(range(0,25)) ///
    xlabel(0(5)25) ylabel(0(10)40) yscale(range(0,40))     ///
    title("Graph produced by Binscatter") name(g2)
    
    graph combine g1 g2 
    
    
    
    
    
    missingplot
    // Generates a graph of missing values 
    
    
    Requires: missingplot
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install missingplot
    
    
    webuse nlsw88, clear
    missingplot, var labels mlabcolor(blue ..)
    
    
    
    
    sparkline
    // sparkline graphs sparkline-type plots for one or more y
    // variables against a single x variable. Typically, plots for
    // different y variables or for different subsets of one y variable
    // are stacked vertically into one image. 
    
    Requires: sparkline
    to download this program type the following on the Stata
    command line (if not already loaded):
    ssc install sparkline
    
    
    webuse grunfeld, clear 
    
    sparkline invest year, by(company) extremes
    
    
    
    
    
    
    




    Programs that help produce Stata graphs:
    
     Program that helps with specification of regular linear and logarithmic 
    axis scales, ranges and tick lists 
    
    Requires: regaxis
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc install regaxis
    
    To run the example: copy the following into a do file and run
    
    
    sysuse auto, clear
    regaxis rep78, cycle(.5) singleok margin(0.5) lrange(yrange) lticks(ylabs)
    regaxis weight, include(0) lticks(xlabs)
    scatter rep78 weight, yscale(range(`yrange')) ylabel(`ylabs') xlabel(`xlabs')
    
    
    
    
    
     Program that helps with specification of label positions
    
    Requires: egenmore
    to download this program type the following on the Stata 
    command line (if not already loaded):
    ssc egenmore
    
    To run the example: copy the following into a do file and run
    
    
    clear all
    
    //graph without the egenmore generated label position
    sysuse auto, clear
    egen clock = mlabvpos(mpg weight)
    scatter mpg weight, mlab(make) mlabvpos(clock) name(a1) ///
    scheme(s1)
    
    	
    // look at a suitable matrix
    // for the egen mlabvpos option
    matrix z= 11, 1, 12, 11, 1 \ 10, 2, 12, 10, 2 \ 9, 3, 12, 9 ,3 \ ///
    8, 4, 6, 8, 4 \ 7, 5 ,6, 7, 5	
    
    matrix list z
    
    
    //graph with the egenmore generated label position
    egen clock2 = mlabvpos(mpg weight), matrix(11 1 12 11 1 \\ ///
    10 2 12 10 2 \\ 9 3 12 9 3 \\ 8 4 6 8 4 \\ 7 5 6 7 5)
    
    scatter mpg weight, mlab(make) mlabvpos(clock2) name(a2) ///
    title("Graph using egenmore mlabvpos generated data")    ///
    scheme(s1)
    
    
    
    



    An Excellent book on Stata graphs is: