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   Mon, 19 Oct 2009 11:21:57 +0200

Appreciate it, Maarten...Works like a charm.

//M

On Mon, Oct 19, 2009 at 12:37 AM, Maarten buis <[email protected]> wrote:
> --- On Sun, 18/10/09, moleps islon wrote:
>> 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.
>
> The reason why you didn't get it to work because you fed the
> -: label- extended macro function the variable name rather than
> the name of the label. Quoting the helpfile:
>
> returns the value label of # in valuelabelname.  For instance,
> label forlab 1 might return Foreign cars if forlab were the
> name of a value label and 1 mapped to "Foreign cars".
>
> So you can fix your program as follows:
>
> *-------------- begin example ----------------
> capture program drop km
> program km
>        local h
>        local g 1
>        qui levelsof `1', local(lev)
>        local lab : value label `1'
>        foreach val of local lev {
>        local k `:label `lab' `val''
>                local m `m' lab(`g' "`k'")
>                local ++g
>                local gr `"`gr' scatter price mpg if `1' == `val' ||"'
>        }
>        twoway `gr', legend(`m')
> end
> sysuse auto, clear
> km foreign
> *---------------------- end example ------------------
> (For more on examples I sent to the Statalist see:
> http://www.maartenbuis.nl/example_faq )
>
> Hope this helps,
> Maarten
>
> --------------------------
> Maarten L. Buis
> Institut fuer Soziologie
> Universitaet Tuebingen
> Wilhelmstrasse 36
> 72074 Tuebingen
> Germany
>
> http://www.maartenbuis.nl
> --------------------------
>
>
>
>
>
>
>
> *
> *   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