Announcement

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

  • How to generate number of adults in a household

    Hi All,

    I am working with panel data for 3 periods (waves 3, 4, and 5). I have the following information: unique household identifier (hhid), unique person identifier (pid), wave, age, and household size (hsize).

    I want to create a new variable for the number of adults in a household defined as individuals aged 15 and above.

    Thanks.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float hhid long pid float(wave age hsize)
    300000 304623 3 39  2
    300000 304623 4 42  2
    300000 304623 5 44  3
    300000 304624 3 74  2
    300000 304624 4 77  2
    300000 304624 5 79  3
    300001 305249 3 21  5
    300001 305249 4 23  4
    300001 305249 5 25  5
    300001 305250 3 52  5
    300001 305250 4 55  4
    300001 305250 5 57  5
    300001 305268 3 55  5
    300001 305268 4 57  4
    300001 305268 5 59  5
    300001 305269 3 28  5
    300001 305269 4 30  1
    300001 305269 5 32  1
    300001 620952 3  4  5
    300001 620952 4  6  4
    300001 620952 5  8  5
    300002 319161 3 24  1
    300002 319161 4 27  1
    300002 319161 5 29  2
    300003 305291 3 51  .
    300003 305291 4 53  2
    300003 305291 5 55  4
    300003 309522 3 56  .
    300003 309522 4  .  .
    300003 309522 5  .  .
    300003 402779 3  9  .
    300003 402779 4 12  4
    300003 402779 5 13  4
    300003 582536 3 29  .
    300003 582536 4 31  2
    300003 582536 5 33  4
    300003 583034 3 27  .
    300003 583034 4 30  1
    300003 583034 5 31  1
    300004 302034 3 23  1
    300004 302034 4 26  1
    300004 302034 5 28  1
    300005 303039 3 44  1
    300005 303039 4 47  1
    300005 303039 5 49  1
    300006 305649 3 52  2
    300006 305649 4 54  1
    300006 305649 5 56  1
    300006 311353 3 90  2
    300006 311353 4 93  7
    300006 311353 5  .  .
    300007 407393 3  8  .
    300007 407393 4 11  .
    300007 407393 5 13  4
    300007 407397 3  6  .
    300007 407397 4  8  .
    300007 407397 5 10  3
    300008 319052 3 34  4
    300008 319052 4 37  7
    300008 319052 5 39  8
    300008 321630 3 52  4
    300008 321630 4 55  7
    300008 321630 5 57  3
    300008 321631 3 60  4
    300008 321631 4 63  7
    300008 321631 5 65  3
    300008 410590 3 13  4
    300008 410590 4 15  7
    300008 410590 5 18  3
    300009 301903 3 26  1
    300009 301903 4 28  1
    300009 301903 5 30  1
    300010 381188 3 22  .
    300010 381188 4 24  7
    300010 381188 5 26  2
    300010 409493 3 14  .
    300010 409493 4 16  3
    300010 409493 5 19  6
    300010 409494 3 17  .
    300010 409494 4 19  3
    300010 409494 5 22  6
    300010 620604 3  2  .
    300010 620604 4  5  7
    300010 620604 5  7  2
    300011 319823 3 50  .
    300011 319823 4 53  .
    300011 319823 5 55  .
    300011 319824 3 22  .
    300011 319824 4 24  .
    300011 319824 5 27  .
    300011 319825 3 46  .
    300011 319825 4 49  .
    300011 319825 5 51  .
    300011 470329 3 18  .
    300011 470329 4 20  .
    300011 470329 5 23  .
    300012 315004 3 54  9
    300012 315004 4 56  9
    300012 315004 5 58 10
    300012 315005 3 53  9
    end

  • #2
    This should at least create a variable, that counts the number of individuals per household and per wave which are 15 or older.
    Code:
    bysort hhid wave: egen age15 = total(age>=15)
    Last edited by Benno Schoenberger; 30 Aug 2024, 06:05.

    Comment


    • #3
      Charles:
      depending on what you've planned to do with your data, you may want to calculate the total o per wave number of persons aged>15 years per household:
      Code:
      . bysort hhid (wave): egen wanted=count( pid) if age>15
      
      
      . bysort hhid wave: egen wanted_2=count( pid) if age>15
      
      
      . list if hhid==300000
      
           +----------------------------------------------------------+
           |   hhid      pid   wave   age   hsize   wanted   wanted_2 |
           |----------------------------------------------------------|
        1. | 300000   304624      3    74       2        6          2 |
        2. | 300000   304623      3    39       2        6          2 |
        3. | 300000   304624      4    77       2        6          2 |
        4. | 300000   304623      4    42       2        6          2 |
        5. | 300000   304623      5    44       3        6          2 |
           |----------------------------------------------------------|
        6. | 300000   304624      5    79       3        6          2 |
           +----------------------------------------------------------+
      
      .
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment


      • #4
        This sounds like

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input float hhid long pid float(wave age hsize)
        300000 304623 3 39  2
        300000 304623 4 42  2
        300000 304623 5 44  3
        300000 304624 3 74  2
        300000 304624 4 77  2
        300000 304624 5 79  3
        300001 305249 3 21  5
        300001 305249 4 23  4
        300001 305249 5 25  5
        300001 305250 3 52  5
        300001 305250 4 55  4
        300001 305250 5 57  5
        300001 305268 3 55  5
        300001 305268 4 57  4
        300001 305268 5 59  5
        300001 305269 3 28  5
        300001 305269 4 30  1
        300001 305269 5 32  1
        300001 620952 3  4  5
        300001 620952 4  6  4
        300001 620952 5  8  5
        300002 319161 3 24  1
        300002 319161 4 27  1
        300002 319161 5 29  2
        300003 305291 3 51  .
        300003 305291 4 53  2
        300003 305291 5 55  4
        300003 309522 3 56  .
        300003 309522 4  .  .
        300003 309522 5  .  .
        300003 402779 3  9  .
        300003 402779 4 12  4
        300003 402779 5 13  4
        300003 582536 3 29  .
        300003 582536 4 31  2
        300003 582536 5 33  4
        300003 583034 3 27  .
        300003 583034 4 30  1
        300003 583034 5 31  1
        300004 302034 3 23  1
        300004 302034 4 26  1
        300004 302034 5 28  1
        300005 303039 3 44  1
        300005 303039 4 47  1
        300005 303039 5 49  1
        300006 305649 3 52  2
        300006 305649 4 54  1
        300006 305649 5 56  1
        300006 311353 3 90  2
        300006 311353 4 93  7
        300006 311353 5  .  .
        300007 407393 3  8  .
        300007 407393 4 11  .
        300007 407393 5 13  4
        300007 407397 3  6  .
        300007 407397 4  8  .
        300007 407397 5 10  3
        300008 319052 3 34  4
        300008 319052 4 37  7
        300008 319052 5 39  8
        300008 321630 3 52  4
        300008 321630 4 55  7
        300008 321630 5 57  3
        300008 321631 3 60  4
        300008 321631 4 63  7
        300008 321631 5 65  3
        300008 410590 3 13  4
        300008 410590 4 15  7
        300008 410590 5 18  3
        300009 301903 3 26  1
        300009 301903 4 28  1
        300009 301903 5 30  1
        300010 381188 3 22  .
        300010 381188 4 24  7
        300010 381188 5 26  2
        300010 409493 3 14  .
        300010 409493 4 16  3
        300010 409493 5 19  6
        300010 409494 3 17  .
        300010 409494 4 19  3
        300010 409494 5 22  6
        300010 620604 3  2  .
        300010 620604 4  5  7
        300010 620604 5  7  2
        300011 319823 3 50  .
        300011 319823 4 53  .
        300011 319823 5 55  .
        300011 319824 3 22  .
        300011 319824 4 24  .
        300011 319824 5 27  .
        300011 319825 3 46  .
        300011 319825 4 49  .
        300011 319825 5 51  .
        300011 470329 3 18  .
        300011 470329 4 20  .
        300011 470329 5 23  .
        300012 315004 3 54  9
        300012 315004 4 56  9
        300012 315004 5 58 10
        300012 315005 3 53  9
        end
        
        bysort hhid wave : egen wanted = total(inrange(age, 15, .))
        
        tabdisp hhid wave, c(wanted)
        
        ----------------------------
                  |       wave      
             hhid |    3     4     5
        ----------+-----------------
           300000 |    2     2     2
           300001 |    4     4     4
           300002 |    1     1     1
           300003 |    4     3     3
           300004 |    1     1     1
           300005 |    1     1     1
           300006 |    2     2     1
           300007 |    0     0     0
           300008 |    3     4     4
           300009 |    1     1     1
           300010 |    2     3     3
           300011 |    4     4     4
           300012 |    2     1     1
        ----------------------------
        For some broad trickery in this territory see

        https://journals.sagepub.com/doi/pdf...1536867X110110

        Comment


        • #5
          Originally posted by Nick Cox View Post


          For some broad trickery in this territory see

          https://journals.sagepub.com/doi/pdf...1536867X110110
          Unfortunately, I cannot find the linked document under the link provided. Instead I get the message "Error! The requested article is not currently available on this site."

          Comment


          • #6
            https://journals.sagepub.com/doi/pdf...867X1101100210 works for me. I left behind some characters on a copy and paste, so sorry about that.
            Last edited by Nick Cox; 30 Aug 2024, 06:54.

            Comment


            • #7
              Now it works fine, thank you for the correction!

              Comment


              • #8
                Many thanks to you all, for the responses.

                Comment


                • #9
                  Note that

                  Code:
                  age  > 15
                  in #2 and #3 does not include 15 — which is what you want — yet does include missings — which you may or may not want. OTOH

                  Code:
                  inrange(age, 15, .)
                  In #4 does include 15 yet does not include missings.

                  Comment

                  Working...
                  X