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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: Re: finding a word within a string variable in Stata 12


From   Michael Mulcahy <mulcahy_uconn@yahoo.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: finding a word within a string variable in Stata 12
Date   Wed, 21 Mar 2012 18:28:37 -0700 (PDT)

I have been using regexm way too much recently - I'm categorizing non-profit organizations based strings of organizational names, such as: 


obs1: orgname == "Seattle Brotherhood of Whatever Benevolent Association"  and
obs2: orgname == "Memphis Big Capital Employees Benevolent Assoc"
obs3: orgname == "Peoria Association of Dairy Farmers"
My klunky approach is:


gen benev = 0
replace benev = regexm(orgname, "Benev") & regexm(orgname, "Assoc")


This codes obs1 & obs2 as "1", and leaves obs3 as "0"




----- Original Message -----

From: Nick Cox <njcoxstata@gmail.com>
To: statalist@hsphsun2.harvard.edu
Cc: 
Sent: Wednesday, March 21, 2012 1:21 PM
Subject: st: Re: finding a word within a string variable in Stata 12

I haven't tried to see what doesn't work with the regex machinery
because this problem seems to call only for

gen construction = strpos(sic, "construction") > 0

Nick

On Wed, Mar 21, 2012 at 7:28 PM, Navarro Paniagua, Maria
<m.navarropaniagua@lancaster.ac.uk> wrote:
> Dear Professor Cox,
>
>
>
> I am trying to find a word (for instance construction) within a string
> variable (sic), the string can have as categories (construction 1, b
> construction)
>
>
>
> Could you please help me with this?
>
>
>
> gen construction = regexs(1) if regexm(sic, "[construction]+")
>
> g one = 1 if strmatch(sic, "*constr*")
>
*
*   For searches and help try:
*  http://www.stata.com/help.cgi?searchhttp://www.stata.com/support/statalist/faqhttp://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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index