Announcement

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

  • How to generate parents variables matched to their children

    Hello everyone,

    I've been trying to create a dummy variable indicating if at least one of the two parents (living with the children) is black. I read many of the previous entries regarding similar topics, but my dataset is quite different, so I did not come up with any ideas. My data looks like this:
    id sector quest p_num relation_hh famnumb condfam father mother numfath numbmoth race
    123 1001 1 1 head 1 head 0 0 1
    124 1001 1 2 son/daughter 1 son/daughter 0 1 1 1 1
    125 1001 2 1 head 1 head 0 0 2
    126 1002 1 1 head 1 head 0 0 2
    127 1002 1 2 spouse 1 spouse 0 0 1
    128 1002 1 3 son/daughter 1 son/daughter 1 1 1 2
    129 1002 2 1 head 1 head 0 1 3 1
    130 1002 2 2 son/daughter 1 son/daughter 1 1 1 1
    131 1002 2 3 mother/father 1 mother/father 0 0 2
    132 1003 1 1 son/daughter 1 son/daughter 1 1 2 3 2
    133 1003 1 2 head 1 head 0 0 1
    134 1003 1 3 spouse 1 spouse 0 0 2
    135 1003 1 4 grandchild 1 grandchild 1 0 1 2
    136 1003 1 5 brother/sister 2 head 0 0 1
    137 1003 1 6 nephew/niece 2 son 0 1 6 1

    ID is the unique person ID number, sector is the sector within the research, quest is the questionnaire number, p_numb is the respondent's number within the household, relation_hh is the relationship to the head of household, famnumb is the family number within the household, condfam is the condition within the family, father/mother is whether the father/mother lives in the same household, numbfath/numbmoth is the p_numb of father/mother, race is the self declared race (1-black, no-black).

    Thank you so much in advance.

    Regards,

    Rebeca

  • #2
    That data example is hard to read. It's best to follow FAQ Advice #12. This code reproduces the data example using code and includes a wild guess at what you want. I suspect you explained it clearly, but this is a long way from my own playgrounds.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(id sector) byte(quest p_num) str14 relation_hh byte famnumb str13 condfam byte(father mother numfath numbmoth race)
    123 1001 1 1 "head"           1 "head"          0 0 . . 1
    124 1001 1 2 "son/daughter"   1 "son/daughter"  0 1 1 1 1
    125 1001 2 1 "head"           1 "head"          0 0 . . 2
    126 1002 1 1 "head"           1 "head"          0 0 . . 2
    127 1002 1 2 "spouse"         1 "spouse"        0 0 . . 1
    128 1002 1 3 "son/daughter"   1 "son/daughter"  1 1 1 . 2
    129 1002 2 1 "head"           1 "head"          0 1 . 3 1
    130 1002 2 2 "son/daughter"   1 "son/daughter"  1 1 1 . 1
    131 1002 2 3 "mother/father"  1 "mother/father" 0 0 . . 2
    132 1003 1 1 "son/daughter"   1 "son/daughter"  1 1 2 3 2
    133 1003 1 2 "head"           1 "head"          0 0 . . 1
    134 1003 1 3 "spouse"         1 "spouse"        0 0 . . 2
    135 1003 1 4 "grandchild"     1 "grandchild"    1 0 1 . 2
    136 1003 1 5 "brother/sister" 2 "head"          0 0 . . 1
    137 1003 1 6 "nephew/niece"   2 "son"           0 1 . 6 1
    end
    
    * NJC guesswork 
    egen nblackparents = total((race == 1) * (condfam == "mother/father")), by(famnumb)
    gen iblackparents = nblackparents > 0

    Comment


    • #3
      It is unclear (to me) what is your data structure. I think your sector variable is the household id (the hh_id variable) and the famnumb is the number of the family within the household . If that so, it means you have families within families. I'm not sure about my solution but without much more details this is the best I can propose:

      Code:
      bys sector famnumb: g father_race=race[numbfath]
      bys sector famnumb: g mother_race=race[numbmoth]
      
      bys sector famnumb: egen black_parent=max(father_race==1 | mother_race==1)
      If you are interested only in the family number, then drop the sector variable from above.

      Comment


      • #4
        Hello everyone!

        Thank you so much for your help.

        Sector is not the household id, but it contains many households. The dictionary is not clear, but after studying the data I believe the questionnaire number serves as household id within the sector. I am studying your proposals and get back soon.

        Rebeca

        Comment

        Working...
        X