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   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Variable name length limit
Date   Tue, 20 Aug 2013 15:30:55 +0100

that is too long could not in fact be a variable name, so it never
gets to be a member of _all. Applying -rename- to make it shorter not
only won't help, it is not even possible in principle.
Nick
[email protected]


On 20 August 2013 15:26, Phil Schumm <[email protected]> wrote:
> 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/

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