|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: overlapping graphs
Brilliant! Thank you kindly Svend.
Michael McCulloch wrote:
The following commands compare two graphs, side-by-side. My question is,
can they be overlapped, so both curves are plotted within the same graph?
sysuse cancer.dta, clear
stset studytime
keep if drug==3
sts graph, by(drug) title("survival", box bfcolor(white))
saving("survival", replace )
sts graph, by(drug) na title("hazard", box bfcolor(white))
saving("hazard", replace )
graph combine survival.gph hazard.gph, rows(2) cols(2)
iscale(0.5) title(Survival vs. Hazard)
===================================================================
Use -sts generate- to create the functions, and next create the graph.
Note that you need two vertical axes here.
sysuse cancer.dta, clear
stset studytime
keep if drug==3
sts generate surv = s
sts generate cumhaz = na
// We need the point of origin (0,1) for the survival curve:
local N1 = _N+1
set obs `N1'
replace surv=1 in -1
replace _t=0 in -1
sort _t
twoway ///
(scatter surv _t , msymbol(none) connect(J) lpattern(l) yaxis(1)) ///
(scatter cumhaz _t , msymbol(none) connect(J) lpattern(-) yaxis(2)) ///
, ytitle("Survival" , axis(1)) ytitle("Cumulative hazard" , axis(2))
Hope this helps
Svend
________________________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [email protected]
_________________________________________________________
*
* 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/
*
* 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/