Announcement

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

  • How to count for each household, the number of household member who present specific characteristics

    I would like to know how I could execute STATA commands in order to count for each household, the number of household members who present specific characteristics.

    Indeed, I use individual-based household survey database which can be presented as follows:
    hh_id indiv_id disabled disabled_hh
    01 011 1 0
    01 012 1 0
    02 021 2 1
    03 031 2 4
    03 032 2 4
    03 033 2 4
    03 034 2 4
    03 035 1 4
    04 041 1 0
    04 042 1 0
    05 051 2 1
    06 061 2 3
    06 062 2 3
    06 063 2 3
    07 071 1 0
    08 081 1 2
    08 082 1 2
    08 083 2 2
    08 084 2 2
    09 091 1 0
    10 101 1 1
    10 102 2 1
    10 103 1 1
    11 111 2 1
    hh_id = Household id
    indiv_id = Household member (individual) id
    disabled = no (1) or yes (2)
    disabled_hh = number of disabled in each household


    Which STATA commands can help to compute the disabled_hh column when considering information about 11 000 households?


    Thanks in advance for your availability.

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str2 hh_id str3 indiv_id byte disabled
    "01" "011" 1
    "01" "012" 1
    "02" "021" 2
    "03" "031" 2
    "03" "032" 2
    "03" "033" 2
    "03" "034" 2
    "03" "035" 1
    "04" "041" 1
    "04" "042" 1
    "05" "051" 2
    "06" "061" 2
    "06" "062" 2
    "06" "063" 2
    "07" "071" 1
    "08" "081" 1
    "08" "082" 1
    "08" "083" 2
    "08" "084" 2
    "09" "091" 1
    "10" "101" 1
    "10" "102" 2
    "10" "103" 1
    "11" "111" 2
    end
    
    by hh_id, sort: egen byte disabled_hh = total(disabled == 2)
    The coding of the variable disabled as no = 1 and yes = 2 is not really very convenient for working in Stata. (Actually, I doubt it's convenient for working in any statistical package, but be that as it may.) Almost anything you want to do in Stata will be easier if you recode this as no = 0 and yes = 1. That coding will make working with logical expressions easier. If you do make that change, the code for this task simplifies to:
    Code:
    by hh_id, sort: egen byte disabled_hh = total(disabled)
    In the future, when showing data examples, please use the -dataex- command to do so, as I have in this response. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Thanks Clyde for your clear explanations.

      Now, I get the solution. I also learnt about -dataex- command so that I will use it henceforth.

      Best.
      Armand.

      Comment

      Working...
      X