Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: renaming variables based on long labels


From   "Cohen, Elan" <cohened@upmc.edu>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: renaming variables based on long labels
Date   Thu, 21 Jul 2011 14:00:18 +0000

Statalisters,

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

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
cohened@upmc.edu


*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index