Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Getting saved results from ineqdec0 for groups


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Getting saved results from ineqdec0 for groups
Date   Fri, 8 Aug 2003 11:14:26 +0100

Ankur Sarin
 
> I am trying to get the gini coefficient for each of my
> (around 200) groups. I am using ineqdec0 in Stata 8
> and was trying the following:
> 
> statsby "ineqdec0 income" $S_gini , by(group1) saving
> (test_gini) replace
> 
> However,this does not work and I get a new variable
> called  _stat_1 with all missing values. Is there any
> other way to do what I am trying to?

No; this won't work for the following Stata reason. 

Stata reads your command line left to right and, 
among other things, substitutes any global and local macros
by their current values. This is _before_ you have even 
run -ineqdec0- once. Elsewhere this has been referred to 
as the "substitution first" rule. 

But the global macro S_gini is at that 
point undefined, unless perchance it is lying around from 
a previous run of -ineqdec0-. (Even then -statsby- wouldn't
work as desired.) So Stata will see as what it presumes you meant 

statsby "ineqdec0 income" , by(group1) saving
(test_gini) replace

with the consequence you describe. I don't believe
that -statsby- will work correctly with programs 
like -ineqdec0- which leave their results behind
in globals. 

But there are other ways to do it. Here's one: 

preserve 

gen Gini = . 

levels group1, local(groups)

qui foreach g of local groups { 
	ineqdec0 income if group1 == `g' 
	replace Gini = $S_gini if group1 == `g' 
}

bysort group1 : keep if _n == 1 
keep group1 Gini 
save test_gini 

restore 

For more details, see 
http://www.stata.com/support/faqs/data/foreach.html

Nick 
[email protected] 

*
*   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