Statalist


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

st: automatic coding so that legends assume the label variables


From   moleps islon <[email protected]>
To   [email protected]
Subject   st: automatic coding so that legends assume the label variables
Date   Sun, 18 Oct 2009 22:20:48 +0200

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/



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