Hi,

I am trying to create by group sums of a variable and my data includes three variables: a district id (x) , year (y) , and a count variable (z). I want to create a variable that sums all counts in a given year but that is distinct for each district- specifically, for a given value of x, the value of z for that district leaves out values of z from that district. I know rangestat is one way of achieving this, but I am not sure how to specify the "excludeself" option when the group variable I want to exclude is different from that which I am summing over.

Without the leave-one-out approach, I am doing the following:
Code:
by y: egen yeartotal= sum(z)
and not sure how to modify the following to achieve this:
Code:
rangestat (sum) yeartotal = z, by(y)
Thanks in advance.