Statalist


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

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


From   moleps islon <[email protected]>
To   [email protected]
Subject   Re: st: RE: automatic coding so that legends assume the label variables
Date   Sun, 18 Oct 2009 23:17:38 +0200

I tried that approach, however the only thing that happens is that it
"feeds" 0 and 1 through, not the var label. However when the var is
1/2 everything is OK. I find it strange that at least the 1-value
doesnt find its associated var val in 0/1 variables.
e.g.

capture program drop km
program km
local h
local g 1
qui levelsof `1', local(lev)
di `lev'
	 foreach val of local lev {
		
      	local k `:label `1' `val''
		di "`k'"
		local h `h' `g' "`1' `k'"
		local m `m' lab(`g' "`1' `k'")
		local ++g
}
etc
etc


. tab female

     female |      Freq.     Percent        Cum.
------------+-----------------------------------
         No |        163       50.46       50.46
        Yes |        160       49.54      100.00
------------+-----------------------------------
      Total |        323      100.00


. tab female,nol

     female |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        163       50.46       50.46
          1 |        160       49.54      100.00
------------+-----------------------------------
      Total |        323      100.00

. km female
01
0
1

. tab sex

        sex |      Freq.     Percent        Cum.
------------+-----------------------------------
       male |        163       50.46       50.46
     female |        160       49.54      100.00
------------+-----------------------------------
      Total |        323      100.00

. tab sex,nol

        sex |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |        163       50.46       50.46
          2 |        160       49.54      100.00
------------+-----------------------------------
      Total |        323      100.00

. km sex
12
male
female

.




On Sun, Oct 18, 2009 at 10:37 PM, Kieran McCaul
<[email protected]> wrote:
> ...
>
> 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: [email protected]
> 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: [email protected] [mailto:[email protected]] On Behalf Of moleps islon
> Sent: Monday, 19 October 2009 4:21 AM
> To: [email protected]
> 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悲
> 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/
>

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