Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Keeping only unique combination of observations in 2 columns

    Hi
    I have observations in two columns. Many of the values get repeated. I would like to keep only unique combination of observations for the two variables/columns, i.e. none of the observation gets repeated in any other row (if possible). I have pasted below a subset of the data. Looking forward to your suggestions. Thank You.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(id index)
      1  325
      1  390
      1  628
      2  119
      2  592
      2  657
      3  693
      3 1012
      3  694
      4  945
      4   20
      4  166
      7  198
      7   73
      7  655
     24  202
     24  635
     24  586
     25 1081
     25  946
     25  484
     26  657
     26  796
     26  119
     29  467
     29  652
     29  653
     30  125
     30  480
     30 1006
     31  481
     31  265
     31  130
     32  682
     32   65
     32   63
     34 1039
     34 1038
     34   28
     42 1084
     42  779
     42 1001
     43  516
     43  778
     43   88
     43  514
     44  111
     44  192
     44  462
     57   50
     57  629
     57  343
     58  965
     58  542
     58 1053
     59  608
     59  609
     59  703
     60  629
     60  343
     60   50
     61  608
     61  703
     61  609
     74  467
     74  156
     74  264
     75   98
     75  112
     75  769
     82  702
     82  292
     82  710
     89  555
     89  605
     89  311
     90  376
     90  479
     90  680
     92  616
     92  953
     92 1067
     93  322
     93  321
     93  584
     94  321
     94  374
     94  787
    100  399
    100  340
    100 1083
    107  977
    107  786
    107  711
    108  751
    108  934
    108  966
    113  528
    113  474
    113  541
    116  446
    116  143
    116  582
    121 1083
    121  927
    121  399
    122  899
    122  782
    122   40
    123    6
    123  411
    123  410
    126  704
    126  261
    126  732
    127  143
    127  446
    127  582
    137  195
    137  663
    137  194
    153  424
    153   18
    153  141
    165  740
    165  541
    165  766
    175  142
    175   39
    175  771
    197  144
    197  581
    197  705
    204  613
    204  612
    204  549
    208  675
    208  679
    208   91
    209  597
    209  615
    209 1048
    210 1048
    210  615
    210  597
    211  679
    211  675
    211   91
    212  828
    212  659
    212   86
    213  597
    213 1048
    213  615
    214  678
    214  495
    214  828
    215  678
    215  495
    215  615
    216  464
    216  789
    216  668
    217  597
    217  615
    217 1048
    218   91
    218  675
    218  679
    219  789
    219  464
    219  668
    220  678
    220  828
    220  495
    221  374
    221  321
    221  787
    222 1048
    222  677
    222  597
    223  470
    223  786
    223  616
    224  411
    224    6
    224  410
    225  595
    225  475
    225  442
    226  580
    226  264
    226  364
    227  549
    227  482
    227  914
    232   33
    232  273
    232  117
    233  946
    end

  • #2
    Code:
    bys id index: keep if _n==1
    Last edited by Andrew Musau; 27 Feb 2020, 03:53.

    Comment


    • #3
      If I understood correctly, - duplicates drop - can do the trick as well.
      Best regards,

      Marcos

      Comment

      Working...
      X