Statalist


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

Re: st: sts graph: customizing -legend- option of -sts graph-


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: sts graph: customizing -legend- option of -sts graph-
Date   Wed, 10 Sep 2008 06:17:16 +0100 (BST)

--- Michael McCulloch <mm@pinest.org> wrote:
> I've created a KM plot comparing two troups, and have used the 
> -legend- option. Note in the 1st graph example that they're labeled 
> 1, 2, and 3.
> 
> Also note that in the second example, after dropping "drug 2", that 
> even though 1 and 3 are left, they're labelled 1 and 2. If I've 
> dropped 2, I'd like to see the labels say 1 and 3! Is there a way to 
> do this?
> 
> sysuse cancer.dta, clear
> stset studytime
> * graph 1
> sts graph, by(drug) atrisk legend(label(1 "drug 1") label(2 "drug 2")
> 
> label(3 "drug 3")) ///
> drop if drug==2
> * graph 2
> sts graph, by(drug) atrisk legend(label(1 "drug 1") label(2 "drug 2")
> label(3 "drug 3")) ///

-label()- referes to first, second, and third line in your graph, not
to the value 1, 2, and 3 in the variable drug. This is necessary given
that the syntax of -legend- is designed to handle much more complex
graphs. There are two ways of doing what you want:

1) Say to Stata that the first line represents drug 1 and and second
line drug 3:

*----------- begin example ---------------
sysuse cancer.dta, clear
stset studytime, failure(died)
drop if drug == 2
sts graph, by(drug) atrisk ///
     legend(label(1 "drug 1") ///
            label(2 "drug 3"))  
*------------ end example ----------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

2) Assign labels to the values of the variable drug:

*----------- begin example -----------
sysuse cancer.dta, clear
stset studytime, failure(died)
drop if drug == 2
label define drug 1 "drug 1" 2 "drug 2" 3 "drug 3"
label value drug drug
sts graph, by(drug) atrisk
*------------ end example ------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room N515

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


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



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