Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

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


From   "Beecroft, Erik (VDSS)" <[email protected]>
To   <[email protected]>
Subject   st: FW: Using regex to identify strings with capital letters
Date   Wed, 26 May 2010 14:37:25 -0400

I tried Nick's suggestion, pasted below, but inrange does not seem to
distinguish between lower and upper case.  In other words, the statement
below keeps all observations that begin with two letters, whether
capital or lower case.

Erik




You don't need regex for this. 

... if inrange(substr(myvar,1,2), "AA", "ZZ") 

should be enough, or even "AK" to "WY" or whatever it is. (Remember this
is an international list!) 

Nick 
[email protected] 


-----Original Message-----
From: Beecroft, Erik (VDSS) 
Sent: Wednesday, May 26, 2010 2:03 PM
To: '[email protected]'
Subject: Using regex to identify strings with capital letters

I need to extract certain observations from a series of text files.
Each file contains only one variable, which is string.  The
observations I want all begin with two capital letters. (They are state
abbreviations, such as VA or AK).  The other observations do not begin
with two capital letters.

Is there a way to tell Stata to keep only observations for which the
variable begins with two capital letters?

It seems like the regex function might work, but I have never worked
with regular expression syntax before.  

For example, a portion of a text file might look like:
	text1
	text2
	VA department of Social Services
	text4
	text5

I want to keep only the third observation above.

I am using Stata for Windows 10.1.

Erik


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