Instead of capture rename ... use capture confirm variable.
capture confirm variable `newname'
After that you can rename the variable if the new one does not exist.
Regards, Sergiy
On 2/12/08, Friedrich Huebler <[email protected]> wrote:
> 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.
>
> Thanks,
>
> Friedrich
> *
> * 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/
>
*
* 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/