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]

Re: st: RE: RE: AW: Search for string values in dataset??


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: st: RE: RE: AW: Search for string values in dataset??
Date   Mon, 21 Feb 2011 16:18:23 +0000

<>

One way to match insensitive to case would be to create a lowercase (and (optionally) temporary) version of the string variable and match on that, so:

*********************!
clear
inp str10(var1)
"GmbH7UuIZ"
"GMbH7UuIZ"
"gmbh7Uuiz"
end

//1.  from Markus and Junlin//
g one = 1 if strmatch(var1, "*GmbH*")
g byte two = regexm(var1, "GmbH")
list var1 if regexm(var1, "GmbH")

//2.  Another option:  index //
g str10 three = var1 if index(var1, "GmbH")
g str10 four = var1 if index(var1, "gmbh")
list var1 if index(var1, "GmbH")

//3.  case insensitive - lower case matches //
tempvar var1_lower 
g `var1_lower' = lower(var1)
g str10 five = var1 if index(`var1_lower', "gmbh") 
/* could evaluate to 1 if matched (instead of var1 contents) */
l
*********************!

- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754

On Feb 21, 2011, at 9:52 AM, Liao, Junlin wrote:

> Continue on this topic, anyone has a good way to make those two commands case insensitive? Thanks,
> 
> Junlin
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Liao, Junlin
> Sent: Monday, February 21, 2011 9:40 AM
> To: [email protected]
> Subject: st: RE: AW: Search for string values in dataset??
> 
> Miyu,
> 
> Another command is -regexm-
> 
> gen byte GmbH_Match = regexm(variable, "GmbH")
> 
> If you simply want to list the entries:
> 
> list variable if regexm(variable, "GmbH")
> 
> Junlin
> 
> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Wiemann, Markus
> Sent: Monday, February 21, 2011 9:17 AM
> To: [email protected]
> Subject: st: AW: Search for string values in dataset??
> 
> Hi Miyu,
> 
> try the -strmatch- command.
> For example:
> gen GmbH = 1 if strmatch(variablename, "*GmbH*")
> 
> 
> Best
> Markus
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von miyu Lee
> Gesendet: Montag, 21. Februar 2011 16:12
> An: [email protected]
> Betreff: st: Search for string values in dataset??
> 
> Is there ANY way to search for specific string values in a dataset with string variables? For example: I am searching for all entries showing the part "GmbH" in a vector with firm names. I have a bad feeling about this!
> 
> Best
> Miyu
> *
> *   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/
> 
> *
> *   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/
> 
> 
> ________________________________


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