04.06.2013 Views

Introduction to Stata 8 - (GRIPS

Introduction to Stata 8 - (GRIPS

Introduction to Stata 8 - (GRIPS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

twoway line<br />

Per cent surviving<br />

100<br />

80<br />

60<br />

40<br />

20<br />

0<br />

Females<br />

Males<br />

1901-05<br />

1840-49<br />

1999-2000<br />

0 20 40 60 80 100<br />

Age<br />

/ / c:\dokumenter\...\gph.DKsurvival.do<br />

use<br />

c:\dokumenter\...\DKsurvival.dta , clear<br />

s ort age // Data must be sorted by the x-axis variable<br />

l ist in 1/3, clean // List <strong>to</strong> show the data structure<br />

age m1840 k1840 m1901 k1901 m1999 k1999<br />

1. 0 100.00 100.00 100.00 100.00 100.00 100.00<br />

2. 1 84.47 86.76 86.93 89.59 99.16 99.37<br />

3. 2 80.58 83.11 85.22 87.89 99.08 99.32<br />

set<br />

scheme lean1<br />

twoway ///<br />

(line m1840-k1999 age , clpattern( - l - l – l )) ///<br />

, ///<br />

plotregion(margin(zero)) ///<br />

xtitle("Age") ///<br />

ytitle("Per cent surviving") ///<br />

legend(label(1 "Males") label(2 "Females") order(2 1) ///<br />

ring(0) pos(8)) ///<br />

text(91 72 "1999-2000") ///<br />

text(77 48 "1901-05") ///<br />

text(49 40 "1840-49") ///<br />

xsize(3.3) ysize(2.3) scale(1.4)<br />

A line plot is a variation of scatterplot without markers, but with connecting lines. This graph<br />

includes six line plots, required by one plot-specification with six y- and one x-variable. The<br />

clpattern() option defines the six connected-line patterns.<br />

Make sure data are sorted according <strong>to</strong> the x-axis variable; otherwise the result is nonsense.<br />

The example shows how <strong>to</strong> include text in a graph and how <strong>to</strong> position the legend within the<br />

plot area (see section 14.5 on placement of graph elements).<br />

Twoway graphs by default include "empty" space between the axes and the extreme plot<br />

values. The graph option plotregion(margin(zero)) lets the plot start right at the axes.<br />

46

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!