Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Rebecca Pope <rebecca.a.pope@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: RE: Stata analog to Mata's -strdup()- or better approach? |
Date | Fri, 11 Mar 2011 20:51:25 -0600 |
Nick, I had to read what you wrote a couple of times before the "Duh" kicked in. In one of my many attempts, I did (nearly) exactly what you wrote below. The real difference, which I didn't catch at first, is that you don't condense the spaces into a single space like I did. -split- will create a new variable for each " ", thereby preserving where the string started. For subsequent instances of variables including Xs, the index on the variable generated by -split- will be off, but I could just add the length of the preceding variables. Brilliant! (you, not me) In the interest of full disclosure, I'm rather ashamed to admit that I initially used -split- exactly as you do and cursed at it for not recognizing multiple delimiters as one, went back and condensed the multiple spaces to a single space, and then -split- the variable again. In fact, my initial reaction to your e-mail was "Did that; doesn't work." I suppose "obtuse" does apply. Sorry for the trouble. Unless I'm missing something else, I could just use - split estring, parse(-) -, correct? Thanks again for all the help, Rebecca On Fri, Mar 11, 2011 at 6:32 PM, Nick Cox <njcoxstata@gmail.com> wrote: > > Have you thought of something like > > clonevar fstring = estring > replace fstring = subinstr(fstring, "-", " ", .) > split fstring > <truncated> * * 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/