dalhia, you could use -joinby- to avoid looping, see the code below.
mike
clear
input str20 name1 str20 name2
"ram solanki" solanki
"goel mehta" mehta
"ashish gupta" joe
"john doe" smith
"jim brown" blue
"anna karenina" betsy
"betsy smith" anna
end
gen byte one = 1
save names, replace
use names, clear
keep name2 one
save name2, replace
use names, clear
keep name1 one
joinby one using name2
drop one
duplicates drop name1 name2, force
gen match = regexm(name1,name2)
keep if match==1
list
+---------------------------------+
| name1 name2 match |
|---------------------------------|
1. | anna karenina anna 1 |
2. | betsy smith betsy 1 |
3. | goel mehta mehta 1 |
4. | betsy smith smith 1 |
5. | ram solanki solanki 1 |
+---------------------------------+
On Thu, Jun 4, 2009 at 6:49 PM, Dalhia<[email protected]> wrote:
>
> hi,
>
> I have a list of two variables: name1 and name2. I need to check if name2 occurs in any of the name1s. The regexm command in stata is perfect for what I want to do, but it checks only one string at a time, and I need it to somehow rotate over a whole list of names.
>
> Here is what I have:
>
> name1
> ram solanki
> goel mehta
> ashish gupta
>
> name2
> solanki
> mehta
>
> I need to be able to figure out that "solanki" and "mehta" in name2 occur in name1 observation1 and observation2.
>
> Any help will be much appreciated.
> thanks
> dalhia
*
* 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/