|
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Re: global keys
On Sep 19, 2007, at 8:25 AM, Brendan Halpin wrote:
"Michael Blasnik" <[email protected]> writes:
----- Original Message -----
From: "Michael McCulloch" <[email protected]>
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"
see help inlist()
It only works with up to 10 strings (which your example exactly
meets)
keep if inlist( ) | inlist() ...
should allow for more then 10 strings.
I like Brendan's -regexm- solution, which is very adaptable to more
complicated situations. Stata's implementation of regular expressions
does not appear to allow count specifications, but it is possible to
improvise. Here is an example which keeps only variables prefixed
by "c" and followed by 1 or 2 digits.
/******************************/
input str10 x
c11
c333
c09877
c4
d5
d66
d888
end
keep if regexm(x,"c[0-9]")
list
drop if regexm(x,"c[0-9][0-9][0-9]+")
list
/***********************************/
Or use regular expressions: v
. keep if regexm(site_02,"C18[0-9]")
Brendan
--
Brendan Halpin, Department of Sociology, University of Limerick,
Ireland
Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room
F2-025 x 3147
mailto:[email protected] http://www.ul.ie/sociology/
brendan.halpin.html
*
Steven Samuels
[email protected]
18 Cantine's Island
Saugerties, NY 12477
Phone: 845-246-0774
EFax: 208-498-7441
*
* 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/