Statalist The Stata Listserver


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

RE: st: rename


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: rename
Date   Wed, 29 Mar 2006 15:26:32 +0100

I'd tweak this a little. 

This is going to fail when Stata is asked to 

rename foo foo 

and it could also -rename- variables 
which you are happy to keep with their
present names. So, use the most restrictive 
varlist you can specify, say: 

foreach v of var _* {
	local V : subinstr local v "_" ""
	rename `v' `V' 
}

That said, to this solution from first principles
should be added two other suggestions: 

1. Following Ada Ma's post, note that -renpfix- is already 
in Stata as an official command. (Oddly, the complementary 
-rensfix- remains user-written and outside official 
Stata.) 

2. Also -renvars- (-search renvars-) remains on offer
as a general renaming tool. 

Nick 
n.j.cox@durham.ac.uk 

Ulrich Kohler
 
> Hans J. Baumgartner wrote:
> > some of my data?s variables have an leading underscore but 
> not all, i.e.:
> >
> > _var1 _var2 _var3 var4 var5 _var 6
> >
> > How can I remove the leading underscore to get
> >
> > var1 var2 var3 var4 var5 var6
> 
> forach var of varlist _all {
> 	rename `var' `=subinstr("`var'","_","",.)'
> }

*
*   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–2020 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index