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

RE: st: rename variables UPPERCASE to lowercase


From   "Joao Pedro W. de Azevedo" <jazevedo@provide.com.br>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: rename variables UPPERCASE to lowercase
Date   Sat, 1 May 2004 11:25:32 +0100

Hello Ada,

Check the code below. It works fine with the auto dataset.

In your case you will have the change the local command line to

local new_var=lower("`var'")

use auto, clear
foreach var of varlist _all {
	local new_var=upper("`var'")
	rename `var' `new_var'
}

All the very best,

JP



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ada Ma
Sent: Monday, April 26, 2004 3:39 PM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: rename variables UPPERCASE to lowercase


Hi all,

Thanks for all the suggestions.  May be becoz I'm crap - I tried both Nick 
Winter's and Nick Cox's version and neither works.

When I used these commands:

foreach var varlist QUOTA-UALDWK2 {
rename `var' `=lower("`var'")'
}

Stata returns says "Invalid Syntax" r(198).  I tried several versions of it
and 
none of it work.

I think I'll stick to (and try to memorise) the "simpler" _renvars_!


Ada Ma


Nick Cox wrote:

> Independently, Nick Winter has suggested what
> I suggested as a solution using only official
> commands. However, his version is correct 
> in remembering the " " in 
> 
>   . rename `v' `=lower("`v'")'
> 
> and mine is incorrect.
> 
> Nick
> n.j.cox@durham.ac.uk 
> 
> Nick Winter
> 
> 
>>>I need to convert all variable names from UPPERCASE to
>>
>>lowercase.  How can
>>
>>>I do that?
>>
>>         . foreach var of varlist * {
>>         . rename `v' `=lower("`v'")'
>>         . }
>>
>>
>>This will cycle through every variable in the dataset,
>>renaming each to its 
>>equivalent, all-lower-case self.
>>
>>Or I'm sure there are canned solutions out there, but this is
>>a case, for 
>>me at least, where knowing a bit about -foreach- and local 
>>macros is far 
>>easier than remembering which canned solution does this little job...


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

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