Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: splitting a numeric string


From   "Oleksandr Talavera, BC" <[email protected]>
To   [email protected]
Subject   Re: st: splitting a numeric string
Date   Sun, 26 Jan 2003 23:18:01 -0500

you can try the following (I assume that ed is str12):

*-------CODE------
replace ed = subinstr(ed , "10" , "0", 6)
forvalues i=1(1)6 {
g str1 choice`i' = substr(ed , `i' , 1)
replace choice`i' = "10" if choice`i'=="0"
destring choice`i', replace
}
*---------------------

Sasha Talavera,
--------------------
[email protected]



Steven Stillman (LMPG) wrote:

Hi. I have a string variable which contains information on a maximum of 6
choices made (of education). The choices are numbered 1-10 and are a
running string. They can be in any order and can be repeated. I want to
create 6 variables choice1, choice2, ... choice6. The problem I am running
into is that all numbers are 1 digit besides 10 (fortunately 0 is not a
choice) and 10 can be located anywhere in the string.
Here is a snippet of what I have and what I am trying to do.

ed choice1 choice2
choice3 etc.
54. 54 5 4 .
65. 89 8 9 .
66. 5 5 . .
67. 1 1 . .
78. 932 9 3 2
81. 10 10 . .
97. 8 8 . .
103. 105410 10 5 4


Thanks for any help,
Steve

<><><><><><><><><><><><><><><><>
Steven Stillman - Senior Economic Researcher
Labour Market Policy Group
New Zealand Department of Labour
PO Box 3705 - Wellington, New Zealand
Email: [email protected] Web: http://www.thestillmans.org/econ.html
Tel: (64)4-915-4076 - Fax: (64)4-915-4040
<><><><><><><><><><><><><><><><>


The information contained in this document is intended only for the
addressee and is not necessarily the views nor the official communication of the Department of Labour. All final/official papers which are sent from the Department will be sent by non-electronic
means, on appropriate letterhead, signed by authorised personnel.
*
* 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/



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