Hi, Apologies for the vague title. I am trying to create a new variable which is the sum of the 'ssqrd' as listed below but I want to sort it by 'occupation'. I used the following code to do this before:
Code:
egen HHI= sum(ssqrd), by(OCCUPATION time)
But there is one issue, I want to add ssqrd only once for each caste per occupation. for example- if ssqrd for- Brahmins= 0.5675, Upper caste=0.5864, OBC=0.6443... I want my HHI to show value of 0.5675 + 0.5864 + 0.6443. Instead of that, the above code is adding all the values if the CASTE is repeated for the same occupation. So if there are 10 Brahmins in my dataset involved in Occupation 1, what this does is 0.5675*10 + (Rest of the Values). I particularly want to get rid of the *10 here.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float CASTE double(OCCUPATION ssqrd)
6  .                   .
4  .                   .
7  .                   .
1  .                   .
6  .                   .
4  .                   .
3 63  .12891192949776026
3  .                   .
2  .                   .
4 98  .04029183669790953
1 43 .005133198245092206
3  .                   .
3 63  .12891192949776026
3  .                   .
2  .                   .
3  .                   .
3  .                   .
2  .                   .
3  .                   .
3  .                   .
6  .                   .
2  .                   .
4  .                   .
4  .                   .
2  .                   .
2  .                   .
4  .                   .
4  .                   .
6  .                   .
4  .                   .
2  .                   .
4  .                   .
3  .                   .
4  .                   .
2  .                   .
5  .                   .
3  .                   .
3  8  .07321799307958476
3  .                   .
2  .                   .
2 63  .00806835999564883
6 52  .01222975778546713
4 53  .09494997295835586
3 15  .06689460346578277
3 63  .13619516038503374
3  .                   .
3  .                   .
8  .                   .
3  .                   .
4  .                   .
end
label values CASTE GROUPS
label def GROUPS 1 "Brahmin 1", modify
label def GROUPS 2 "Forward caste 2", modify
label def GROUPS 3 "OBC 3", modify
label def GROUPS 4 "Dalit 4", modify
label def GROUPS 5 "Adivasi 5", modify
label def GROUPS 6 "Muslim 6", modify
label def GROUPS 7 "Christian, Sikh, Jain 7", modify
label def GROUPS 8 "Christian, Sikh, Jain 8", modify