Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: separating string variable into components


From   "Ada Ma" <[email protected]>
To   [email protected]
Subject   Re: st: separating string variable into components
Date   Sun, 13 Aug 2006 21:56:01 +0100

you should be able to find out more about these commands if you look
it up on -help string functions-:

* first count the number of strings in your string variable
gen wordcount=wordcount(mystring)

tab wordcount

gen split1=word(mystring,1)
...

so on and so forth.



On 8/13/06, Radu Ban <[email protected]> wrote:
Dear Listers,

I have a string variable that looks like this:

mystring
   (1 2 3) (1 2 2)  (7 8 9)    (1 3 4)
 (2 3 4)    (1 2 3) (10 11 12)

etc. The numbers inside the brackets are made up. The problem is that
the number of spaces between brackets is not constant. Also the number
of brackets is not constant across observations. I want to split this
variable so that each bracket is contained in its own variable, i.e.

split1   split2    split3         split4
(1 2 3)  (1 2 2)  (7 8 9)        (1 3 4)
(2 3 4)  (1 2 3)  (10 11 12)   <blank>

I've tried the -split- command, with various numbers of spaces as the
parse character, but that doesn't work, i.e. it doesn't split if i
specify too many blanks, or it creates blank observations if i specify
too few blanks.

Any suggestions are appreciated.

Thanks,
Radu Ban
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


--
Ada Ma
Research Fellow
Health Economics Research Unit
University of Aberdeen, UK.
http://www.abdn.ac.uk/heru/
Tel: +44 (0) 1224 553863
Fax: +44 (0) 1224 550926
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index