Announcement

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

  • Calculating houshold income

    Hello everyone,

    I use Stata 15 and have to calculate the household income in a panel dataset. For this purpose I have two variables at my disposal:

    1.) The individual income of the persons in a household ("inc_ind"). --> One individual value per person.

    2.) A variable that captures other income components that are beneficial to the household as a whole, but are not included in the individual income ("inc_hh"). --> The same value for all persons living in the same household.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double hh_id long p_id double year float(inc_ind inc_hh)
    159 1501 2005 73920   40
    159 1501 2006 72000   27
    159 1501 2007 75000   25
    167 1601 2005 15816 1848
    167 1603 2005   300 1848
    167 1602 2005  4200 1848
    167 1602 2006  3600    0
    167 1601 2006 16800    0
    167 1601 2007 16392    0
    167 1602 2007  6120    0
    175 1704 2005 34816 1680
    175 1701 2005 39288 1680
    175 1705 2005     0 1680
    175 1705 2006     0 1800
    175 1701 2006 43663 1800
    175 1704 2006 35880 1800
    175 1701 2007     . 1800
    175 1704 2007 28200 1800
    175 1705 2007     0 1800
    end
    label values hh_id mis
    label values p_id mis
    label values year mis
    I want to calculate the total household income by adding the individual incomes of the household members and the variable "inc_hh" of each houshold. However, the variable "inc_hh" should only be taken into account once per household. So if there's more than one person living in a household, "inc_hh" should nevertheless only be included once in the calculation. I hope it becomes clear what I mean...

    Furthermore, the two variables should only be added together when both the individual "inc_ind"'s variables and "inc_hh" are nonmissing.

    Unfortunately, I haven't found a solution to my problem yet and I really hope that someone can help me here.

    Many thanks in advance and best regards!
    Tom

  • #2
    The household total of inc_ind in each year can be derived using code such as
    Code:
    bys hh_id year: egen total_inc_ind = total(inc_ind)
    In your data example, you appear to have only one observation for each hh_id-year combination. That's inconsistent with your request for help which refers to having potentially more than one person per household per year.

    I suggest that you construct and share a data example that better represents the features of your problem (multi-person households; the desired treatment of inc_hh; treatment of missing values)

    Comment


    • #3
      Thanks for the quick reply, Stephen!

      Your code does indeed work well for the individual level. Thanks for that!

      Apparently I haven't made my issue clear enough since the data example I posted contains all the necesarry value constellations.

      I'll try to make my problem clear by giving you two examples:

      1.) I need another code line that adds the value of "inc_hh" to your "total_inc" variable. Let me explain this using the example of "hh_id" 167, year 2015: To the "total_inc" of 20.316€ the "inc_hh" of 1.816€ needs to be added. We have three persons in this household and year, but the 1.816€ of "inc_hh" should only be added once to "total_inc". This is due to the fact that "inh_hh" refers to the household as a whole and not to each single person.

      2.) If you take a look at "hh_id" 175, year 2007, there are three persons in this household. But for one person "inc_ind" is missing. In that case, "total_inc" (i. e. the addition of "inc_ind's" and "inc_hh") needs to be a missing value as well.

      I'm thankful for any further advice!

      Comment


      • #4
        I need another code line that adds the value of "inc_hh" to your "total_inc" variable.
        Perhaps Stephen hesitated to spell out what seems to be obvious
        Code:
        generate total_inc_hh = total_inc_ind + inc_hh
        With regard to the handling of missing values, perhaps this is what you wanted, or at least a start toward it.
        Code:
        bys hh_id year: egen total_inc_ind = total(inc_ind)
        bys hh_id year: egen hasmissing = max(missing(inc_ind))
        replace total_inc_ind = . if hasmissing
        generate total_inc_hh = total_inc_ind + inc_hh
        Code:
        . list, noobs sepby(hh_id year) abbreviate(16)
        
          +------------------------------------------------------------------------------------+
          | hh_id   p_id   year   inc_ind   inc_hh   total_inc_ind   hasmissing   total_inc_hh |
          |------------------------------------------------------------------------------------|
          |   159   1501   2005     73920       40           73920            0          73960 |
          |------------------------------------------------------------------------------------|
          |   159   1501   2006     72000       27           72000            0          72027 |
          |------------------------------------------------------------------------------------|
          |   159   1501   2007     75000       25           75000            0          75025 |
          |------------------------------------------------------------------------------------|
          |   167   1601   2005     15816     1848           20316            0          22164 |
          |   167   1603   2005       300     1848           20316            0          22164 |
          |   167   1602   2005      4200     1848           20316            0          22164 |
          |------------------------------------------------------------------------------------|
          |   167   1602   2006      3600        0           20400            0          20400 |
          |   167   1601   2006     16800        0           20400            0          20400 |
          |------------------------------------------------------------------------------------|
          |   167   1601   2007     16392        0           22512            0          22512 |
          |   167   1602   2007      6120        0           22512            0          22512 |
          |------------------------------------------------------------------------------------|
          |   175   1704   2005     34816     1680           74104            0          75784 |
          |   175   1701   2005     39288     1680           74104            0          75784 |
          |   175   1705   2005         0     1680           74104            0          75784 |
          |------------------------------------------------------------------------------------|
          |   175   1705   2006         0     1800           79543            0          81343 |
          |   175   1701   2006     43663     1800           79543            0          81343 |
          |   175   1704   2006     35880     1800           79543            0          81343 |
          |------------------------------------------------------------------------------------|
          |   175   1701   2007         .     1800               .            1              . |
          |   175   1704   2007     28200     1800               .            1              . |
          |   175   1705   2007         0     1800               .            1              . |
          +------------------------------------------------------------------------------------+

        Comment


        • #5
          Perfect, that has worked out well. Thanks a lot!

          Comment

          Working...
          X