Statalist The Stata Listserver


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

st: RE: how to split a variable?


From   "Rodrigo Martell" <[email protected]>
To   <[email protected]>
Subject   st: RE: how to split a variable?
Date   Wed, 7 Mar 2007 12:05:46 +1100

Hi Yu-Jin,

try this (I'll assume your variable is called "var"):

gen house_no = substr(var,1,4)
gen indiv_no = substr(var,5,2)
destring house_no, replace
destring gen indiv_no, replace

You can have a look at other string functions in the [D] manual under "functions" or just by typing "help string functions"


Cheers, 

Rodrigo

Rodrigo Martell

 <http://www.frontier-economics.com> 	
Frontier Economics Pty. Ltd.
395 Collins Street
Melbourne VIC 3000
Australia
www.frontier-economics.com 	
switch:
direct:
fax:
mobile:
email:


+61 (0)3 9620 4488
+61 (0)3 9613 1518
+61 (0)3 8614 2711
+61 (0)407 909 811
[email protected] <mailto:[email protected]> 


This e-mail, including any attachments, may contain confidential and privileged information for the sole use of the intended recipient(s). Any review, use, disclosure or distribution by others is strictly prohibited. If you are not the intended recipient (or authorised to receive information for the recipient), please contact the sender by reply e-mail and delete all copies of this message. Thank you.

	



-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of
[email protected]
Sent: Wednesday, 7 March 2007 11:58 AM
To: [email protected]
Subject: st: how to split a variable?


I have a string variable with 6 characters wide. The first four characters are
household numbbers, and the last two are the individual members in a household.
I want two variables, namely, the household and the individual. Eventually, I
want to make them numerical. So, being string variable isn't important.

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