Announcement

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

  • Count number of households with multiple IDs

    Hi all, I have some data below where individuals are nested within households.

    I know that, to isolate the number of unique households, I can simply do:

    Code:
    by household, sort: gen nvals = _n == 1
    tab nvals
    This tells me there are 31 unique households in my data. However, the question I really want to know the answer to is: "What percent of households have multiple individuals"? This would just be the inverse to what I did above if it were the case that all multi-individual households had only 2 individuals, but as you can see that is not the case with my data, some households have 3 or 4.

    Does anyone have a concise way of figuring this out? Thanks.




    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int(household individual)
    432 111
    433 112
    145 113
    145 114
    145 115
    145 116
    603 117
    439 118
    440 119
    441 120
    442 121
    443 122
    444 123
    784 124
    785 125
    447 126
    448 127
    449 128
    449 129
    449 130
    452 131
    453 132
    454 133
    455 134
    455 135
    457 136
    134 137
    459 138
    460 139
    460 140
    643 141
    345 142
    465 143
    674 144
    658 145
    255 146
    468 147
    336 148
    end
    Last edited by Anne Todd; 06 Jul 2023, 12:55.

  • #2
    Code:
    by household (individual), sort: gen byte multiple_members = _N > 1 if _n == 1
    tab multiple_members

    Comment

    Working...
    X