/*******************************************************/ /* Program to check for name mismatches */ /* List of standardized names kept in "names.dta" */ /* If current names don't all match, generates */ /* diagnostics file and stop execution */ /* */ /* Syntax: namecheck varname */ /* where varname is name variable used in both files */ /* NOTE: You first have to create a list of "correct" */ /* names and save in "names.dta". You also have*/ /* to use the same variable name for the naming */ /* variable in both locations */ /*******************************************************/ capture program drop namecheck program define namecheck quietly { preserve keep `1' duplicates drop merge 1:1 `1' using "names.dta" count if _merge==1 local r1=`r(N)' count if _merge==2 local r2=`r(N)' } if `r1'>0 & `r2'>0 { quietly { drop if _merge==3 rename _merge matchtype sort `1' gen sequence=_n reshape wide `1', i(sequence) j(matchtype) rename `1'1 `1' rename `1'2 standard_`1' order standard_`1' `1' drop sequence export excel using namelist, firstrow(variables) nolabel replace } display as smcl "Name mismatches written to {browse "`"namelist.xls}"'" error(1) } else { display "No name mismatches problems found." } restore end *end of program namecheck* quietly { wbopendata, indicators(SP.POP.TOTL) long clear nometadata drop if region=="NA" | region=="" rename countryname Country keep Country duplicates drop save names.dta, replace } /*Start your code here*/