*! version 1.0.0 02/02/93 extrname utility; STB-13: dm13 program define _crcexn5 /* lname fname mname sx s cs */ version 3.0 local lname "`1'" local fname "`2'" local mname "`3'" local sx "`4'" local suffix "`5'" local csuffix "`6'" tempvar tofix bad quietly { gen byte `tofix' = `lname'=="`suffix'" & `sx'=="" capture assert `tofix'==0 if _rc==0 { exit } local d=length("`csuffix'") minlen `d' `sx' replace `sx'="`csuffix'" if `tofix' /* try the middle name for last name */ local type : type `mname' minlen `type' `lname' replace `lname'=`mname' if `tofix' replace `mname'="" if `tofix' compress `lname' `mname' gen byte `bad'=`tofix' & `lname' /* still */ =="" capture assert `bad'==0 if _rc==0 { exit } /* use the first name for last name */ local type : type `fname' minlen `type' `lname' replace `lname' = `fname' if `bad' replace `fname' = "" if `bad' compress `fname' `lname' } end exit /* lname fname mname sx "suffix" "csuffix" Check of lname contains "suffix" (e.g., "Jr") Check the sx is empty in such cases. Put corrected suffix "csuffix" (e.g., "Jr.") in sx. Find a new last name from either fname or mname */