Bookmark and Share

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]

Re: st: variable containing proportions of another variable


From   Scott Merryman <scott.merryman@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: variable containing proportions of another variable
Date   Fri, 16 Nov 2012 16:37:16 -0600

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index