Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Rename problem: r(110) already defined


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Rename problem: r(110) already defined
Date   Tue, 12 Feb 2008 23:16:53 -0000

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 
n.j.cox@durham.ac.uk 

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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index