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: String Variable With Probable Extra Space, Problems with Trim


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: String Variable With Probable Extra Space, Problems with Trim
Date   Wed, 2 Jun 2010 13:14:27 -0500

You might find Nick Cox's -charlist- on SSC helpful  (and -ascii- or
-asciiplot- as well).

Scott


On Wed, Jun 2, 2010 at 12:52 PM, J Taylor <jwtayl@gmail.com> wrote:
> I have a variable of US state names that include what I think are some
> extra spaces at the front and at the end of the variable value.
> Instead of "California", I think the variable is "  California  ".  I
> received the dataset in Excel and then saved it as a .csv file with
> Excel 2007.
>
> I say 'I think' above because I'm not 100% sure if there might be some
> character that I can't see that is not a space.
>
> I try using
> gen state1 = trim(state)
>
> but state1 continues to have "  California  " as a value instead of
> "California."  This is super-weird, and I apologize I cannot provide
> information about what is going on.
>
> Might there be another way (other than trim) to extract the state name
> so that there are no spaces?  I could look for a continuous group of
> letter characters, but this may face disadvantages for the two word
> states, e.g. "New Hampshire."  Any other suggestions about fixing this
> problem?
>
> Thanks,
> JT

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