Hello,

I have the following stylized dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(group grade) str6 name float what_i_want
1  2 "Brown"  73
1  5 "Yellow" 34
1 10 "Black"  73
2  1 "White"  84
2  3 "Push"   44
2  5 "Ying"   36
2  9 "Smith"  84
end

what_i_want is the person-specific squared differences in grades to the other group members. So for Brown it is (2-5)^2+(2-10)^2 = 9 + 64 = 73 and for Yellow it is (5-2)^2 + (5-10)^2 = 9 + 25 = 34 and so on.

The number of persons within a group might vary. In principle, the grades can also be negative.

Best,
Julian