Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: variable containing proportions of another variable
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: variable containing proportions of another variable
Date
Fri, 16 Nov 2012 23:06:31 +0000
This is an FAQ:
FAQ . . Creating variables recording prop. of the other members of a group
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
4/05 How do I create variables summarizing for each
individual properties of the other members of a
group?
<http://www.stata.com/support/faqs/data-management/creating-variables-recording-properties/>
Nick
On Fri, Nov 16, 2012 at 10:37 PM, Scott Merryman
<[email protected]> wrote:
> clear
> input pid hid X proportion
> 1 1 0 0
> 2 1 0 0
> 3 1 0 0
> 4 2 1 0
> 5 2 0 1
> 6 3 0 1
> 7 3 1 0.66
> 8 3 1 0.66
> 9 3 1 0.66
> 10 4 0 0.4
> 11 4 0 0.4
> 12 4 0 0.4
> 13 4 1 0.2
> 14 4 1 0.2
> 15 4 0 0.4
> end
> egen total = total(X), by(hid)
> bys hi: gen proportion2 = (total-X)/(_N-1)
> drop total
> l
>
> Scott
>
>
> On Fri, Nov 16, 2012 at 4:27 PM, Manos Mentzakis <[email protected]> wrote:
>> Dear all,
>>
>> Apologies for the uninformative subject line but I couldnt think of a
>> way to easily describe my problem. I d like to create a variable that
>> takes as values the proportion of ones of another variable X when the
>> line under consideration is excluded. Specifically, I d like to have
>> the proportion of smokers in the household other than the individual
>> under consideration. Below is a table where proportion is the variable
>> I d like. pid is individual identifier, hid is household identifier, X
>> is an indicator with 1 if smoker 0 otherwise.
>>
>> pid hid X proportion
>> 1 1 0 0
>> 2 1 0 0
>> 3 1 0 0
>> 4 2 1 0
>> 5 2 0 1
>> 6 3 0 1
>> 7 3 1 0.66
>> 8 3 1 0.66
>> 9 3 1 0.66
>> 10 4 0 0.4
>> 11 4 0 0.4
>> 12 4 0 0.4
>> 13 4 1 0.2
>> 14 4 1 0.2
>> 15 4 0 0.4
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/