Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Referencing variable labels in a foreach loop

From   Philipp Rehm <>
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.


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

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?

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index