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

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
RE: st: data management question - creating a household identifier |

Date |
Thu, 20 Sep 2007 19:02:25 +0100 |

In addition, note the FAQ in this territory 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 Nick n.j.cox@durham.ac.uk Svend Juul > 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) > > If -consecu- is a string you can use the -substring()- > function to isolate selected digits. * * 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/

**References**:**Re: st: data management question - creating a household identifier***From:*"Svend Juul" <SJ@SOCI.AU.DK>

- Prev by Date:
**st: permute** - Next by Date:
**st: RE: Goodness of fit and model comparison in xtgee** - Previous by thread:
**Re: st: data management question - creating a household identifier** - Next by thread:
**st: -Predict- after multi-equation ml command** - Index(es):

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