-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdtalink_example.log
3970 lines (3476 loc) · 213 KB
/
dtalink_example.log
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------------------------------------------------------------------------------------------------------------------------------------------------
name: dtalink_example
log: C:\Users\kkranker\Documents\Stata\dtalink\code-dtalink\dtalink_example.log
log type: text
opened on: 9 Sep 2019, 16:45:51
.
. *! dtalink_example.do
. *! Probabilistic record linkage routine - examples
. *!
. *! This progam shows how the dtalink command might be used.
. *!
. *! By Keith Kranker
. *
. * Copyright (C) Mathematica Policy Research, Inc. This code cannot be copied, distributed or used without the express written permission of Mathematica Policy
> Research, Inc.
.
. pwd
C:\Users\kkranker\Documents\Stata\dtalink\code-dtalink
. which dtalink
.\dtalink.ado
*! dtalink.ado
*! Probabilistic record linkage or deduplication
*! By Keith Kranker
*! Mata Source Code
*! Defines classes which are called by dtalink.ado
*! dtalink is the parent class and includes shared functions
*! dtalink is used for deduplicating 1 file
*! dtalink2 extends dtalink for the case of linking 2 files
*! some functions in dtalink are replaced in the derived class, dtatlink2
. set processors `c(processors_max)'
The maximum number of processors or cores being used is 4. It can be set to any number between 1 and 4.
.
.
. ***************************************
. * Examples w/ baseball players
. ***************************************
.
. input byte id str8 first str6 middle str9 last byte yankee byte file
id first middle last yankee file
1. 1 "M." "" "Mantle" 1 0
2. 1 "Mickey" "" "Mantle" 1 0
3. 1 "Mickey" "" "Mantle" 1 0
4. 2 "Henry" "Louis" "Gehrig" 1 0
5. 2 "Lou" "" "Gehrig" 1 0
6. 3 "Babe" "" "Ruth" 1 0
7. 3 "George" "Herman" "Ruth, Jr." 1 0
8. 3 "George" "Herman" "Ruth" 0 0
9. 4 "Ted" "" "Williams" 0 0
10. 4 "Theodore" "Samuel" "Williams" 0 0
11. 5 "William" "Ted" "Cox" 0 0
12. 5 "Ted" "" "Cox" 0 0
13. 6 "Stan" "" "Williams" 0 0
14. 7 "M." "" "Mantle" 1 1
15. 7 "Mickey" "" "Mantle" 1 1
16. 8 "Henry" "Louis" "Gehrig" 1 1
17. 8 "Lou" "" "Gehrig" 1 1
18. 9 "Babe" "" "Ruth" 1 1
19. 9 "Babe" "" "Ruth, Jr" 1 1
20. 9 "George" "Herman" "Ruth, Jr" 0 1
21. 10 "Ted" "" "Williams" 0 1
22. 10 "Theodore" "Samuel" "Williams" 0 1
23. 11 "William" "Ted" "Cox" 0 1
24. 11 "Ted" "" "Cox" 0 1
25. 12 "Stan" "" "Williams" 0 1
26. end
.
. bys file (id): list, sepby(id) noobs
----------------------------------------------------------------------------------------------------------------------------------------------------------------
-> file = 0
+----------------------------------------------------+
| id first middle last yankee file |
|----------------------------------------------------|
| 1 M. Mantle 1 0 |
| 1 Mickey Mantle 1 0 |
| 1 Mickey Mantle 1 0 |
|----------------------------------------------------|
| 2 Henry Louis Gehrig 1 0 |
| 2 Lou Gehrig 1 0 |
|----------------------------------------------------|
| 3 Babe Ruth 1 0 |
| 3 George Herman Ruth, Jr. 1 0 |
| 3 George Herman Ruth 0 0 |
|----------------------------------------------------|
| 4 Ted Williams 0 0 |
| 4 Theodore Samuel Williams 0 0 |
|----------------------------------------------------|
| 5 William Ted Cox 0 0 |
| 5 Ted Cox 0 0 |
|----------------------------------------------------|
| 6 Stan Williams 0 0 |
+----------------------------------------------------+
----------------------------------------------------------------------------------------------------------------------------------------------------------------
-> file = 1
+---------------------------------------------------+
| id first middle last yankee file |
|---------------------------------------------------|
| 7 M. Mantle 1 1 |
| 7 Mickey Mantle 1 1 |
|---------------------------------------------------|
| 8 Henry Louis Gehrig 1 1 |
| 8 Lou Gehrig 1 1 |
|---------------------------------------------------|
| 9 Babe Ruth 1 1 |
| 9 Babe Ruth, Jr 1 1 |
| 9 George Herman Ruth, Jr 0 1 |
|---------------------------------------------------|
| 10 Ted Williams 0 1 |
| 10 Theodore Samuel Williams 0 1 |
|---------------------------------------------------|
| 11 William Ted Cox 0 1 |
| 11 Ted Cox 0 1 |
|---------------------------------------------------|
| 12 Stan Williams 0 1 |
+---------------------------------------------------+
. preserve
.
. // basic dedup
. drop id file
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1, cutoff(4) examples(16) describe
----------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
-------------------------+--------------------------------------------------
Blocking variables |
(None) | 0
-------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last | 8 -5 0
middle | 3 -1 0
yankee | 0 -1 0
----------------------------------------------------------------------------
41 matches were found.
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
4.00 | 3 |***
5.00 | 26 |**************************
11.00 | 9 |*********
14.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 41
The current configuration of the data is: one row per record.
Description of the new dataset:
Contains data
obs: 83
vars: 8
size: 2,573
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
_id float %9.0g Row number in original data file
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
first str8 %9s
middle str6 %9s
last str9 %9s
yankee byte %8.0g
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by: _matchID _id first middle last yankee
Note: Dataset has changed since last saved.
Examples (up to 16 rows):
+------------------------------------------------------------------------+
| _matchID _id _score _match~g first middle last yankee |
|------------------------------------------------------------------------|
1. | 1 1 5.00 Matched M. Mantle 1 |
2. | 1 2 5.00 Matched Mickey Mantle 1 |
|------------------------------------------------------------------------|
3. | 2 1 5.00 Matched M. Mantle 1 |
4. | 2 3 5.00 Matched Mickey Mantle 1 |
|------------------------------------------------------------------------|
5. | 3 1 11.00 Matched M. Mantle 1 |
6. | 3 14 11.00 Matched M. Mantle 1 |
|------------------------------------------------------------------------|
7. | 4 1 5.00 Matched M. Mantle 1 |
8. | 4 15 5.00 Matched Mickey Mantle 1 |
|------------------------------------------------------------------------|
9. | 5 2 11.00 Matched Mickey Mantle 1 |
10. | 5 3 11.00 Matched Mickey Mantle 1 |
|------------------------------------------------------------------------|
11. | 6 2 5.00 Matched Mickey Mantle 1 |
12. | 6 14 5.00 Matched M. Mantle 1 |
|------------------------------------------------------------------------|
13. | 7 2 11.00 Matched Mickey Mantle 1 |
14. | 7 15 11.00 Matched Mickey Mantle 1 |
|------------------------------------------------------------------------|
15. | 8 3 5.00 Matched Mickey Mantle 1 |
16. | 8 14 5.00 Matched M. Mantle 1 |
+------------------------------------------------------------------------+
.
. // basic dedup - with id() variable and the "fillunmatched" option
. restore, preserve
. keep if file==0
(12 observations deleted)
. drop file
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1, cutoff(4) id(id) fillunmatched describe examples(16)
----------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
-------------------------+--------------------------------------------------
Blocking variables |
(None) | 0
-------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last | 8 -5 0
middle | 3 -1 0
yankee | 0 -1 0
----------------------------------------------------------------------------
1 match was found.
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
5.00 | 1 |*
------------+------------+-----------------------------------------------------
Total | 1
The current configuration of the data is: one row per record.
Description of the new dataset:
Contains data
obs: 13
vars: 8
size: 364
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
id byte %8.0g
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
first str8 %9s
middle str6 %9s
last str9 %9s
yankee byte %8.0g
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by: _matchID id first middle last yankee
Note: Dataset has changed since last saved.
Examples (up to 16 rows):
+---------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee |
|---------------------------------------------------------------------------|
1. | 1 4 5.00 Matched Ted Williams 0 |
2. | 1 4 5.00 Matched Theodore Samuel Williams 0 |
3. | 1 6 5.00 Matched Stan Williams 0 |
+---------------------------------------------------------------------------+
. cap nois list , sepby(_matchID)
+-------------------------------------------------------------------------------+
| _matchID id _score _matchflag first middle last yankee |
|-------------------------------------------------------------------------------|
1. | 1 4 5.00 Matched Ted Williams 0 |
2. | 1 4 5.00 Matched Theodore Samuel Williams 0 |
3. | 1 6 5.00 Matched Stan Williams 0 |
|-------------------------------------------------------------------------------|
4. | 2 1 . Not matched M. Mantle 1 |
5. | 2 1 . Not matched Mickey Mantle 1 |
6. | 2 1 . Not matched Mickey Mantle 1 |
|-------------------------------------------------------------------------------|
7. | 3 2 . Not matched Henry Louis Gehrig 1 |
8. | 3 2 . Not matched Lou Gehrig 1 |
|-------------------------------------------------------------------------------|
9. | 4 3 . Not matched Babe Ruth 1 |
10. | 4 3 . Not matched George Herman Ruth 0 |
11. | 4 3 . Not matched George Herman Ruth, Jr. 1 |
|-------------------------------------------------------------------------------|
12. | 6 5 . Not matched Ted Cox 0 |
13. | 6 5 . Not matched William Ted Cox 0 |
+-------------------------------------------------------------------------------+
.
. // same thing with one caliper matching variable
. restore, preserve
. tostring id , replace format(%03.0f)
id was byte now str3
. replace id = id + "XX"
variable id was str3 now str5
(25 real changes made)
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1 1, cutoff(4) id(id) fillunmatched describe examples(16) calcweights
------------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
---------------------------+--------------------------------------------------
Blocking variables |
(None) | 0
---------------------------+--------------------------------------------------
Caliper matching variables |
yankee | 0 -1 1
---------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last | 8 -5 0
middle | 3 -1 0
------------------------------------------------------------------------------
10 matches were found.
Suggested matching weights:
-----------------------------------------------------------------------
| new_wgt_match new_wgt_no_match Caliper
---------------------------+-------------------------------------------
Caliper_matching_variables |
yankee | 0.000 0.000 1.000
---------------------------+-------------------------------------------
Exact_matching_variables |
first | 3.636 -0.624 .
middle | 3.707 -0.158 .
last | 1022.000 -1022.000 .
-----------------------------------------------------------------------
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
5.00 | 4 |****
11.00 | 3 |***
14.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 10
The current configuration of the data is: one row per record.
Description of the new dataset:
Contains data
obs: 37
vars: 9
size: 1,221
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
id str5 %9s
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
first str8 %9s
middle str6 %9s
last str9 %9s
yankee byte %8.0g
file byte %8.0g
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by: _matchID id yankee first middle last
Note: Dataset has changed since last saved.
Examples (up to 16 rows):
+--------------------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee file |
|--------------------------------------------------------------------------------------|
1. | 1 001XX 11.00 Matched M. Mantle 1 0 |
2. | 1 001XX 11.00 Matched Mickey Mantle 1 0 |
3. | 1 001XX 11.00 Matched Mickey Mantle 1 0 |
4. | 1 007XX 11.00 Matched M. Mantle 1 1 |
5. | 1 007XX 11.00 Matched Mickey Mantle 1 1 |
|--------------------------------------------------------------------------------------|
6. | 2 002XX 14.00 Matched Henry Louis Gehrig 1 0 |
7. | 2 002XX 14.00 Matched Lou Gehrig 1 0 |
8. | 2 008XX 14.00 Matched Henry Louis Gehrig 1 1 |
9. | 2 008XX 14.00 Matched Lou Gehrig 1 1 |
|--------------------------------------------------------------------------------------|
10. | 3 003XX 11.00 Matched George Herman Ruth 0 0 |
11. | 3 003XX 11.00 Matched Babe Ruth 1 0 |
12. | 3 003XX 11.00 Matched George Herman Ruth, Jr. 1 0 |
13. | 3 009XX 11.00 Matched George Herman Ruth, Jr 0 1 |
14. | 3 009XX 11.00 Matched Babe Ruth 1 1 |
15. | 3 009XX 11.00 Matched Babe Ruth, Jr 1 1 |
|--------------------------------------------------------------------------------------|
16. | 4 004XX 5.00 Matched Ted Williams 0 0 |
17. | 4 004XX 5.00 Matched Theodore Samuel Williams 0 0 |
18. | 4 006XX 5.00 Matched Stan Williams 0 0 |
+--------------------------------------------------------------------------------------+
. cap nois list , sepby(_matchID)
+--------------------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee file |
|--------------------------------------------------------------------------------------|
1. | 1 001XX 11.00 Matched M. Mantle 1 0 |
2. | 1 001XX 11.00 Matched Mickey Mantle 1 0 |
3. | 1 001XX 11.00 Matched Mickey Mantle 1 0 |
4. | 1 007XX 11.00 Matched M. Mantle 1 1 |
5. | 1 007XX 11.00 Matched Mickey Mantle 1 1 |
|--------------------------------------------------------------------------------------|
6. | 2 002XX 14.00 Matched Henry Louis Gehrig 1 0 |
7. | 2 002XX 14.00 Matched Lou Gehrig 1 0 |
8. | 2 008XX 14.00 Matched Henry Louis Gehrig 1 1 |
9. | 2 008XX 14.00 Matched Lou Gehrig 1 1 |
|--------------------------------------------------------------------------------------|
10. | 3 003XX 11.00 Matched George Herman Ruth 0 0 |
11. | 3 003XX 11.00 Matched Babe Ruth 1 0 |
12. | 3 003XX 11.00 Matched George Herman Ruth, Jr. 1 0 |
13. | 3 009XX 11.00 Matched George Herman Ruth, Jr 0 1 |
14. | 3 009XX 11.00 Matched Babe Ruth 1 1 |
15. | 3 009XX 11.00 Matched Babe Ruth, Jr 1 1 |
|--------------------------------------------------------------------------------------|
16. | 4 004XX 5.00 Matched Ted Williams 0 0 |
17. | 4 004XX 5.00 Matched Theodore Samuel Williams 0 0 |
18. | 4 006XX 5.00 Matched Stan Williams 0 0 |
|--------------------------------------------------------------------------------------|
19. | 5 004XX 14.00 Matched Ted Williams 0 0 |
20. | 5 004XX 14.00 Matched Theodore Samuel Williams 0 0 |
21. | 5 010XX 14.00 Matched Ted Williams 0 1 |
22. | 5 010XX 14.00 Matched Theodore Samuel Williams 0 1 |
|--------------------------------------------------------------------------------------|
23. | 6 004XX 5.00 Matched Ted Williams 0 0 |
24. | 6 004XX 5.00 Matched Theodore Samuel Williams 0 0 |
25. | 6 012XX 5.00 Matched Stan Williams 0 1 |
|--------------------------------------------------------------------------------------|
26. | 7 005XX 14.00 Matched Ted Cox 0 0 |
27. | 7 005XX 14.00 Matched William Ted Cox 0 0 |
28. | 7 011XX 14.00 Matched Ted Cox 0 1 |
29. | 7 011XX 14.00 Matched William Ted Cox 0 1 |
|--------------------------------------------------------------------------------------|
30. | 8 006XX 11.00 Matched Stan Williams 0 0 |
31. | 8 012XX 11.00 Matched Stan Williams 0 1 |
|--------------------------------------------------------------------------------------|
32. | 9 006XX 5.00 Matched Stan Williams 0 0 |
33. | 9 010XX 5.00 Matched Ted Williams 0 1 |
34. | 9 010XX 5.00 Matched Theodore Samuel Williams 0 1 |
|--------------------------------------------------------------------------------------|
35. | 10 010XX 5.00 Matched Ted Williams 0 1 |
36. | 10 010XX 5.00 Matched Theodore Samuel Williams 0 1 |
37. | 10 012XX 5.00 Matched Stan Williams 0 1 |
+--------------------------------------------------------------------------------------+
. return list
scalars:
r(scores_max) = 14
r(scores_min) = 5
r(scores_sd) = 4.06201920231798
r(scores_mean) = 9.5
r(pairsnum) = 10
r(N) = 24
r(misscheck) = 1
r(cutoff) = 4
r(numfiles) = 1
macros:
r(new_wgt_specs) : "first 3.636203 -.6237977 middle 3.706592 -.1575942 last 1022 -1022 yankee 0 0 1"
r(dstnegwgt) : "-1"
r(dstposwgt) : "0"
r(dstradii) : "1"
r(dstvars) : "yankee"
r(mtcnegwgt) : "-3 -1 -5"
r(mtcposwgt) : "3 3 8"
r(mtcvars) : "first middle last"
r(idvar) : "id"
r(cmdline) : "dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1 1, cutoff(4) id(id) fillunmatched describe examples(16) calcweights"
r(cmd) : "dtalink"
matrices:
r(new_weights) : 4 x 3
r(new_dst_negwgt) : 1 x 1
r(new_dst_poswgt) : 1 x 1
r(new_mtc_negwgt) : 3 x 1
r(new_mtc_poswgt) : 3 x 1
.
. // dedup where we keep only the "best" _matchid for each id --- notice that we no longer have matches between 4 and 6, 4 and 10, 4 and 12, or 10 and 12
. restore, preserve
. drop file
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1, cutoff(4) id(id) bestmatch noweight
10 matches were found.
Keeping best match for each id
(3 pairs deleted.)
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
5.00 | 1 |*
11.00 | 3 |***
14.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 7
The current configuration of the data is: one row per record.
. list , sepby(_matchID)
+----------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee |
|----------------------------------------------------------------------------|
1. | 1 1 11.00 Matched M. Mantle 1 |
2. | 1 1 11.00 Matched Mickey Mantle 1 |
3. | 1 1 11.00 Matched Mickey Mantle 1 |
4. | 1 7 11.00 Matched M. Mantle 1 |
5. | 1 7 11.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
6. | 2 2 14.00 Matched Henry Louis Gehrig 1 |
7. | 2 2 14.00 Matched Lou Gehrig 1 |
8. | 2 8 14.00 Matched Henry Louis Gehrig 1 |
9. | 2 8 14.00 Matched Lou Gehrig 1 |
|----------------------------------------------------------------------------|
10. | 3 3 11.00 Matched Babe Ruth 1 |
11. | 3 3 11.00 Matched George Herman Ruth 0 |
12. | 3 3 11.00 Matched George Herman Ruth, Jr. 1 |
13. | 3 9 11.00 Matched Babe Ruth 1 |
14. | 3 9 11.00 Matched Babe Ruth, Jr 1 |
15. | 3 9 11.00 Matched George Herman Ruth, Jr 0 |
|----------------------------------------------------------------------------|
16. | 5 4 14.00 Matched Ted Williams 0 |
17. | 5 4 14.00 Matched Theodore Samuel Williams 0 |
18. | 5 10 14.00 Matched Ted Williams 0 |
19. | 5 10 14.00 Matched Theodore Samuel Williams 0 |
|----------------------------------------------------------------------------|
20. | 7 5 14.00 Matched Ted Cox 0 |
21. | 7 5 14.00 Matched William Ted Cox 0 |
22. | 7 11 14.00 Matched Ted Cox 0 |
23. | 7 11 14.00 Matched William Ted Cox 0 |
|----------------------------------------------------------------------------|
24. | 8 6 11.00 Matched Stan Williams 0 |
25. | 8 12 11.00 Matched Stan Williams 0 |
|----------------------------------------------------------------------------|
26. | 9 6 5.00 Matched Stan Williams 0 |
27. | 9 10 5.00 Matched Ted Williams 0 |
28. | 9 10 5.00 Matched Theodore Samuel Williams 0 |
+----------------------------------------------------------------------------+
.
. // dedup with "combined" matched sets --- notice that 4, 6, 10, and 12 are now in a single matched set
. restore, preserve
. drop file
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1, cutoff(4) id(id) combinesets noweight
10 matches were found.
(dtalink::combinesets required 1 iteration to achieve convergence)
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
5.00 | 4 |****
11.00 | 3 |***
14.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 10
The current configuration of the data is: one row per record.
. list , sepby(_matchID)
+----------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee |
|----------------------------------------------------------------------------|
1. | 1 1 11.00 Matched M. Mantle 1 |
2. | 1 1 11.00 Matched Mickey Mantle 1 |
3. | 1 1 11.00 Matched Mickey Mantle 1 |
4. | 1 7 11.00 Matched M. Mantle 1 |
5. | 1 7 11.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
6. | 2 2 14.00 Matched Henry Louis Gehrig 1 |
7. | 2 2 14.00 Matched Lou Gehrig 1 |
8. | 2 8 14.00 Matched Henry Louis Gehrig 1 |
9. | 2 8 14.00 Matched Lou Gehrig 1 |
|----------------------------------------------------------------------------|
10. | 3 3 11.00 Matched Babe Ruth 1 |
11. | 3 3 11.00 Matched George Herman Ruth 0 |
12. | 3 3 11.00 Matched George Herman Ruth, Jr. 1 |
13. | 3 9 11.00 Matched Babe Ruth 1 |
14. | 3 9 11.00 Matched Babe Ruth, Jr 1 |
15. | 3 9 11.00 Matched George Herman Ruth, Jr 0 |
|----------------------------------------------------------------------------|
16. | 4 4 14.00 Matched Ted Williams 0 |
17. | 4 4 14.00 Matched Theodore Samuel Williams 0 |
18. | 4 6 11.00 Matched Stan Williams 0 |
19. | 4 10 14.00 Matched Ted Williams 0 |
20. | 4 10 14.00 Matched Theodore Samuel Williams 0 |
21. | 4 12 11.00 Matched Stan Williams 0 |
|----------------------------------------------------------------------------|
22. | 7 5 14.00 Matched Ted Cox 0 |
23. | 7 5 14.00 Matched William Ted Cox 0 |
24. | 7 11 14.00 Matched Ted Cox 0 |
25. | 7 11 14.00 Matched William Ted Cox 0 |
+----------------------------------------------------------------------------+
.
. // dedup with ties
. restore, preserve
. drop file
. dtalink first 3 -3 middle 3 -3 last 3 -3 yankee 3 -3, cutoff(4) id(id) bestmatch noweight ties
6 matches were found.
Keeping best match for each id (keeping ties)
(0 pairs deleted.)
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
9.00 | 3 |***
12.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 6
The current configuration of the data is: one row per record.
. list , sepby(_matchID)
+----------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee |
|----------------------------------------------------------------------------|
1. | 1 1 9.00 Matched M. Mantle 1 |
2. | 1 1 9.00 Matched Mickey Mantle 1 |
3. | 1 1 9.00 Matched Mickey Mantle 1 |
4. | 1 7 9.00 Matched M. Mantle 1 |
5. | 1 7 9.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
6. | 2 2 12.00 Matched Henry Louis Gehrig 1 |
7. | 2 2 12.00 Matched Lou Gehrig 1 |
8. | 2 8 12.00 Matched Henry Louis Gehrig 1 |
9. | 2 8 12.00 Matched Lou Gehrig 1 |
|----------------------------------------------------------------------------|
10. | 3 3 9.00 Matched Babe Ruth 1 |
11. | 3 3 9.00 Matched George Herman Ruth 0 |
12. | 3 3 9.00 Matched George Herman Ruth, Jr. 1 |
13. | 3 9 9.00 Matched Babe Ruth 1 |
14. | 3 9 9.00 Matched Babe Ruth, Jr 1 |
15. | 3 9 9.00 Matched George Herman Ruth, Jr 0 |
|----------------------------------------------------------------------------|
16. | 4 4 12.00 Matched Ted Williams 0 |
17. | 4 4 12.00 Matched Theodore Samuel Williams 0 |
18. | 4 10 12.00 Matched Ted Williams 0 |
19. | 4 10 12.00 Matched Theodore Samuel Williams 0 |
|----------------------------------------------------------------------------|
20. | 5 5 12.00 Matched Ted Cox 0 |
21. | 5 5 12.00 Matched William Ted Cox 0 |
22. | 5 11 12.00 Matched Ted Cox 0 |
23. | 5 11 12.00 Matched William Ted Cox 0 |
|----------------------------------------------------------------------------|
24. | 6 6 9.00 Matched Stan Williams 0 |
25. | 6 12 9.00 Matched Stan Williams 0 |
+----------------------------------------------------------------------------+
.
. // dedup with ties
. restore, preserve
. drop file
. dtalink first 3 -3 middle 3 -3 last 3 -3 yankee 3 -3, cutoff(4) id(id) bestmatch noweight ties combinesets
6 matches were found.
Keeping best match for each id (keeping ties)
(0 pairs deleted.)
(dtalink::combinesets required 0 iteration to achieve convergence)
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
9.00 | 3 |***
12.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 6
The current configuration of the data is: one row per record.
. list , sepby(_matchID)
+----------------------------------------------------------------------------+
| _matchID id _score _match~g first middle last yankee |
|----------------------------------------------------------------------------|
1. | 1 1 9.00 Matched M. Mantle 1 |
2. | 1 1 9.00 Matched Mickey Mantle 1 |
3. | 1 1 9.00 Matched Mickey Mantle 1 |
4. | 1 7 9.00 Matched M. Mantle 1 |
5. | 1 7 9.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
6. | 2 2 12.00 Matched Henry Louis Gehrig 1 |
7. | 2 2 12.00 Matched Lou Gehrig 1 |
8. | 2 8 12.00 Matched Henry Louis Gehrig 1 |
9. | 2 8 12.00 Matched Lou Gehrig 1 |
|----------------------------------------------------------------------------|
10. | 3 3 9.00 Matched Babe Ruth 1 |
11. | 3 3 9.00 Matched George Herman Ruth 0 |
12. | 3 3 9.00 Matched George Herman Ruth, Jr. 1 |
13. | 3 9 9.00 Matched Babe Ruth 1 |
14. | 3 9 9.00 Matched Babe Ruth, Jr 1 |
15. | 3 9 9.00 Matched George Herman Ruth, Jr 0 |
|----------------------------------------------------------------------------|
16. | 4 4 12.00 Matched Ted Williams 0 |
17. | 4 4 12.00 Matched Theodore Samuel Williams 0 |
18. | 4 10 12.00 Matched Ted Williams 0 |
19. | 4 10 12.00 Matched Theodore Samuel Williams 0 |
|----------------------------------------------------------------------------|
20. | 5 5 12.00 Matched Ted Cox 0 |
21. | 5 5 12.00 Matched William Ted Cox 0 |
22. | 5 11 12.00 Matched Ted Cox 0 |
23. | 5 11 12.00 Matched William Ted Cox 0 |
|----------------------------------------------------------------------------|
24. | 6 6 9.00 Matched Stan Williams 0 |
25. | 6 12 9.00 Matched Stan Williams 0 |
+----------------------------------------------------------------------------+
.
.
. // basic dedup - wide format
. restore, preserve
. keep if file==0
(12 observations deleted)
. drop file id
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 0 -1, cutoff(4) wide nomerge describe examples(16)
----------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
-------------------------+--------------------------------------------------
Blocking variables |
(None) | 0
-------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last | 8 -5 0
middle | 3 -1 0
yankee | 0 -1 0
----------------------------------------------------------------------------
9 matches were found.
Distribution of matched pair scores, among pairs with score >=4:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
4.00 | 1 |*
5.00 | 7 |*******
11.00 | 1 |*
------------+------------+-----------------------------------------------------
Total | 9
The current configuration of the data is: one row per matched pair.
Description of the new dataset:
Contains data
obs: 9
vars: 5
size: 45
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
_id0 byte %9.0g Row number in original data file
_id1 byte %9.0g Row number in original data file
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by:
Note: Dataset has changed since last saved.
Examples (up to 16 rows):
+--------------------------------------------+
| _matchID _id0 _id1 _score _match~g |
|--------------------------------------------|
1. | 1 1 2 5.00 Matched |
2. | 2 1 3 5.00 Matched |
|--------------------------------------------|
3. | 3 2 3 11.00 Matched |
|--------------------------------------------|
4. | 4 4 5 5.00 Matched |
|--------------------------------------------|
5. | 5 6 8 4.00 Matched |
|--------------------------------------------|
6. | 6 9 10 5.00 Matched |
7. | 7 9 13 5.00 Matched |
|--------------------------------------------|
8. | 8 10 13 5.00 Matched |
|--------------------------------------------|
9. | 9 11 12 5.00 Matched |
+--------------------------------------------+
.
. // basic dedup with blocks
. restore, preserve
. keep if file==0
(12 observations deleted)
. drop file id
. replace yankee = . in 4/5
(2 real changes made, 2 to missing)
. dtalink first 3 -3 middle 2 -1 last 6 -5 yankee 2 0, cutoff(3) block(yankee | last) describe examples(16)
----------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
-------------------------+--------------------------------------------------
Blocking variables |
last (1) | 0
yankee (1) | 0
-------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last (2) | 6 -5 0
middle | 2 -1 0
yankee (2) | 2 0 0
----------------------------------------------------------------------------
Starting 2 blocks for blocking set 1 of 2: yankee. Each dot is 1 block.
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..
Starting 5 blocks for blocking set 2 of 2: last. Each dot is 1 block.
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....
9 matches were found.
Distribution of matched pair scores, among pairs with score >=3:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
3.00 | 2 |**
5.00 | 6 |******
11.00 | 1 |*
------------+------------+-----------------------------------------------------
Total | 9
The current configuration of the data is: one row per record.
Description of the new dataset:
Contains data
obs: 19
vars: 8
size: 589
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
_id float %9.0g Row number in original data file
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
first str8 %9s
middle str6 %9s
last str9 %9s
yankee byte %8.0g
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by: _matchID _id first middle last yankee
Note: Dataset has changed since last saved.
Examples (up to 16 rows):
+----------------------------------------------------------------------------+
| _matchID _id _score _match~g first middle last yankee |
|----------------------------------------------------------------------------|
1. | 1 1 5.00 Matched M. Mantle 1 |
2. | 1 2 5.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
3. | 2 1 5.00 Matched M. Mantle 1 |
4. | 2 3 5.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
5. | 3 2 11.00 Matched Mickey Mantle 1 |
6. | 3 3 11.00 Matched Mickey Mantle 1 |
|----------------------------------------------------------------------------|
7. | 4 4 3.00 Matched Henry Louis Gehrig . |
8. | 4 5 3.00 Matched Lou Gehrig . |
|----------------------------------------------------------------------------|
9. | 5 6 3.00 Matched Babe Ruth 1 |
10. | 5 8 3.00 Matched George Herman Ruth 0 |
|----------------------------------------------------------------------------|
11. | 6 9 5.00 Matched Ted Williams 0 |
12. | 6 10 5.00 Matched Theodore Samuel Williams 0 |
|----------------------------------------------------------------------------|
13. | 7 9 5.00 Matched Ted Williams 0 |
14. | 7 13 5.00 Matched Stan Williams 0 |
|----------------------------------------------------------------------------|
15. | 8 10 5.00 Matched Theodore Samuel Williams 0 |
16. | 8 13 5.00 Matched Stan Williams 0 |
+----------------------------------------------------------------------------+
.
. // basic merge
. restore, preserve
. drop id
. dtalink first 3 -3 middle 3 -1 last 8 -5 yankee 2 0, cutoff(3) source(file) describe
----------------------------------------------------------------------------
Usage type and variable |
name | Match weight No match weight Caliper
-------------------------+--------------------------------------------------
Blocking variables |
(None) | 0
-------------------------+--------------------------------------------------
Exact matching variables |
first | 3 -3 0
last | 8 -5 0
middle | 3 -1 0
yankee | 2 0 0
----------------------------------------------------------------------------
26 matches were found.
Distribution of matched pair scores, among pairs with score >=3:
Probabilist |
ic matching |
score | Freq.
------------+------------+-----------------------------------------------------
3.00 | 1 |*
5.00 | 1 |*
7.00 | 13 |*************
13.00 | 8 |********
16.00 | 3 |***
------------+------------+-----------------------------------------------------
Total | 26
The current configuration of the data is: one row per record.
Description of the new dataset:
Contains data
obs: 54
vars: 9
size: 1,728
----------------------------------------------------------------------------------------------------------------------------------------------------------------
storage display value
variable name type format label variable label
----------------------------------------------------------------------------------------------------------------------------------------------------------------
_matchID byte %10.0g Matched set identifier
file byte %8.0g
_id float %9.0g Row number in original data file
_score byte %9.2f Probabilistic matching score
_matchflag byte %11.0g _mtchflg Match indicator
first str8 %9s
middle str6 %9s
last str9 %9s
yankee byte %8.0g
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Sorted by: _matchID file _id first middle last yankee
Note: Dataset has changed since last saved.
. gsort -_score _matchID file _id
. list, sepby(_matchID)
+---------------------------------------------------------------------------------------+