Stata version 16.1

Hello Stata experts,
I am using the following code to flag duplicates between datasets after merging the two datasets.
The code works very well when there are only two matched as duplicates. However, when there are more than two matched as duplicates, the output only keeps one matched observation, although is has been matched as a duplicate. I am hoping to alter my code so the output lists all matches as potential duplicates and not just when there are only two matches.
FYI for the code below
Code:
notif
is the flag for when an observation comes from one dataset and not the other.
Any help would be much appreciated.
Cheers,
Jonathan

Code:
use "merged Q2.dta", clear

sort yearbirth famname givename
quietly by yearbirth famname givename: gen dup = cond(_N==1,0,_n)

drop if dup == 0
drop dup

sort yearbirth famname givename notif
quietly by yearbirth famname givename notif: gen dup = cond(_N==1,0,_n)
drop if dup >0

sort yearbirth famname givename notif

keep natno stateno famname givename dob cob_name state  state notif datedx expcode
order dob famname givename notif natno cob_name stateno natno state  state datedx expcode
 
rename state STATE

export excel using "matched Q2.xlsx", sheet("dob name") sheetreplace firstrow(variables)