Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: data management question - creating a household identifier


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   Re: st: data management question - creating a household identifier
Date   Thu, 20 Sep 2007 19:39:14 +0200

Fran wrote:
 
I have a data-set where individuals are nested in 
households. I have the following unique identifier: 
consecu (a long variable).
 
For example, below, 101 102 and 103 denotes three
individuals of the same household, just like 1284001
1284002 1284003 1284004 and 1284005 denotes five
individuals of another household.

consecu X
101 1
102 1
103 0
201 1
202 0
203 0
.
.
.
1283901 1
1283902 0
1283903 0
1283904 1
1284001 0
1284002 0
1284003 1
1284004 1
1284005 0

Question1 : How can I generate a household identifier?
Maybe a household identifier that goes from 10 to
128400?
 
Question 2: How can I generate a household level
variable, Xhh, that captures whether any member of a
household scores 1 for the X variable?
 
----------------------------------------------
 
Long ids are best handled as strings; see, e.g.:
http://www.ats.ucla.edu/stat/stata/faq/longid.htm.
 
-consecu- is numeric variable, stored as -long-.
Try this:
 
   generate hhid=floor(consecu/100)
   generate pid=mod(consecu,100)
   bysort hhid: egen Xhh = max(X)
 
Long ids are best handled as strings; see, e.g.:
http://www.ats.ucla.edu/stat/stata/faq/longid.htm.
If -consecu- is a string you can use the -substring()- 
function to isolate selected digits.
 
Hope this helps
Svend
 
 
________________________________________________________ 
 
Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 
DK-8000 Aarhus C,  Denmark 
Phone, work:  +45 8942 6090 
Phone, home:  +45 8693 7796 
Fax:          +45 8613 1580 
E-mail:       [email protected] 
_________________________________________________________ 

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



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index