Bookmark and Share

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


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

Re: st: Removing Spaces from Variable Labels


From   "Michael N. Mitchell" <[email protected]>
To   [email protected]
Subject   Re: st: Removing Spaces from Variable Labels
Date   Sat, 20 Nov 2010 12:35:43 -0800

I wonder if this response from Martin Weiss to a similar question would help.

http://www.stata.com/statalist/archive/2010-04/msg01279.html

Michael N. Mitchell
Data Management Using Stata      - http://www.stata.com/bookstore/dmus.html
A Visual Guide to Stata Graphics - http://www.stata.com/bookstore/vgsg.html
Stata tidbit of the week         - http://www.MichaelNormanMitchell.com



On 2010-11-20 9.44 AM, Dan Connor wrote:
Hi all,

I have a series of survey-derived datasets, with about 700 variables in each. I need to merge them, which I can do. The problem is that the variable names are uninformative (they're called v1, v2, v3...), and are not in the same order in each dataset (eg, v3 might correspond to gender in one dataset, and level of education in another). Fortunately, the variable names are the same when the survey question was the same. So I'm planning to just change the variable name to the variable label, using this routine:

foreach var of varlist * {
local x : variable label 'v'
rename 'v' 'x'
label variable 'x' "'v'"
}

However (and here's the part I need help with), the variable labels contain spaces, sometimes special characters, and sometimes are longer than 32 characters. This means that they are invalid names, so my loop above won't work. Is there a good way to remove these spaces and such from the labels before I run the above loop?

Thanks-

Dan

---
Dan B. F. Connor
[email protected]


*
*   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/
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index