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]

st: Referencing variable labels in a foreach loop

From   Ishir Bhan <>
Subject   st: Referencing variable labels in a foreach loop
Date   Tue, 13 Jul 2010 22:18:02 -0400

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:

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