Announcement

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

  • Keep highest value by multiple groups

    With data organized like below, I want to keep only the row containing the highest -counter- value within respondent-category groups. So for respondent 100, category 0, the highest -counter- value would be 3, and that's the row I'd want to keep within that 100-0 grouping. What is the most efficient way to do this? Thanks in advance.


    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int respondent byte(category counter score)
    100 0 1 3
    100 0 2 1
    100 0 3 10
    100 1 1 4
    100 1 2 20
    100 1 3 14
    100 1 4 4
    100 2 1 13
    100 2 2 2
    101 0 1 3
    101 0 2 4
    101 0 3 2
    101 0 4 3
    101 1 1 17
    101 1 2 2
    101 2 1 12
    101 2 2 11
    101 2 3 3
    end
    [/CODE]

  • #2
    Code:
    by respondent category (counter), sort: keep if _n == _N

    Comment

    Working...
    X