Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Referencing variable labels in a foreach loop


From   Philipp Rehm <[email protected]>
To   [email protected]
Subject   Re: st: Referencing variable labels in a foreach loop
Date   Tue, 13 Jul 2010 22:30:47 -0400

.

Try this:

di "`: var label `v''"

See help extended_fcn.

HTH,
Ph

On 7/13/2010 10:18 PM, Ishir Bhan wrote:
Is there any way to reference a variable's label, rather than the
variable name, in a foreach loop?

For example, I want to do a Spearman correlation of one variable with
a list of other variables. Then I want to print the name of the
variable with a significant association along with rho and the
p-value.

I can do this like this:

foreach var of varlist totalgrams-sucralosemg {
	quietly spearman alb `var'
	if r(p)<0.05 {
		display "`var'" _column(40) round(r(rho),0.01) _column(50) round(r(p),0.0001)
	}
}

However, this will display the name of the variable, not its label.
Oftentimes, the label is more informative.

Any way to do this?

Thanks.
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index