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: Splitting the contents of a cell with enter key as the delimiter


From   Sergiy Radyakin <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Splitting the contents of a cell with enter key as the delimiter
Date   Tue, 3 Dec 2013 12:55:14 -0500

clear
set obs 1
local separator `"`=char(13)'"'
generate str100 s = "Banc of America Securities
LLC"+`"`separator'"'+"JP Morgan & Co Inc"+`"`separator'"'+"Morgan
Stanley"
list
split s, generate(t) parse(`"`separator'"')
list t*

It's up to you what the separator is. Perhaps consider everything
non-printable as a separator.
Best, Sergiy


On Tue, Dec 3, 2013 at 12:28 PM, Nick Cox <njcoxstata@gmail.com> wrote:
> I won't rule out that it could be CR and LF together.
>
> -charlist-  (SSC) is a simple utility that identifies characters
> present in string variables.
> Nick
> njcoxstata@gmail.com
>
>
> On 3 December 2013 17:08, Nick Cox <njcoxstata@gmail.com> wrote:
>> That's not enough information for us to identify which character  that
>> is (Stata sense) but from standard lists e.g.
>> http://www.asciitable.com/ it sounds like carriage return or line
>> feed. Either way, -split- should be up to it. There is an example in
>> the help for -split- showing how to split on tabs, meaning -char(9)-,
>> which should be of the same form.
>>
>> This is one example, where the Statalist convention, urged upon you
>> all by the FAQ but adopted only by a few, of flagging syntax with - -
>> is really helpful, as in
>>
>> I am using the -split- command.
>>
>> Nick
>> njcoxstata@gmail.com
>>
>>
>> On 3 December 2013 16:46, Dev Vencappa <Dev.Vencappa@nottingham.ac.uk> wrote:
>>
>>>      I am trying to split the contents of a string variable which reads as one long name as below when viewing it in the data editor:
>>>
>>> Banc of America Securities LLCJP Morgan & Co IncMorgan Stanley
>>>
>>> But upon closer inspection, this is actually stored with the enter key as a delimiter in the cell as below:
>>>
>>> Banc of America Securities LLC
>>> JP Morgan & Co Inc
>>> Morgan Stanley
>>>
>>> I am trying to use the command split to retrieve and save each of these three business names into three different columns. However, I am not sure how to code split to specify thatthe parser should be the enter key. Can someone please kindly offer a solution to this please? My string variable has thousands such cases where sometimes there are up to 15 different names in the content of a cell delimited using the enter key.
>
> *
> *   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