/* This sends summary hhousehold match rates to the logfile. It drops observations from the unmatched year 2 households & moves observations from the unmatched year 1 households to a temporary file, nomatch.dta, to be returned after the individual matches (within matched households) are complete. The maximum number of individual matches is the sum over households of the year1-year2 minimum number of members. */ use ${temploc}junk,clear sort $family $match1 mac def firstx : tempvar mac def x1 : tempvar mac def x2 : tempvar qui by $family:gen byte $firstx=_n==1 qui by $family:gen byte $x1=year==$yr1 qui by $family:replace $x1=sum($x1) qui by $family:replace $x1=$x1[_N] qui by $family:gen byte $x2=year==$yr2 qui by $family:replace $x2=sum($x2) qui by $family:replace $x2=$x2[_N] count if $firstx & $x1 local h=_result(1) count if $firstx & $x1 & $x2 local hm=_result(1) count if $firstx & $x1 & !$x2 local hu=_result(1) ${debug}log on noisily display " " noisily display "MIS ${mo$j}" noisily display " Year 1 Households = `h'" noisily display " Matched = `hm' (" %4.3f `hm'/`h' ")" noisily display " Not Matched = `hu'" noisily display " " count if $firstx & $x2 local h=_result(1) count if $firstx & $x1 & $x2 local hm=_result(1) count if $firstx & $x2 & !$x1 local hu=_result(1) noisily display " Year 2 Households = `h'" noisily display " Matched = `hm' (" %4.3f `hm'/`h' ")" noisily display " Not Matched = `hu'" noisily display " " count if year==$yr1 local p=_result(1) count if year==$yr1 & $x2 local pm=_result(1) count if year==$yr1 & !$x2 local pu=_result(1) noisily display " Year 1 People = `p' noisily display " In Matched Households = `pm' (" %4.3f `pm'/`p' ")" noisily display " In Unmatched Households = `pu'" gen zkky=min($x1,$x2) replace zkky=zkky*$firstx replace zkky=sum(zkky) local q=zkky[_N] drop zkky noisily display " Max. Potential Matches = `q' (" %4.3f `q'/`pm' ")" count if year==$yr2 local p=_result(1) count if year==$yr2 & $x1 local pm=_result(1) count if year==$yr2 & !$x1 local pu=_result(1) noisily display " " noisily display " Year 2 People = `p' noisily display " In Matched Households = `pm' (" %4.3f `pm'/`p' ")" noisily display " In Unmatched Households = `pu'" ${debug}log off if $retain < 3 { drop if $x1==0 } if $retain>1 { save ${temploc}junk,replace keep if $x2==0 | $x1==0 drop $firstx $x1 $x2 replace level=-1 save ${temploc}nomatch,replace use ${temploc}junk } drop if $x2==0 | $x1==0 drop $firstx $x1 $x2 save ${temploc}junk,replace exit 0