Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: renaming variables based on long labels

From   "Cohen, Elan" <>
To   "''" <>
Subject   st: renaming variables based on long labels
Date   Thu, 21 Jul 2011 14:00:18 +0000


I have a dataset with variable names VAR1-VAR40.  All variables have (pretty long) labels.  I'm using 

foreach var of varlist VAR* {
	rename `var' `=strtoname("`:var lab `var''")'

to rename each variable according to their label.  I'm running into a problem because the variable labels are not unique within the first 32 characters and so I'm getting "Relationship_of_interviewee_to_s already defined".

Can Stata automatically generate a unique name based on existing variables?  This seems like it's possible based on the following output:

webuse bg2
renvars, prefix(longprefix)

where Stata truncates variables names and automatically finds a unique string to display for each variable (-findit renvars-).

Thanks for any help you can provide,

- Elan

Elan D Cohen, MS
Center for Research on Health Care Data Center
University of Pittsburgh

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index