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]

st: Splitting a textvariable


From   "Tomas Lind" <[email protected]>
To   <[email protected]>
Subject   st: Splitting a textvariable
Date   Wed, 12 May 2010 13:06:54 +0200

Dear listers


I have (in principal) a dataset that looks like this with an id-variable and
a text-variable with addresses. Unfortunately there are often several
addresses in the same variable. I have to split these into one variable for
the first address, another for the second and so on.

id   	address
---------------------------------------------------------------
1	Stockholm xroad 12 London yroad10
2	London zroad 31
3	Helsinki rroad 1 Oslo sroad 123 Berlin troad 13


Each address ends with a number. My idea is to put in a parsing "," in the
empty space after the number (to be able to use -split parse-. Like this.


id   	address
----------------------------------------------------------------
1	Stockholm xroad,12 London yroad10
2	London zroad 31,
3	Helsinki rroad 1,Oslo sroad123,Berlin troad 13



One idea to do this is to use something like (if we rename the
address-variable to a shorter name, x).

replace x[i]=","  if x[`i' - 1]==inrange(0, x[`i'], 9) & x[`i']==" "



I´m not sure about how to work out the details to get this into work. Any
help is welcome to put the commas into place. Other ideas are also welcome.

Yours

Tomas


*
*   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