Michael's one-liner solution is covered with a small mountain
of commentary in
2/03 How do I create a variable recording whether any
members of a group (or all members of a group)
possess some characteristic?
http://www.stata.com/support/faqs/data/anyall.html
The FAQ also discusses the important issue raised by Austin
Nichols, what if missing values are present?
Nick
[email protected]
Michael Blasnik
> I haven't seen any other one line solutions, so thought I'd
> post as well:
>
> by HouseholdID: egen HHinfected=max(Infected)
>
> or, if there are no missing values in Infected:
>
> by HouseholdID (Infected): gen byte HHinfected=Infected[_N]
Honorati Masanja
> > I have a dataset with individuals in households. Each
> individual has a
> > unique identifier. Some individuals in the households are
> infected and
> > some are not. My problem is how do I tell Stata to create a
> new variable
> > which will have 1 for households with at least one infected
> person and
> > 0 for households without infected persons. The datasets
> looks like this
> >
> > HouseholdID PersonID Infected
> > 010101 01010101 1
> > 010101 01010102 1
> <snip>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/