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]

Re: st: RE: Changing variable name to variable label


From   Daniel Jones <dbj3@pitt.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Changing variable name to variable label
Date   Mon, 12 Apr 2010 17:15:26 -0400

Thanks to all the replies. Nick's solution worked extremely well. 

Daniel

On Apr 12, 2010, at 4:40 PM, Michael Norman Mitchell wrote:

> Oh, I just saw Nick's reply... that is much better than mine.
> Michael N. Mitchell
> See the Stata tidbit of the week at...
> http://www.MichaelNormanMitchell.com
> 
> On 2010-04-12 1.38 PM, Michael Norman Mitchell wrote:
>> Dear Daniel
>> 
>>  Indeed, I think that Martin is on the right track... here is some sample code
>> 
>> clear
>> sysuse auto
>> unab vlist : *
>> display "`vlist'"
>> foreach varname of local vlist {
>>  local varlabel : variable label `varname'
>>  mata : vl = st_local("varlabel")
>>  mata : newvarname = strtoname(vl)
>>  mata : st_local("varname2",newvarname)
>>  rename `varname' `varname2'
>> }
>> 
>> describe , full
>> 
>>  I know this could be done better using more mata, but I hope it helps
>> 
>> Michael N. Mitchell
>> See the Stata tidbit of the week at...
>> http://www.MichaelNormanMitchell.com
>> 
>> On 2010-04-12 1.24 PM, Martin Weiss wrote:
>>> <>
>>> 
>>> *******
>>> help mf_strtoname
>>> *******
>>> 
>>> comes to mind...
>>> 
>>> 
>>> HTH
>>> Martin
>>> 
>>> -----Original Message-----
>>> From: owner-statalist@hsphsun2.harvard.edu
>>> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Daniel Jones
>>> Sent: Montag, 12. April 2010 22:18
>>> To: statalist@hsphsun2.harvard.edu
>>> Subject: st: Changing variable name to variable label
>>> 
>>> I have a set of repeated cross sections (10 years) which I would like to
>>> combine into a single dataset. The problem is that the variable names are
>>> different across years -- it's a survey, so a variable I need might be
>>> called "Q13" one year and "Q17" the next.
>>> 
>>> Variable labels seem to be constant across years, so I thought a solution
>>> might be to rename the the variables on the basis of their labels. I found a
>>> previous Statalist posting which describes such a procedure. However, for
>>> this to work, variable labels need to already be appropriately formatted to
>>> be variable names -- i.e., no spaces, etc. My variable labels are of the
>>> form "Education Volunteer - Past 12 Months." I'm assuming there's a way to
>>> remove spaces, etc. from variable labels, and then make them the variable
>>> names -- but I don't know what it is.
>>> 
>>> Alternatively, it seems like there could be a simpler solution to merging
>>> all of these years together. Does anyone have any suggestions?
>>> 
>>> Thanks,
>>> Daniel
>>> *
>>> *   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/
> *
> *   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index