Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: Computing proportions within generated reference groups

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: Computing proportions within generated reference groups Date Tue, 30 Aug 2011 16:41:38 +0100

Let's suppose that key individuals are identified by an indicator
variable -key- and also that no group has more than one such
individual. Then it sounds like

bysort group (key income): gen cumul = sum(income < income[_N]) if key[_N]
by group : replace cumul = 1 - cumul/(_N - 1)

Nick

On Tue, Aug 30, 2011 at 4:18 PM, Namrata Chindarkar
<namrata.chindarkar@gmail.com> wrote:
> Thank you for your responses.
>
> A reference group is generated by year, country, age category, and
> education category
>
> egen group = group(year country age_cat edu_cat)
>
> Each individual is an observation in one of the reference groups. No
> individual belongs to more than one reference group.
>
> Namrata
>
> On Tue, Aug 30, 2011 at 11:11 AM, Nick Cox <njcoxstata@gmail.com> wrote:
>> No; it is most unlikely that you need to write a Stata program to do this.
>>
>> It is an application of -by:- and -sum()- and likely to be about two
>> lines of code.
>>
>> To suggest good code I would need to know more about how that
>> individual is defined.
>>
>> Nick
>>
>> On Tue, Aug 30, 2011 at 3:54 PM, Namrata Chindarkar
>> <namrata.chindarkar@gmail.com> wrote:
>>
>>> I have created reference groups in my dataset using -egen- and now
>>> want to compute proportions within those groups for certain variables.
>>> For instance, for the income variable, I want to compute the
>>> proportion of individuals that have income greater than income of
>>> individual "i" in each reference group. As an example if group1 has 5
>>> individuals with incomes 30, 20, 10, 60, and 70 respectively, I want
>>> to be able to get values 0.4, 0.6, 0.8, 0.2, and 0 respectively.
>>> Any suggestions on how to write a STATA program to compute this?
>>
>> *
>> *   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/
>
> *
> *   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/
>

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