Announcement

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

  • Finding average age of each HH where every member age mentioned.

    area hh_no tot_pop q_8 q_10 q_11
    1 1 0 1 54 1
    1 1 0 2 44 2
    1 1 0 3 14 1
    1 1 3 4 22 1
    1 2 0 1 52 1
    1 2 0 2 44 2
    1 2 3 3 24 1
    1 3 0 1 35 1
    1 3 0 2 29 2
    1 3 0 4 9 2
    1 3 4 3 4 1
    1 4 1 1 54 1
    1 5 0 1 46 1
    1 5 0 2 39 2
    1 5 3 3 11 2
    1 6 0 1 51 1
    1 6 0 2 44 2
    1 6 0 3 16 1
    1 6 4 4 22 1
    1 7 0 1 49 1
    1 7 0 2 44 2
    1 7 3 3 22 1

    .................................................. .........................
    .................................................. .........................
    In this data set q_10 represents the age of each member. I want to find the average age of each HH. In the tot_pop variable integer number represents the total hh member.
    For example (54+44+14+22)/3, (52+44+24)/3 ..

  • #2
    I don't follow #1. Why divide the sum of 4 ages by 3?

    Comment


    • #3
      That's a very good question Nick. Perhaps 1 death in the survey year in that HH. It misguides definitely.

      Comment


      • #4
        If the only guess is that someone died, it seems that you have choices. Here are two.

        1. Average the ages given.

        2. #1, except only if tot_pop matches the number of observations.


        Code:
        clear 
        input area hh_no tot_pop q_8 q_10 q_11
        1 1 0 1 54 1
        1 1 0 2 44 2
        1 1 0 3 14 1
        1 1 3 4 22 1
        1 2 0 1 52 1
        1 2 0 2 44 2
        1 2 3 3 24 1
        1 3 0 1 35 1
        1 3 0 2 29 2
        1 3 0 4 9 2
        1 3 4 3 4 1
        1 4 1 1 54 1
        1 5 0 1 46 1
        1 5 0 2 39 2
        1 5 3 3 11 2
        1 6 0 1 51 1
        1 6 0 2 44 2
        1 6 0 3 16 1
        1 6 4 4 22 1
        1 7 0 1 49 1
        1 7 0 2 44 2
        1 7 3 3 22 1
        end 
        
        bysort area hh_no (tot_pop) : gen N1 = tot_pop[_N] 
        by area hh_no : gen N2 = _N 
        egen mean1 = mean(q_10), by(area hh_no)
        egen mean2 = mean(q_10) if N1 == N2, by(area hh_no)
        
        list hh_no tot_pop q_10 mean?, sepby(hh_no) 
        
        
             +----------------------------------------------+
             | hh_no   tot_pop   q_10      mean1      mean2 |
             |----------------------------------------------|
          1. |     1         0     54       33.5          . |
          2. |     1         0     44       33.5          . |
          3. |     1         0     14       33.5          . |
          4. |     1         3     22       33.5          . |
             |----------------------------------------------|
          5. |     2         0     52         40         40 |
          6. |     2         0     44         40         40 |
          7. |     2         3     24         40         40 |
             |----------------------------------------------|
          8. |     3         0     35      19.25      19.25 |
          9. |     3         0     29      19.25      19.25 |
         10. |     3         0      9      19.25      19.25 |
         11. |     3         4      4      19.25      19.25 |
             |----------------------------------------------|
         12. |     4         1     54         54         54 |
             |----------------------------------------------|
         13. |     5         0     46         32         32 |
         14. |     5         0     39         32         32 |
         15. |     5         3     11         32         32 |
             |----------------------------------------------|
         16. |     6         0     51      33.25      33.25 |
         17. |     6         0     44      33.25      33.25 |
         18. |     6         0     16      33.25      33.25 |
         19. |     6         4     22      33.25      33.25 |
             |----------------------------------------------|
         20. |     7         0     49   38.33333   38.33333 |
         21. |     7         0     44   38.33333   38.33333 |
         22. |     7         3     22   38.33333   38.33333 |
             +----------------------------------------------+

        Comment


        • #5
          Thanks Nick.

          Comment

          Working...
          X