[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   Maarten buis <>
Subject   Re: st: RE: automatic coding so that legends assume the label variables
Date   Sun, 18 Oct 2009 15:37:49 -0700 (PDT)

--- 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')
sysuse auto, clear
km foreign
*---------------------- end example ------------------
(For more on examples I sent to the Statalist see: )

Hope this helps,

Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen


*   For searches and help try:

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