Michael McCulloch wrote:
I have a dataset which contains a variable <site_02>
containing a long list of tumor ID codes, from which
I want to keep ten: C180 through C189.
Is there a less labor-intensive way to do the following:
keep if site_02=="C180" | site_02=="C181" | site_02=="C182" | ///
site_02=="C183" | site_02=="C184" | site_02=="C185" | ///
site_02=="C186" | site_02=="C187" | site_02=="C188" | site_02=="C189"
----------------------------------------------------------
Yes! You can:
keep if site_02 >= "C180" & site_02 < "C190"
Relational operators also work with strings:
" " < "12" < "2" < "A" < "AA" < "Z" < "a"
Strings are sorted in dictionary sequence; however, all uppercase
letters come before lowercase, numbers come before letters, and
spaces or blanks come before anythng else.
Hope this helps.
Svend
________________________________________________________
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000 Aarhus C, Denmark
Phone, work: +45 8942 6090
Phone, home: +45 8693 7796
Fax: +45 8613 1580
E-mail: [email protected]
_________________________________________________________
*
* 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/