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: renaming variables based on long labels


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

Thank you Daniel, -permname- worked wonderfully.  I looked through all the string functions but forgot there was extra string functionality in the extended macro functions.

- Elan


> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-
> statalist@hsphsun2.harvard.edu] On Behalf Of daniel klein
> Sent: Thursday, July 21, 2011 11:36
> To: statalist@hsphsun2.harvard.edu
> Subject: Re: st: renaming variables based on long labels
> 
> First, I do not see under which circumstances you would prefer long
> variable names, too long to ever be typed out, to names like VAR1,
> VAR2, etc. but you will probably have your reasons.
> 
> Second, abbreviations used in your examples are not unique to
> -summarize-. It is used in every command producing output (e.g.
> tabstat). A lot of those command are implemented  as ados. However,
> unfortunatly nothing in these program's code will give you a hint how
> Stata manages to come up with the abbreviations.
> 
> Third, and I hope this helps, there is an extended function called
> -permname-, which creates valid variable names based on suggested
> names. If you modify your code to read
> 
> foreach var of varlist VAR* {
> 	rename `var' `:permname `=strtoname("`: var lab `var''")''
> }
> 
> you should not have the problem of invalid or already defined names.
> 
> Best
> 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/


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