Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Create Variable containing Generations per Household


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Create Variable containing Generations per Household
Date   Wed, 19 Sep 2012 15:56:01 +0100

No looping is necessary. The number of distinct values of -rel_hh-
within households (I assume a household identifier -hh_id-) is given
by tagging each distinct value of -rel_hh- within each household and
then counting.

egen tag = tag(hh_id rel_hh)
egen ngen = total(tag), by(hh_id)

One-line solutions are also identifiable.

For a discussion of principles, see

SJ-8-4  dm0042  . . . . . . . . . . . .  Speaking Stata: Distinct observations
        (help distinct if installed)  . . . . . .  N. J. Cox and G. M. Longton
        Q4/08   SJ 8(4):557--568
        shows how to answer questions about distinct observations
        from first principles; provides a convenience command

which is accessible at
http://www.stata-journal.com/sjpdf.html?articlenum=dm0042

Nick

On Wed, Sep 19, 2012 at 3:11 PM, Laura Marlene Große
<[email protected]> wrote:

> I have a dataset comprising a few houndred households and about 3,000
> individuals that I've collected last year.
> One of my criteria to draw a random subsample for my future research will be
> how many generations do live in one household. Using my variable "relation
> to the head of the household" i have identified the different types of
> relatives and their inter-generational position. Including my codes for
> rel_head that makes 5 possible generations:
> 1 (6 Parent, 7 Parent in law, 12 Uncle/Aunt)
> 2 (1 Head, 2 Conjugal Partner, 8 Biological Brother or Sister, 14 Cousin, 21
> Sister/Brother in law, 23 Son in laws mother)
> 3 (3 Biological Son or Daughter, 4 Son/Daughter in law, 9
> Adopted/Foster/Stepchild, 18 Late husbands nephew, 19 Nephew/Niece, 20
> Wife's cousin's daughter, 22 Son in laws brother, 25 Stepson, 13 Brothers
> daughters husband)
> 4 (5 Grandchild, 15 Granddaughters boyfriend, 16 Grandsnephew/Grandniece, 24
> Step daughters daughter)
> 5 (17 Great-grandchild)
> In my individual based dataset (individual and household ID's), I would like
> to create a new variable which contains the number of generations per
> household. So it would be 1 generation if only number 2 is present, 2
> generations if numbers 1 and 2 or 2 and 3 are present in the household and
> so on. I assume that I will have to write a loop using foreach or similar.
> However, I'm confused as to how to tell Stata to limit the loop to the
> specific households?!

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index