--- On Sun, 29/11/09, Hau Chyi wrote:
> How do I add a total group on the survival graph when I
> specify: -sts
> graph, by(var1)-
You can do it by creating variables to represent those survival curves
with -sts generate- and plot those directly. To get exactly the same
graphs as -sts graph- you'll need to do a bit of additional data
manipulation to ensure that the survival curves begin at the point t=0
and Survival proportion =1.
*-------------------- begin example -------------------------
sysuse cancer, clear
stset studytime, failure(died)
sts gen S_by = s, by(drug)
sts gen S_tot = s
// We want to start the curve at t=0 and Survival proportion = 1
// So we add 3 new observations, one for each group, to represent
// these initial points
gen byte new = 0
set obs `=_N+3'
replace new = 1 if new == .
replace drug = 1 if _n == _N-2
replace drug = 2 if _n == _N-1
replace drug = 3 if _n == _N
replace _t = 0 if new
replace S_by = 1 if new
replace S_tot = 1 if new
twoway line S_by _t if drug == 1 , sort connect(J) || ///
line S_by _t if drug == 2 , sort connect(J) || ///
line S_by _t if drug == 3 , sort connect(J) || ///
line S_tot _t , sort connect(J) ///
legend(order(1 "placebo" ///
2 "drug 2" ///
3 "drug 3" ///
4 "total" ))
// We don't want to keep those "new" observations
drop if new
drop new S_by S_tot
*--------------------------- end example ----------------------
( For more on how to use examples I sent to statalist see:
http://www.maartenbuis.nl/stata/exampleFAQ.html )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/