Statalist


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

st: RE: RV: RE: Sum over all possible combinations


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RV: RE: Sum over all possible combinations
Date   Mon, 23 Jul 2007 19:11:41 +0100

That can happen if you don't tell us the _real_ problem. 
And you haven't yet, as "a somewhat complex weighting scheme" 
could mean various things. 

But yes, Mata would help a lot. You just need to loop doubly 
over your data. Sorting your data and looping only over non-negative
differences and then doubling might help. 

Nick 
[email protected] 

J E
 
> 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.

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index