duplicates
Finds rows that appear more than once.
What we have
report,list,tag,dropandexamples- on a named variable list, or on the whole row
Coming later
Nothing known to be missing.
How you write it
duplicates report | list | tag | drop [varlist]
Square brackets mean optional. A vertical bar means choose one.
What it does
Four things in one command. duplicates report counts them, duplicates list shows them, duplicates tag adds a column marking them so you can look at them yourself, and duplicates drop keeps one of each and removes the rest.
Name the columns that ought to identify a row — duplicates report id — and it checks for repeats on those alone, which is usually what you mean.
Watch out.
duplicates drop changes the data and cannot be undone. Run report first, always, and use preserve if you want a way back.Try it
Every example below was run after sysuse vira.sample02, clear.
. duplicates report state sector
Duplicates in terms of state sector
copies | observations surplus
-----------+--------------------------------
187 | 187 186
261 | 261 260
315 | 315 314
360 | 360 359
389 | 389 388
501 | 501 500
519 | 519 518
671 | 671 670
676 | 676 675
678 | 678 677
712 | 712 711
731 | 731 730
The same thing in pandas and in R
R
# no R form for `duplicates` yet -- see docs/r-equivalents.md