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]

From |
Nick Cox <n.j.cox@durham.ac.uk> |

To |
"'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: splitting strings |

Date |
Thu, 10 Feb 2011 13:18:12 +0000 |

What a nice question. I'm credited as the original author of -split-, following earlier joint work with Michael Blasnik, and I don't think I thought of this rather natural question when writing it. I checked to see whether I had solved it by accident and I hadn't. Whatever you specify as argument to -parse()- is taken literally and not checked to see if it is a variable name. However, there is a work-around. clonevar V1_2 = V1 replace V1_2 = subinstr(V1_2, V2, "&", .) split V1_2, parse(&) The essential is to use as new separator -- "&" in the example -- something that does not otherwise occur. You can test any potential separator by e.g. assert strpos(V1, "&") == 0 Nick n.j.cox@durham.ac.uk Daniel Henriksen I have a question regarding splitting up strings. Is it possible to split up a string using a string from another variable defined in the same observation. I'm thinking of using the "split" command. Here's an example, where V1 is the string I'd like to split and V2 is where I'd like to split (different from each observation). V1_1 and V1_2 are the results of the splitting V1 V2 V1_1 V1_2 hello John Smith how are you? John Smith hello how are you? I'm fine Jane, how about you Jane, I'm fine how about you? * * 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/

**References**:**st: splitting strings***From:*Daniel Henriksen <henriksen.dp@gmail.com>

- Prev by Date:
**RE: st: date/time question** - Next by Date:
**Re: st: splitting strings** - Previous by thread:
**Re: st: splitting strings** - Next by thread:
**st: New package -fvprevar- on SSC** - Index(es):