Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Re: Finding "near"-matches


From   "Frank de Libero" <fedmerchant@comcast.net>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Re: Finding "near"-matches
Date   Fri, 28 Oct 2005 10:35:17 -0700

Is this it?

---------------------------------------------------
*! soundex algorithm - vers 2.1 by M Blasnik 11oct2001
*! syntax: egen newvar=soundex(oldvar), [Length(int 4)]
program define _gsoundex
	version 7.0

	gettoken type 0 : 0
	gettoken g    0 : 0
	gettoken eqs  0 : 0

	syntax varlist(max=1) [if] [in], [Length(integer 4) BY(string)]

	if `"`by'"' != "" {
		_egennoby soundex() `"`by'"'
	}

marksample touse, strok
tempvar work res code vlen
quietly {
gen str1 `g'=substr(`varlist',1,1)
gen str1 `work'=""
gen str1 `code'=""
gen byte `vlen'=length(`varlist')
sum `vlen', meanonly
local maxvlen=r(max)
drop `vlen'
local codestr "BFPV####CGJKQSXZDT######L#######MN######R#######AEIOUWHY"
forvalues i=2/`maxvlen' {
	replace `work'=upper(substr(`varlist',`i',1))
	replace
`code'=string((int((index("`codestr'",`work')-1)/8)+1)*(index("`codestr'
",`work')!=0))
	replace `g'=`g'+ `code' if `work'!="" & substr(`g',-1,1)!=`code'
& `code'>"0" & `code'<"8"
	if `i'==2 {replace `g'=substr(`g',1,1) if
`work'==substr(`g',1,1)}
}
replace `g'=subinstr(`g',"7","",.)
replace `g'=substr(`g',1,`length')
replace `g'=`g'+substr("0000000000",1,`length'-length(`g'))
replace `g'="" if !`touse'
compress `g'
}
end



---------------------------------------------------

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Michael
Blasnik
Sent: Friday, October 28, 2005 10:27 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Re: Finding "near"-matches

I wrote an egen extension for soundex coding and I think I posted it SSC
a 
few years ago, but now I can't find it using search.

Michael Blasnik
michael.blasnik@verizon.net


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index