--- Honorati Masanja wrote:
> 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.
Honorati Masanja:
Yesterday I posted a way of doing this on the statalist, see:
http://www.stata.com/statalist/archive/2006-11/msg00841.html. Applying it
to your data would look like the example below:
*-------------- begin example ---------------------
input HouseholdID PersonID Infected
010101 01010101 1
010101 01010102 1
010102 01010201 0
010102 01010202 1
010102 01010203 1
010103 01010301 0
010103 01010302 0
010103 01010303 0
010104 01010401 0
010104 01010402 1
end
bys HouseholdID: egen tinfected = total(Infected)
gen houseinfected = tinfected>=1
*---------------- end example ----------------------
HTH,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* 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/