Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Re: RE: values to labels


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: st: Re: RE: values to labels
Date   Mon, 13 Feb 2006 10:40:39 +0000

Michael's description matches my reading of the problem.

There is a small ragbag of unofficial -label- utilities in the
-labutil- package on SSC. The -labmask- command may be what
is wanted.

. ssc type labmask.hlp
-------------------------------------------------------------------------------
help for labmask
-------------------------------------------------------------------------------

Assign values or value labels of one variable as value labels to another

labmask varname [if exp] [in range] , values(varname)[lblname(lblname)
decode ]

Description

labmask assigns the values (or optionally the value labels) of one
variable values as the value labels of another variable varname. Any
existing value labels will be overwritten. The idea behind the program
name is that henceforth the face that varname presents will not be its
own, but a mask borrowed from values. Thus, for example, a year variable
might be coded by party winning at election and those value labels then
shown as labels on a graph axis.

varname must take on integer values for the observations selected. values
must not vary within groups defined by the distinct values of varname for
the observations selected. However, there is no rule that the same label
may not be assigned to different values of varname.

Nick
[email protected]

Michael Blasnik

I don't think this does what they asked -- this creates value labels that are sequential values labeled with the values of a variable -- in fact it does what -encode- does more directly. The question was about labeling the values of one variable using the values of another -- a slightly trickier problem. I've written an ado that does this but haven't posted it to SSC (no help file, not fully gracious with errors). I could send a copy off-list if Caleb would like.

Scott Merryman

Here is one way:

levelsof year, local(levels)
local i = 1
foreach l of local levels {
local mylabels "`mylabels' `i' `l'"
local ++i
}
label define label `mylabels'
label values round label

Caleb Southworth

Is there a convenient way to convert the values of one variable into
labels? For example, if rounds of survey are given in a particular year,
then

. tab round, sum(year)

round | Summary of year
number | Mean Std. Dev. Freq.
------------+------------------------------------
1 | 1992 0 4763
2 | 1993 0 6037
5 | 1994 0 2787
6 | 1995 0 2650
7 | 1996 0 2611
8 | 1998 0 2651
9 | 2000 0 2733
10 | 2001 0 3201
11 | 2002 0 3339
12 | 2003 0 3351
------------+------------------------------------
Total | 1996.8892 3.9638084 34123

Of course, I could define labels for round and label its values. My desire
is to automate this process over several surveys and many variables to
label graph axes. Thanks!
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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