Announcement

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

  • How to attach parental characteristics with more than one parents in one hh

    Dear all,
    for my research, I am using IFLS data to look for the relationship between parental characteristics and educational outcome. I have a dataset that includes household id (hhid93), person id (pidlink), line number of hh member (ar001a), line number of birth father (ar10), line number of birth mother (ar11), and edu level of each member.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str7 hhid93 str9 pidlink byte(ar001a sex93 ar10 ar11 edu_level93)
    "1571000" "157100001"  1 1  .  . 2
    "1571000" "157100002"  2 0 16 17 2
    "1571000" "157100003"  3 0  1  2 3
    "1571000" "157100004"  4 0  1  2 2
    "1571000" "157100005"  5 0  1  2 2
    "1571000" "157100006"  6 0  1  2 2
    "1571000" "157100007"  7 0  1  2 1
    "1571000" "157100008"  8 1  1  2 1
    "1571000" "157100009"  9 1  1  2 1
    "1571000" "157100010" 10 1 16 17 7
    "1571000" "157100011" 11 0  .  . 1
    "1571000" "157100012" 12 1 10 11 4
    "1571000" "157100013" 13 1 10 11 2
    "1571000" "157100014" 14 1 10 11 2
    "1571000" "157100015" 15 1 10 11 2
    "1571000" "157100016" 16 1  .  . 2
    "1571000" "157100017" 17 0  .  . 1
    end
    label values sex93 sex
    label def sex 0 "0.F", modify
    label def sex 1 "1.M", modify
    I want to generate maternal and paternal edu variables. The problem is within the same household there are more than 1 family live in the house (in this case there are 3 parents). I have tried some strategies but always generate the education based on the edu of the head of hh member (number 1 in ar001a). Can you help me with this issue? Any helps is greatly appreciated. Thank you in advance.

  • #2
    Something like this should start you in a useful direction.
    Code:
    use ifls, clear
    keep hhid93 ar001a edu_level93
    rename ar001a ar10
    rename edu_level93 edu_father
    tempfile father
    save `father'
    
    use ifls, clear
    keep hhid93 ar001a edu_level93
    rename ar001a ar11
    rename edu_level93 edu_mother
    tempfile mother
    save `mother'
    
    use ifls, clear
    merge m:1 hhid93 ar10 using `father', keep(master match)
    drop _merge
    merge m:1 hhid93 ar11 using `mother', keep(master match)
    drop _merge
    
    sort hhid93 ar001a
    list, clean noobs abbreviate(12)
    which when run with your example data yields
    Code:
    . list, clean noobs abbreviate(12)
    
         hhid93     pidlink   ar001a   sex93   ar10   ar11   edu_level93   edu_father   edu_mother  
        1571000   157100001        1     1.M      .      .             2            .            .  
        1571000   157100002        2     0.F     16     17             2            2            1  
        1571000   157100003        3     0.F      1      2             3            2            2  
        1571000   157100004        4     0.F      1      2             2            2            2  
        1571000   157100005        5     0.F      1      2             2            2            2  
        1571000   157100006        6     0.F      1      2             2            2            2  
        1571000   157100007        7     0.F      1      2             1            2            2  
        1571000   157100008        8     1.M      1      2             1            2            2  
        1571000   157100009        9     1.M      1      2             1            2            2  
        1571000   157100010       10     1.M     16     17             7            2            1  
        1571000   157100011       11     0.F      .      .             1            .            .  
        1571000   157100012       12     1.M     10     11             4            7            1  
        1571000   157100013       13     1.M     10     11             2            7            1  
        1571000   157100014       14     1.M     10     11             2            7            1  
        1571000   157100015       15     1.M     10     11             2            7            1  
        1571000   157100016       16     1.M      .      .             2            .            .  
        1571000   157100017       17     0.F      .      .             1            .            .

    Comment


    • #3
      Dear William,
      thank you so much for your help. This worked perfectly.
      have a great day,
      best

      Comment


      • #4
        O.P. refers to variables ar001a, ar10 and ar11 as the "line numbers" of the current person and that person's father and mother, respectively. This would seem to imply that if the data are sorted by household and ar001a the values of ar001a will be consecutive integers starting with 1. It appears that this is true in the example data. If that is the case in the entire data set, the following code does the job more simply:

        Code:
        //  VERIFY CRUCIAL ASSUMPTION
        by hhid (ar001a), sort: assert ar001a == _n
        
        //  ASSUMPTION BEING VERIFIED, JUST DO THIS:
        by hhid (ar001a): gen father_edu = edu_level93[ar10]
        by hhid (ar001a): gen mother_edu = edu_level93[ar11]
        
        list, noobs clean
        Added: Also, if the data set is large, this method will be much faster.

        Added later:

        And here's another approach that requires no assumption and I think is still simpler, (and is probably also much faster);

        Code:
        rangestat (max) father_edu = edu_level93, by(hhid) interval(ar001a ar10 ar10)
        rangestat (max) mother_edu = edu_level93, by(hhid) interval(ar001a ar11 ar11)
        replace father_edu = . if missing(ar10)
        replace mother_edu = . if missing(ar11)
        -rangestat- is written by Robert Picard, Nick Cox, and Roberto Ferrer, and is available from SSC.
        Last edited by Clyde Schechter; 18 Oct 2020, 21:54.

        Comment


        • #5
          This also worked perfectly, thanks a bunch Clyde

          Comment

          Working...
          X