Announcement

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

  • Defining household head

    Hi Statalist community,

    I'm new so I'm not sure if this is posted in the right section (sorry if it's not).

    I'm currently working with a panel dataset (HILDA), and need to identify the household head for each household within each period (wave). The household id (hhid) is randomised across each wave, and I define the household head as the individual (labelled xwaveid, kept same across all waves) with the highest income (say, lincome) within that household. Can anyone give me some hints on how to code for that?

    I've looked everywhere. Thanks in advance.

    Huan

  • #2
    One way:

    Code:
    clear
    set more off
    
    *----- example data -----
    
    input ///
    hhid year id income
    1 1990 1 235
    1 1990 2 426
    1 1990 3 346
    1 1991 1 357
    1 1991 2 426
    1 1991 3 598
    2 1991 1 246
    2 1991 2 645
    2 1992 1 798
    2 1992 2 .
    end
    
    *----- what you want -----
    
    bysort hhid year: egen head = max(income)
    replace head = (head == income)
    
    list, sepby(hhid year)
    You should:

    1. Read the FAQ carefully.

    2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

    3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

    4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

    Comment


    • #3
      I assume you have a sensible summary of income for each person. Then use -egen-'s -max()- function to get the maximum for each household. Then the person you want has their income equal to that maximum. See help on -egen- and study the data management FAQs on the Stata website.

      Comment


      • #4
        And one subtle point: if a household has two or more people with the same reported income, and that is the maximum within the household, you will either have to settle for multiple heads in a house hold or adopt some rule for breaking ties. If you're lucky, this problem won't arise--but you should check for it lest it go undiscovered for a while and bite you later on.

        Comment

        Working...
        X