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

RE: st: upper case to lower case for all variable names


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: upper case to lower case for all variable names
Date   Wed, 16 Nov 2005 09:53:45 -0000

It's worth explaining the bridge between 
this and much shorter solutions given by 
others. 

The assumption that variable names go 
from VAR1-VAR999 can be replaced by 
a specification 

<whateverisfirstinyourdata>-<whateverislastinyourdata> 

and in turn by the wildcard * or _all. 

Then you have no need to drop existing macros. 
You can do the renaming on the fly: 

foreach v of var * { 
	rename `v' `=lower("`v'")' 
} 

A small risk with this last trick is that
"all variables" could include temporary variables
with names like __00000A. -rename- that to 
__00000a and you will have programming problems. 

However, when this is done it is, I guess, 
virtually always with the main dataset, and interactively, 
so no temporary variables are in sight. 

Nick 
n.j.cox@durham.ac.uk 

Rafal Raciborski
 
> assuming your variables go from VAR1 to VAR999:
> 
> macro drop _all
> foreach i of varlist VAR1-VAR999 {
> 	local j = lower("`i'")
> 	rename `i' `j'
> 	macro drop j
> }

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index