Announcement

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

  • How to create a variable that summarize properties of the other members of the same family group?

    I have panel data on adult women and their husbands, I have a variable (family_id) which is the same for men and women in the same family unit (husbands and wives). Each adult reports his or her own employment status, I would like to create a new variable for the wives based on the employment status of their husbands, i.e. a binary variable "husband_is_unemployed". For the life of me I cannot figure out how to create a variable that summarize properties of the other members of the same family, as is needed above, even using the following: https://www.stata.com/support/faqs/d...ng-properties/ can anyone please advise?

    To describe the data:


    Code:
    . tab gender
    
         Gender |      Freq.     Percent        Cum.
    ------------+-----------------------------------
         Female |      1,102       62.61       62.61
           Male |        658       37.39      100.00
    ------------+-----------------------------------
          Total |      1,760      100.00
    
    . tab binary_employment_y0
    
          Binary No |
        Employment? |      Freq.     Percent        Cum.
    ----------------+-----------------------------------
    Some Employment |      1,019       73.05       73.05
      No Employment |        376       26.95      100.00
    ----------------+-----------------------------------
              Total |      1,395      100.00
    
    . tab family_id
    
      family_id |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              5 |          1        0.06        0.06
              7 |          2        0.11        0.17
              8 |          1        0.06        0.23
              9 |          2        0.11        0.34
             10 |          2        0.11        0.45
             12 |          1        0.06        0.51
             14 |          2        0.11        0.63
             15 |          2        0.11        0.74
             18 |          2        0.11        0.85
             21 |          2        0.11        0.97
             22 |          1        0.06        1.02
             23 |          2        0.11        1.14
             25 |          2        0.11        1.25
             26 |          2        0.11        1.36
             28 |          2        0.11        1.48
             30 |          1        0.06        1.53
             31 |          1        0.06        1.59
             32 |          2        0.11        1.70
             33 |          1        0.06        1.76
             35 |          2        0.11        1.87
             36 |          2        0.11        1.99
             38 |          2        0.11        2.10
             40 |          2        0.11        2.22
             41 |          2        0.11        2.33
             47 |          2        0.11        2.44
             48 |          2        0.11        2.56
             57 |          1        0.06        2.61
             58 |          2        0.11        2.73
             61 |          2        0.11        2.84
             63 |          1        0.06        2.90
             64 |          2        0.11        3.01
             66 |          2        0.11        3.13
             67 |          1        0.06        3.18
             68 |          2        0.11        3.30
             74 |          2        0.11        3.41
             80 |          1        0.06        3.47
             81 |          2        0.11        3.58
             82 |          1        0.06        3.64
             83 |          2        0.11        3.75
             86 |          2        0.11        3.86
             87 |          1        0.06        3.92
             88 |          2        0.11        4.03
             89 |          2        0.11        4.15
             91 |          1        0.06        4.20
             93 |          1        0.06        4.26
             98 |          2        0.11        4.37
            103 |          2        0.11        4.49
            108 |          2        0.11        4.60
            110 |          2        0.11        4.72
            112 |          1        0.06        4.77
            116 |          2        0.11        4.89
            124 |          2        0.11        5.00
            134 |          2        0.11        5.11
            135 |          2        0.11        5.23
            137 |          2        0.11        5.34
            138 |          2        0.11        5.45
            141 |          1        0.06        5.51
            142 |          2        0.11        5.62
            147 |          2        0.11        5.74
            153 |          2        0.11        5.85
            154 |          2        0.11        5.97
            155 |          2        0.11        6.08
            156 |          1        0.06        6.14
              etc.......
    ------------+-----------------------------------
          Total |      1,760      100.00
    
    . 
    
    The frequency above provides a clue that it refers to the relationship between study members because when women and men are married it is two, but when the woman is single it is one.
    My initial simple thought was something like the below (where male is 1) but of course this won't apply to the wife, who I am anxious to create the variable on spousal employment for

    Code:
    generate maleunemployed_y0 =.
    replace maleunemployed_y0 = 1 if binary_employment_y0==1 & gender == 1 
    replace maleunemployed_y0 = 0 if binary_employment_y0==0 & gender == 1 
    
    generate partnerunemployed_y0 =.
    replace partnerunemployed_y0 = 1 if maleunemployed_y0==1 & gender == 0
    replace partnerunemployed_y0 = 0 if maleunemployed_y0==0 & gender == 0 
    sort family_id
    browse id family_id gender maleunemployed_y0 partnerunemployed_y0 binary_employment_y0

  • #2
    We need an example of the data themselves, not tabulations. Please consult #12 in the FAQ Advice on posting.

    Comment


    • #3
      Thank you for your response Nick, please find attached as requested:


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input long id int family_id long gender float partnerunemployed_y0 byte binary_employment_y0
      200051  5 0 . 1
      300071  7 1 . 0
      200071  7 0 . 0
      200081  8 0 . 1
      300091  9 1 . 0
      200091  9 0 . 0
      300101 10 1 . .
      200101 10 0 . 0
      200121 12 0 . 1
      200141 14 0 . 0
      300141 14 1 . 0
      200151 15 0 . 0
      300151 15 1 . .
      200181 18 0 . 0
      300181 18 1 . 0
      300211 21 1 . .
      200211 21 0 . 0
      200221 22 0 . .
      200231 23 0 . 1
      300231 23 1 . .
      200251 25 0 . 1
      300251 25 1 . .
      200261 26 0 . 0
      300261 26 1 . .
      200281 28 0 . 0
      300281 28 1 . .
      200301 30 0 . 1
      200311 31 0 . 0
      300321 32 1 . .
      200321 32 0 . 0
      200331 33 0 . 1
      300351 35 1 . .
      200351 35 0 . 0
      200361 36 0 . 0
      300361 36 1 . 0
      300381 38 1 . 0
      200381 38 0 . 0
      200401 40 0 . 0
      300401 40 1 . 0
      300411 41 1 . 0
      200411 41 0 . 0
      300471 47 1 . .
      200471 47 0 . 0
      300481 48 1 . .
      200481 48 0 . 0
      200571 57 0 . .
      300581 58 1 . .
      200581 58 0 . 0
      200611 61 0 . 1
      300611 61 1 . 0
      end
      label values gender gender
      label def gender 0 "Female", modify
      label def gender 1 "Male", modify
      label values binary_employment_y0 y0_binary_employment
      label def y0_binary_employment 0 "Some Employment", modify
      label def y0_binary_employment 1 "No Employment", modify

      Comment


      • #4
        If indeed all your families have at most 2 members, then the problem simplifies to the following code, starting with your data loaded in memory.
        Code:
        bysort family_id: generate family_size = _N
        assert family_size <=2
        
        bysort family_id: replace partnerunemployed_y0 = binary_employment_y0[3-_n] if family_size==2
        list if family_id <= 10 | family_id==61, noobs sepby(family_id) nolabel abbreviate(20)
        Code:
        . list if family_id <= 10 | family_id==61, noobs sepby(family_id) nolabel abbreviate(20)
        
          +-----------------------------------------------------------------------------------------+
          |     id   family_id   gender   partnerunemployed_y0   binary_employment_y0   family_size |
          |-----------------------------------------------------------------------------------------|
          | 200051           5        0                      .                      1             1 |
          |-----------------------------------------------------------------------------------------|
          | 300071           7        1                      0                      0             2 |
          | 200071           7        0                      0                      0             2 |
          |-----------------------------------------------------------------------------------------|
          | 200081           8        0                      .                      1             1 |
          |-----------------------------------------------------------------------------------------|
          | 300091           9        1                      0                      0             2 |
          | 200091           9        0                      0                      0             2 |
          |-----------------------------------------------------------------------------------------|
          | 300101          10        1                      0                      .             2 |
          | 200101          10        0                      .                      0             2 |
          |-----------------------------------------------------------------------------------------|
          | 200611          61        0                      0                      1             2 |
          | 300611          61        1                      1                      0             2 |
          +-----------------------------------------------------------------------------------------+

        Comment


        • #5
          More on [3 - _n] within https://www.stata-journal.com/sjpdf....iclenum=dm0043

          Comment

          Working...
          X