tempfile tmp
use 数据集2, clear
expand 2 if sex==.
bysort hop vname: replace sex=_n
reshape wide l u, i(hop sex) j(vname) string
isid hop sex, sort
save `tmp',replace
use 数据集1, clear
sort hop sex
merge hop sex using `tmp', uniqusing
drop if _merge==2
drop _merge
foreach x of varlist rbc0 wbc0 rbc1 wbc1{
local var=substr("`x'",1,3)
gen `x'_out=(`x'>u`var' | `x'<l`var' )
disp in yellow "******* Record no. with `x' out of range ********"
list no if `x'_out==1
}