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: variable containing proportions of another variable

 From Manos Mentzakis To statalist@hsphsun2.harvard.edu Subject Re: st: variable containing proportions of another variable Date Fri, 16 Nov 2012 22:50:39 +0000

```Dear Scott,

thank you very much

Regards
Manos

On Fri, Nov 16, 2012 at 10:37 PM, Scott Merryman
<scott.merryman@gmail.com> 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 <mmentzakis@gmail.com> 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
>>
>>
>> Any help is greatly appreciated.
>>
>> Regards
>> Manos
>> *
>> *   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/
> *
> *   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/
*
*   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/
```