Announcement

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

  • Calculating number of children with same mother and father

    Hello

    I am trying to calculate the number of siblings in a family with the criterion for being siblings that the children share minimum one parent.

    I have generated two variables counting the number of children with the same mother (mother_sib) and father (father_sib) and now I want to calculate the number of siblings sharing both the same mother and father (parent_sib).

    Code:
    bysort mother_id:gen byte father_sib=_N
    
    bysort father_id:gen byte father_sib=_N
    Eventually, I want to add mother_sib and father_sib together and subtract the number of children sharing both the same father and mother to avoid adding the same children twice (mother_sib + father_sib - parents_sib). Then the number of children sharing minimum one parent should appear. But I still need to figure out how to calculate the number of children sharing both the same father and mother - any ideas?


    Code:
    input double(mother_id father_id) byte(morther_sib father_sib)
      22126   2230 1 1
       2256   2206 3 3
       2256   2206 3 3
       2256   2206 3 3
    2278868   2259 1 1
          .   8532 . 1
      22472   2272 3 3
      22472   2272 3 3
      22472   2272 3 3
    2219586   2251 1 1
          .  22615 . 1
    2206309  22428 1 1
    2232781  22450 2 1
    2252360  22780 2 2
    2252360  22780 2 2
    Thank you!

  • #2
    It would have been easier to deal with your problem if you'd created an artificial data set so the patterns were clearer.
    You can generate the number for any pattern of mother and father with
    bysort mother_id father_id:gen byte father_sib=_N

    Comment

    Working...
    X