[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: overlapping graphs

From   Michael McCulloch <>
Subject   Re: st: overlapping graphs
Date   Sun, 14 Sep 2008 07:18:46 -0700

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

* For searches and help try:
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index