Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating Birth Order variable

    I have a data set of siblings and I am currently trying to create a birth order variable where 1 is oldest sibling, 2 is second oldest sibling, 3 is third oldest sibling.... Is there a simple way to do this while the data is still in long format using the age, family id, and id variables I have. I am struggling to think of what the code would be but essentially want to group the id's that share the same famid and then create the birth order variable using their age.

  • #2
    You could rank age by familyid if child.

    Code:
    egen agerank = rank(age) if child, by(familyid)

    Comment


    • #3
      A twist here is that as you want 1 to mean oldest, the function call should be

      Code:
      rank(-age)
      Further, you should consider what you want to happen with twins or other multiple births, and should find that the options associated with egen's rank() give you the nuance you really want.

      For example suppose that birth date of one eldest child followed by two twins with the same birth date yield ranks 1 2.5 2.5. I am guessing wildly that you may not want that for your purposes, but the field, track and unique options are available too.

      Comment

      Working...
      X