-1
input X group
21 1
62 1
98 1
12 2
87 2
end

Now I try to calculate a measure as follows:

$$ \sum_{g} \left | X_{ig}-X_{jg} \right | $$

,where $i$ or $j$ ($i \neq j$) indexes an observation. g corresponds to the group variable (here, 1 and 2)

How to calculate this number using loops?

1
  • 1
    Your latex code is not working properly. Please edit that.
    – Metrics
    Apr 18, 2013 at 22:49

1 Answer 1

2

Looks like a Gini mean difference, apart from a scaling factor. There are numerous user-written commands already in this territory. There is (unusually) a summary within the Stata manual at [R] inequality.

In addition, this is related to the second L-moment. See the lmoments command from SSC.

You need not calculate this through a double loop over indexes. It collapses to a linear combination of the order statistics.

LATER: See David's 1998 paper which is open-access at

https://doi.org/10.1214/ss/1028905831

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.