Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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

**References**:**st: variable containing proportions of another variable***From:*Manos Mentzakis <mmentzakis@gmail.com>

**Re: st: variable containing proportions of another variable***From:*Scott Merryman <scott.merryman@gmail.com>

- Prev by Date:
**Re: st: how to code results from ineqdeco into new variable** - Next by Date:
**Re: st: Unbiased standard deviation in summarize** - Previous by thread:
**Re: st: variable containing proportions of another variable** - Index(es):