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: Variable name length limit


From   Phil Schumm <[email protected]>
To   <[email protected]>
Subject   Re: st: Variable name length limit
Date   Tue, 20 Aug 2013 09:26:04 -0500

On Aug 20, 2013, at 7:59 AM, Jean Bouyer <[email protected]> wrote:
> I have imported data into Stata from an Excel file. Initial variable names have been truncated to 32 characters when necessary.  I have had to use reshape wide that builds new variables adding number 1, 2, 3 ... at the end of the name.  Therefore, some variables would have a name longer than 32 and the program returned an error.  I had to change one by one (I found no other way...) the name of the variables equal to 32. By the way, this was not so easy since the importation from Excel produced variable names with the same 31 first characters and a number in 32nd position.  I agree that the Excel file could be better, but it was not mine ...
> 
> Is there a better way to do ?


I would suggest something like:

    foreach var of varlist _all {
        ren `var' `: permname `var', length(31)'
    }

IIRC, -import excel- preserves the original column names in the variable labels (if they are too long for Stata), so you've always got them available if necessary (I frequently move these to a characteristic for later use).


-- Phil


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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