Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: automatic coding so that legends assume the label variables


From   "Kieran McCaul" <Kieran.McCaul@uwa.edu.au>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: automatic coding so that legends assume the label variables
Date   Mon, 19 Oct 2009 04:37:08 +0800

...

The number in the label option -lab()- refers only to the order that the lines are specified in the graph command.
So I think the following would work:

local i = 1
foreach val of local lev {
	local k `:label `1' `val''
	local h `h' `val' "`1' `k'"
	local m `m' lab(`i' "`1' `k'")
	local ++i
}


______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2701
Fax: (08) 9224 8009
email: Kieran.McCaul@uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
If you live to be one hundred, you've got it made.
Very few people die past that age - George Burns


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of moleps islon
Sent: Monday, 19 October 2009 4:21 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: automatic coding so that legends assume the label variables

Dear listers,
Instead of having graphs with legends composed of var-name==num, I´d
like the legens to automatically assume the name of the label
variables.

capture program drop km
program km

qui levelsof `1', local(lev)
di `lev'
	 foreach val of local lev {
      	local k `:label `1' `val''
		local h `h' `val' "`1' `k'"
		local m `m' lab(`val' "`1' `k'")

}
qui sts test `1'
local e=round(chi2tail(`r(df)',`r(chi2)'),0.01)
sts gr,by (`1') ti("") risktab(,title("") order(`h')) ytit("Survival")
xtit("Observation time, years") caption("* Log rank test",size(small)
span)  note("P=0`e'*",pos(5) ring(0)) legend(pos(2) col(1) `m'
ring(0)) saving (`1' .gph,replace)

end


This works fine as long as the var is coded 1,2,3,4,5 etc. However if
its a binary 0/1 variable I get the error msg legend.labels[0] invalid
name.. Any idea how I can remedy this?

Regards,

M

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



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