Announcement

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

  • Identify parents and children in the sample

    Hello everyone, I would like for some help.

    I have data file with four variables: "id", "id_father", "id_mother" and "birth_year". The variable "id" is the ID number of an individiual, and each value in it is unique, therefore the number of people in the sample is as the number of observations. The values in the rest of the variables are not unique since two people in the sample can be siblings.
    Furthermore, the parents of an individual can appear as individuals in the sample as well, i.e - values that appear in"id_father" and "id_mother" can appear in "id" as well.

    My final goal is to create variables that will be the ID and the year of birth of the child for every person in the sample that his or her children appear in the sample. notice that a parent can have more than one child in the sample.

    For now I have no clue how to make such thing happen, and I would be very glad if someone here can help me with a piece of code.

    Thank you already,

    Fitzgerald.

  • #2
    You could do this and then join the data created.

    Code:
    clear
    input id id_father year
    1 1 1973
    2 1 2000
    3 3 2002
    4 3 1966
    5 3 1998
    6 3 1999
    7 7 1978
    8 7 2020
    9 7 2022
    end
    
    
    bysort id_father: gen child_num = _n
    reshape wide id year, i(id_father) j(child_num)

    Comment


    • #3
      rangestat from SSC can be used for such problems.

      Comment

      Working...
      X