Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: quick question


From   Gary Longton <[email protected]>
To   [email protected]
Subject   Re: st: quick question
Date   Wed, 25 Feb 2004 14:38:31 -0800

Lachenbruch, Peter wrote:

I have a data set that I got with some oddball names like PyrexIA or
CuTaneousDA, etc. and I'd like to rename everything so all characters were
lowercase. Is there an easy way to do this via a foreach loop and a simple
command, or do I have to rename PyrexIA pyrexia
rename CuTaneousDA cutaneousda

I looked at the lower function but that seems to operate on variables rather
than names.
Richard Williams, Roger Newson, and Richard Goldstein suggested -renvars-, a single command solution which will do this in one fell swoop.
But I think you were also on the right track with what Nick Cox might call a "first principles" approach, using -foreach- and the lower() function. You just need to ensure that lower() is looking at the string variable name as an argument, rather than at the variable itself, by enclosing in double quotes. Eg.

foreach var of varlist _all {
local newname = lower("`var'")
if "`var'" ~= "`newname'" {
rename `var' `newname'
}
}

should do it.

- Gary



*
* 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