Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RV: RE: Sum over all possible combinations


From   "J E" <je_123@hotmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: RV: RE: Sum over all possible combinations
Date   Sun, 22 Jul 2007 15:42:56 -0500

Thanks to Nick and to Sebastian for their initial responses to my query I am afraid, however, that both responses, do not fully solve the problem I need to tackle

In the case of Nick's comment (that the Sum of absolute differences over all possible combinations is related to the gini coefficient and to lmoment indicators): is true. However since I need to reweight each absolute difference by a somewhat complex weighting scheme (I did not posted the weights to avoid adding complexities to my query), the shortcut suggested by Nick would not work in my case.

The strategy proposed by Sebastian does work:

bys group: gen g_i=_n
tempfile join_file
preserve
ren y_i y_k
save `join_file', replace
restore
joinby group using `join_file', unmatched(none)
bys group: egen sum_dy = sum(abs(y_i - y_k))
bys group g_i: keep if _n==1

However it only works for relatively small data sets. Very rapidly the strategy eats all my memory since it needs to save in memory a data base containing all possible combinations.

Giving this let me ask if somebody will know an alternative to Sebastian strategy that will not require this intermediate step. Alternatively, will the use of mata will allow me to get around this problem.

thanks in advance!

Julio

-----Mensaje original-----
De: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] En nombre de Nick Cox
Enviado el: Domingo, 22 de Julio de 2007 12:41 p.m.
Para: statalist@hsphsun2.harvard.edu
Asunto: st: RE: Sum over all possible combinations

This sounds like

number in group * Gini mean difference * 2

As the second L-moment is

Gini mean difference / 2

-lmoments- from SSC will get you most of the way there.

For example,

lmoments varname, by(group) gen(n=n sad=l2) replace sad = 4 * n * l2

Check this out with hand-calculations for a toy example.

Nick
n.j.cox@durham.ac.uk

Julio E


I am interested in computing the sum of the absolute value of all
possible differences within a group of my sample.

Suppose that the variable "group" denotes the variable indicating the
group to which an individual belongs and Y is an outcome variable.
I am interested
in computing

sum of abs (Yi-Yj) for all i and j  belonging to group K

My programming skills are almost none. Can somebody help me out
regarding an efficient way of computing such statistic?
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar - get it now! http://toolbar.msn.click-url.com/go/onm00200415ave/direct/01/

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index