Add an option mygini(name) i.e. replace the line
[, BYgroup(varname numeric) Welfare Summarize ]
with:
[, BYgroup(varname numeric) Welfare Summarize mygini(name) ]
and then replace the line:
drop `lgmeank' `ginik' `thetak' `nk' `pyk'
with:
if "`mygini'"!="" g double `mygini'=`ginik'
but you can also used the returned results like so:
gen gini = .
egen group = group(storeid prodid)
qui ineqdeco price, by(group)
su group, meanonly
qui forval i = 1/`r(max)' {
replace gini = r(gini_`i') if group == `i'
}
On Wed, Dec 10, 2008 at 5:07 PM, Austin Nichols <[email protected]> wrote:
> Victor Bennett:
> It would be faster to write your own code, since -ineqdeco- (on SSC)
> does a lot of calculations you don't need. That said, I think you can
> clone ineqdeco.ado as myineqdeco.ado (replacing "program ineqdeco"
> with "program myineqdeco") and add
>
> ren `ginik' mygini
>
> in the loop that begins
> if "`bygroup'" != "" {
>
> to keep the temporary variable with bygroup-specific Ginis on the
> data. Even better, you can add a -stub- option that keeps all the
> results as variables on the data.
>
> On Wed, Dec 10, 2008 at 4:44 PM, Nick Cox <[email protected]> wrote:
>> A cleaner way to do what you are doing
>>
>> gen gini = .
>> egen group = group(storeid prodid)
>> su group, meanonly
>> forval i = 1/`r(max)' {
>> ineqdeco price if group == `i'
>> replace gini = r(gini) if group == `i'
>> }
>>
>> Nick
>> [email protected]
>>
>> Victor Bennett
>>
>> Does anyone have suggestions on how to speed up a loop that calculates
>> many many gini coefficients with ineqdeco?
>>
>> I'm building a data set for doing some comparison of price variation
>> using Gini coefficients from ineqdeco. Each observation is a sale of
>> an item at a particular store. Each item can be sold at multiple
>> stores, and each store sells multiple items.
>>
>> I would like to store the Gini for each store x product combination.
>> If egen did this, the easy way would be egen gini=gini(price),
>> by(store product).
>>
>> The way I'm doing it right now is:
>>
>> gen gini = .
>> levels storeid,local(stores)
>> foreach store of local stores {
>> levels prodid if storeid==`store', local(prodInStore)
>> foreach prod of local prodInStore {
>> ineqdeco price if prodid == `prod'&storeid==`store'
>> replace gini = $S_gini if prodid == `prod'&storeid==`store'
>> }
>> }
>>
>> It seems like there is a way to do this with bygroup() on ineqdeco,
>> but I can't figure out how to extract and store the coefficients.
>> Also, its not clear that it would be any faster. Would it?
>>
>> Is there an alternate library that will calculate gini without
>> calculating the other dispersion measures?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/