Statalist The Stata Listserver


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

st: RE: RE: Renaming varnames


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Renaming varnames
Date   Wed, 25 Jan 2006 21:29:04 -0000

Yes, this is better than my -renvars- 
solution. I clearly don't understand 
the full power of -renvars-. 

But it is unnecessarily long. 

renvars, sub(_) 

is enough. 

Nick 
[email protected] 

Jose Valderrama
 
> Try this option:
> 
> renvars,subs(_ "")

Thomas Speidel
 
> I have a dataset whose variable names contain a varying amount of
> trailing underscores (_).
> Is there a way to rename all variable names without the trialing
> underscores (other than renaming each individual variable)?
> 
> ILLNESS___      byte   %10.0g                 
> SPECIMEN__      str12  %12s                   
> HOSPITAL__      byte   %10.0g                 
> TYPE______      byte   %10.0g                 
> STAGE_____      str4   %9s                    
> SIZE______      byte   %10.0g           
> ...
> 
> This is what I have tried so far (unsuccessfully):
> 
> 
> foreach v of varlist _all {
> 	gen `v'_underscore=strpos("`v'", "_")
> 	rename `v' `=substr("`v'", 1, `v'_underscore)'
> }
> 

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