Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Using regex to identify strings with capital letters


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Using regex to identify strings with capital letters
Date   Thu, 27 May 2010 14:12:43 +0100

I thought PO was the state that contained Podunk State University. 

Nick 
n.j.cox@durham.ac.uk 

Beecroft, Erik (VDSS)

Thank you to Martin and Nick for solving my problem, Martin with the
regexm function and Nick with inrange.

Both of these work with my data:
	keep if regexm(substr(var1,1,2) , "^([A-Z][A-Z])")
	keep if inrange(substr(var1,1,1), "A", "Z") &
inrange(substr(var1,2,1), "A","Z")

Both also keep records that begin with "PO" for Post Office box.  These
records I don't want, but easily dropped by modifying Martin's
suggestion:
	drop if regexm(substr(var1,1,2) , "^([P][O])")

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index