Statalist The Stata Listserver

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

st: Renaming varnames

From   "Thomas Speidel" <>
To   <>
Subject   st: Renaming varnames
Date   Wed, 25 Jan 2006 13:46:11 -0700

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)'

Thomas Speidel
Statistical Associate
Clinical Trials Unit
Tom Baker Cancer Centre
1331 - 29th Street N.W.
Calgary, AB, T2N 4N4

Tel. (403) 521-3370

This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index