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, statalist.org 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 <philipp.rehm@gmx.de>
To   statalist@hsphsun2.harvard.edu
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index