Last modified on 1 April 2010, at 14:02



Scatter PlotsEdit

. clear
. set obs 100
obs was 0, now 100
. gen id = _n 
. gen a = invnorm(uniform())
. gen b = invnorm(uniform()) + a
. gen c = invnorm(uniform()) - 2*a
. sc b c a, msymbol(sh oh) mcolor(cranberry green)
set obs 100

gen x = invnorm(uniform())
gen y = invnorm(uniform()) + x

tw (sc y x)(lfit y x)
tw (sc y x, msymbol(X))(lfit y x)
tw (sc y x, msymbol(D))(lfit y x)
tw (sc y x, msymbol(T))(lfit y x)
tw (sc y x, msymbol(S))(lfit y x)
tw (sc y x, msymbol(+))(lfit y x)
tw (sc y x, msymbol(p))(lfit y x)
tw (sc y x, msymbol(oh))(lfit y x)
tw (sc y x, msymbol(sh))(lfit y x)

Standard Error Bar ChartEdit

Standard Error Bar Chart are very useful to displain confidence interval.

. clear
. set obs 100
obs was 0, now 100
. gen id = _n
. expand 10
(900 observations created)
. gen u = id/30 + invnorm(uniform())
. collapse (mean) mean = u (sd) sd = u, by(id) 
. local s = invnorm(.975) * 97,5 percentile of the normal distribution
. serrbar mean sd id , scale(`s')

Setting for GraphicsEdit

  • the list of symbols :
. palette symbolpalette 

query graphics gives all the settings.

. query graphics
    Graphics settings
        set graphics        on
        set scheme          vg_s2c
        set printcolor      automatic  may be automatic, asis, gs1, gs2, gs3
        set copycolor       automatic  may be automatic, asis, gs1, gs2, gs3
        set macgphengine    quartz     may be quartz or quickdraw
        set piccomments     on

  • The scheme defines the general appearance of the graph.
  • You can download more scheme on the Visual Guide to Stata Graphics website :
. net from
. net install vgsg2

Exporting/Saving graphicsEdit

You can export a graph to png, jpg, ps or pdf format by using once the graph is done the graph export command.

. tw sc y x 
. gr export graph.png, replace

See h gr export to see the list of all available graph devices.

You can also store a graph in the Stata graph format using the graph save command. This format can only be read by Stata.


Previous: Data Index Next: Programming