I guess that -rename- fails with an existing name because you issued
something that could be problematic, even if now and your current
dataset you don't care.
In other words, -rename- is explained with the pattern
-rename old new-
and
-rename old old-
doesn't match that pattern. Although your attitude is "I don't mind",
Stata's attitude is "Why did you ask that? Perhaps you are confused."
So, here and elsewhere, Stata is being hyper-cautious about anything to
do with changing the data.
Another part of the answer is that Stata provides other tools for you to
express your "don't mind" attitude, including -capture-, as others have
emphasised.
-rename- goes back to early Stata and a time of much smaller datasets
and occasional desires to change names. It is not really suited to the
mass renamings that are now common in data management. Jeroen Weesie and
I wrote
-renvars- (-search- for locations) as a more general tool some years
ago, with a name ugly enough to be safe from kidnappers, as C.S. Peirce
said in a different context. So
renvars, lower
does what you want without choking on any existing all-lowercase names.
However, StataCorp have shown marked reluctance either to adopt it or to
do anything to bring Stata's renaming into the 21st century....
Nick
[email protected]
Friedrich Huebler
I am trying to convert all variable names in my data to lowercase,
using the commands below. The -rename- command returns error code 110
"already defined" if a variable name is already lowercase.
ds
local vars "`r(varlist)'"
foreach v of local vars {
local newname = lower("`v'")
rename `v' `newname'
}
The problem can be reproduced with the auto data.
. sysuse auto
. rename make make
make already defined
r(110);
What is the rationale for disallowing -rename- in cases where there is
no other variable by the same name? In theory, no two variables in my
data have the same name, whether uppercase or lowercase. Can the
commands above be modified without resorting to -capture-? I would
like to avoid -capture rename- because if there are variables with the
same name it indicates a problem with the data and execution of the
do-file should stop at that point.
*
* 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/