Announcement

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

  • How to Generate Household Head Variable

    Dear Statalist Users,

    I work with a household survey and I would like to generate a variable for household head. I have three different definitions:

    Definition 1: if one member of the couple is a Full Time worker and the other is not, assign the Full Time worker as household head.

    Definition 2: if both members of the couple are Full Time workers, assign the older person as household head. If both members of the couple are Full Time workers and the same age, assign the ‘first’ person in the HH as the head.

    Definition 3: If both members of the couple are FT workers, assign the higher earner as the household head.

    I am struggling to construct household head variable, I would really appreciate if you could help.

    Many thanks!



    My data look like below:

    Note: Same case number means that individuals sampled in the same address (i.e. they are members of the same household).
    Attached Files
    Last edited by Gokay Uzun; 31 Jan 2016, 05:34.

  • #2
    Thanks for the data example, which looks like an spreadsheet screenshot. It would be even better as executable Stata code. Please see FAQ Advice #12.

    Your rules leave various possibilities implicit, e.g.

    * 2 or more full-time workers.

    * Ties on income given other rules.

    * What happens if no-one is full-time.

    But here is some technique:

    Code:
    clear
    input caseno personno age ft income
    2000 1 22 1 255
    2000 2 27 0 370
    2001 1 28 1 512
    2002 1 32 0 222
    2003 1 46 1 438
    2003 2 48 1 452
    2003 3 24 1 158
    end
    bysort caseno : egen n_ft = total(ft)
    
    bysort caseno (ft) : gen head = personno[_N] if n_ft == 1 
    bysort caseno (ft age personno) : replace head = personno[_N] if head == . & (age[_N] > age[_N-1]) & ft[_N]
    bysort caseno (income) : replace head = personno[_N] if head == .
    
    l, sepby(caseno)
    
         +-----------------------------------------------------+
         | caseno   personno   age   ft   income   n_ft   head |
         |-----------------------------------------------------|
      1. |   2000          1    22    1      255      1      1 |
      2. |   2000          2    27    0      370      1      1 |
         |-----------------------------------------------------|
      3. |   2001          1    28    1      512      1      1 |
         |-----------------------------------------------------|
      4. |   2002          1    32    0      222      0      1 |
         |-----------------------------------------------------|
      5. |   2003          3    24    1      158      3      2 |
      6. |   2003          1    46    1      438      3      2 |
      7. |   2003          2    48    1      452      3      2 |
         +-----------------------------------------------------+
    Last edited by Nick Cox; 31 Jan 2016, 07:24.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Thanks for the data example, which looks like an spreadsheet screenshot. It would be even better as executable Stata code. Please see FAQ Advice #12.

      Your rules leave various possibilities implicit, e.g.

      * 2 or more full-time workers.

      * Ties on income given other rules.

      * What happens if no-one is full-time.

      But here is some technique:

      Code:
      clear
      input caseno personno age ft income
      2000 1 22 1 255
      2000 2 27 0 370
      2001 1 28 1 512
      2002 1 32 0 222
      2003 1 46 1 438
      2003 2 48 1 452
      2003 3 24 1 158
      end
      bysort caseno : egen n_ft = total(ft)
      
      bysort caseno (ft) : gen head = personno[_N] if n_ft == 1
      bysort caseno (ft age personno) : replace head = personno[_N] if head == . & (age[_N] > age[_N-1]) & ft[_N]
      bysort caseno (income) : replace head = personno[_N] if head == .
      
      l, sepby(caseno)
      
      +-----------------------------------------------------+
      | caseno personno age ft income n_ft head |
      |-----------------------------------------------------|
      1. | 2000 1 22 1 255 1 1 |
      2. | 2000 2 27 0 370 1 1 |
      |-----------------------------------------------------|
      3. | 2001 1 28 1 512 1 1 |
      |-----------------------------------------------------|
      4. | 2002 1 32 0 222 0 1 |
      |-----------------------------------------------------|
      5. | 2003 3 24 1 158 3 2 |
      6. | 2003 1 46 1 438 3 2 |
      7. | 2003 2 48 1 452 3 2 |
      +-----------------------------------------------------+
      Dear Nick,

      Many thanks for your help, it was really helpful.

      Best regards,

      Gokay

      Comment

      Working...
      X