Ronnie,
here is one way to do it.
foreach x of varlist r1* {
local end = substr("`x'",-2,.)
local start = subinstr("`x'","`end'","",1)
rename `x' `end'`start'
}
Hope this helps,
Eva
2008/8/7 Ronnie Babigumira <[email protected]>:
> Dear Listers
> How do I rename some variables by switching letters around.
>
> As an example, I would like to rename r1k4 r12k4 to k4r1 and k4r12, so take
> the last two characters and put them at the beginning and put whatever is
> left at the end.
>
> Many thanks
>
> Ronnie
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/