Announcement

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

  • Creating dummy based on the response of other household members

    Hi everyone,

    I am working with a living conditions survey with information at the individual and household levels. In one of the questions, the individuals are asked about the primary caregiver of the household, and they report the individual's identifier (ind). I want to create the variable dummy, where I assign a value of 1 to the individuals whom at least one member of the household identified as the primary caregiver and 0 otherwise.

    hhold ind caregiver dummy
    1 1 1 1
    1 2 1 1
    1 3 2 0
    1 4 1 0
    2 1 1 1
    2 2 1 0
    . . . .
    . . . .
    . . . .

    The variable hhold has the identifier of the household, and the variable caregiver has the response to the primary caregiver question.

    Thank you,

    Tessa


  • #2
    Tessa:
    do you mean something along the folllowing lines?
    Code:
    . input hhold ind caregiver dummy
    
             hhold        ind  caregiver      dummy
      1. 1 1 1 1
      2. 1 2 1 1
      3. 1 3 2 0
      4. 1 4 1 0
      5. 2 1 1 1
      6. 2 2 1 0
      7. end
    
    . bysort hhold: egen wanted=mode( caregiver)
    
    . drop dummy
    
    . replace wanted=0 if caregiver!=wanted
    
    
    . list
    
         +---------------------------------+
         | hhold   ind   caregi~r   wanted |
         |---------------------------------|
      1. |     1     1          1        1 |
      2. |     1     2          1        1 |
      3. |     1     3          2        0 |
      4. |     1     4          1        1 |
      5. |     2     1          1        1 |
         |---------------------------------|
      6. |     2     2          1        1 |
         +---------------------------------+
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      I used rangestat from SSC.

      Code:
      clear 
      input hhold ind caregiver dummy
      1 1 1 1
      1 2 1 1
      1 3 2 0
      1 4 1 0
      2 1 1 1
      2 2 1 0
      end 
      
      rangestat (count) ind , interval(caregiver ind ind) by(hhold)
      gen wanted = !missing(ind_count) 
      
      list, sepby(hhold)
      
           +----------------------------------------------------+
           | hhold   ind   caregi~r   dummy   ind_co~t   wanted |
           |----------------------------------------------------|
        1. |     1     1          1       1          3        1 |
        2. |     1     2          1       1          1        1 |
        3. |     1     3          2       0          .        0 |
        4. |     1     4          1       0          .        0 |
           |----------------------------------------------------|
        5. |     2     1          1       1          2        1 |
        6. |     2     2          1       0          .        0 |
           +----------------------------------------------------+

      Comment


      • #4
        Thank you, Nick. It worked perfectly!

        Comment

        Working...
        X