[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: How can I obtain the name of a variable's value label programatically?
From
Nick Winter <[email protected]>
To
[email protected]
Subject
Re: st: How can I obtain the name of a variable's value label programatically?
Date
Wed, 20 Feb 2008 10:36:37 -0500
See -help extended_fcn- for a discussion of the extended macro
functions, including ": label", which is what you want.
For example:
local lab : value label foreign
levelsof foreign
foreach v in `r(levels)' {
local vl : label `lab' `v'
local vals `vals' `v'
local labels `labels' `vl'
}
di "values: [`vals']"
di "labels: [`labels']"
K Jensen wrote:
On 20/02/2008, Maarten buis <[email protected]> wrote:
--- K. Jensen wrote:
I would like to obtain the name of a variable's value label
programatically within a loop.
You can do that using extended macro function, see:
-help extended_fcn- and the example below:
*------------ begin example ---------------
sysuse auto, clear
foreach var of varlist _all {
local lab : value label `var'
di "`lab'"
}
*------------ end example -----------------
Thanks Martin. You're wonderful!
I hate to say but I forgot to ask my follow up question:-
How could I put the values and labels of a specific value label into a
local macro
i.e. for the auto data
. label list origin
origin:
0 Domestic
1 Foreign
two lists containing (0,1) and ("Domestic", "Foreign")
Thankyou yet again
Karin
*
* 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/
--
--------------------------------------------------------------
Nicholas Winter 434.924.6994 t
Assistant Professor 434.924.3359 f
Department of Politics [email protected] e
University of Virginia faculty.virginia.edu/nwinter w
PO Box 400787, 100 Cabell Hall
Charlottesville, VA 22904
*
* 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 |