Dear All,

Hope you are well.

I am wanting to generate a variable that marks the highest recurring violation type for each business.

There are cases when one business has multiple violation repetitions of the same maximum number so I am unable to determine a way as to how I should deal with these.

For example business id 27 has 4 observations and 2 violations repeating 2 times. This means one business has 2 violation types but having the same maximum count.

Your help will be appreciated. business_id is the id of business, violation_type is the type of violation that business made and violation_rpt is how many times the business repeated that violation.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long business_id byte violation_type float violation_rpt
26  1  2
26  1  2
26  4  1
26  7  3
26  7  3
26  7  3
26 13  5
26 13  5
26 13  5
26 13  5
26 13  5
27  7  2
27  7  2
27 13  2
27 13  2
28  1  1
28  3  1
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  4 13
28  9  1
28 11  1
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
28 13 18
29  4  4
29  4  4
29  4  4
29  4  4
29  7  1
29  9  6
29  9  6
29  9  6
29  9  6
29  9  6
29  9  6
29 11  1
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
29 13 16
30  1  1
30  3  1
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  4 12
30  7  3
30  7  3
30  7  3
30  9  1
30 10  2
30 10  2
30 11  5
30 11  5
end
label values violation_type violation_type
label def violation_type 1 "Adulteration", modify
label def violation_type 3 "Unhygienic Items", modify
label def violation_type 4 "Uncleanliness", modify
label def violation_type 7 "Overpricing", modify
label def violation_type 9 "Incorrect Weights & Measures", modify
label def violation_type 10 "Non availability of price list", modify
label def violation_type 11 "Violation of regulations", modify
label def violation_type 13 "No Violation", modify