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 strings


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: splitting strings
Date   Thu, 10 Feb 2011 14:58:42 +0000

<>

Scott's solution doesn't check V2 for the word that should parse V1 (within the same observation), but instead checks whether V1 contains some text found anywhere in V2.  
This could be a problem if V1 contains segments that can be found in several levels of V2, see the 3rd observation I added below:

***!
clear
input str29 v1 str10 v2
"hello John Smith how are you?" "John Smith"
"I’m fine Jane, how about you?" "Jane,"
"I'm Jane, but you're John Smith, right?" ", ri"
end
levelsof v2
return list
split v1, parse(`=r(levels)')
l
***!

Nick's solution would split the 3rd obs on "ri", but Scott's would split it on "Jane" from the 2nd obs.

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754



On Feb 10, 2011, at 7:20 AM, Scott Merryman wrote:

> If the data set is small  then this should work:
> 
> clear
> input str29 v1 str10 v2
> "hello John Smith how are you?" "John Smith"
> "I’m fine Jane, how about you?" "Jane,"
> end
> levelsof v2
> return list
> split v1, parse(`=r(levels)')
> l
> 
> Scott
> 
> 
> On Thu, Feb 10, 2011 at 7:08 AM, Daniel Henriksen
> <[email protected]> wrote:
>> I'm sorry, the example is unreadable.
>> In observation one :
>> V1: hello John Smith how are you?
>> V2 John Smith
>> V1_1 hello
>> V1_2 how are you?
>> 
>> Observation two:
>> V1: I’m fine Jane, how about you?
>> V2: Jane,
>> V1_1 I'm fine
>> V1_2 how about you?
>> 
>> So the splitting of V1 varies from observation to observation
>> depending on the string text in V2
>> Hope this makes sense
>> 
>> /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