Announcement

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

  • Identifying siblings from the same and different birth by motherID

    Hello

    I would be very grateful for advice on how to generate two variables:
    1. Siblings from the same mother. The mother may have had a multiple birth and other births at a different time.
    2. Identify if a child was a multiple.


    I have the following variables:
    MotherID & BabyID. Mother 1 has 4 babies from 2 births.
    Baby e is a singleton and has no siblings.
    Baby f is a twin but there is no information for the sibling

    I have the birth month and birth year to identify if a multiple birth took place. There are multiple records for some babies as each record is a hospital admission.

    Totalfetus is the number of fetuses delivered for a particular birth.

    I would like to generate a sibling and same birth variable as shown below.

    Here is an example of data.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte motherid str1 babyid byte birthmonth int birthyear byte(totalfetus hassibling samebirth)
    1 "a"  1 2000 1 1 0
    1 "b"  2 2002 3 1 1
    1 "b"  2 2002 3 1 1
    1 "c"  2 2002 3 1 1
    1 "d"  2 2002 3 1 1
    1 "d"  2 2002 3 1 1
    1 "d"  2 2002 3 1 1
    2 "e"  3 1999 1 0 .
    3 "f" 11 2005 2 1 0
    3 "g"  6 2007 2 1 1
    3 "h"  6 2007 2 1 1
    end
    Many thanks!











  • #2
    This would be straightforward but for the multiple entries for the same baby. The easiest way to get around that obstacle is to put the relevant variables into a separate frame, drop the duplicate observations, calculate the desired variables, return to the default frame and bring in the results from the separate frame.
    Code:
    frame put motherid babyid birthmonth birthyear, into(working)
    frame working {
        duplicates drop
        by motherid, sort: gen byte hassibling = _N > 1
        by motherid birthmonth birthyear, sort: gen samebirth = _N > 1 if hassibling
    }
    frlink m:1 motherid babyid, frame(working)
    frget hassibling samebirth, from(working)
    drop working
    frame drop working

    Comment


    • #3
      Thank you so much! This worked perfectly.

      Comment

      Working...
      X