Announcement

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

  • Creating a distance variable for responses of individuals in a couple

    Hello,

    I am working with the Swiss Household Panel (individual dataset). I want to create a distance-variable that measures the difference between the answers of individuals that form a couple in regards to specific questions.
    Variable p11p69 measures the sympathy of the respondent towards a party (0 to 10)
    Each respondent has an identification number (idpers), is either listed as the reference person or the spouse, I also have the identification number of the household.
    How can I relate the answers of reference person and spouse to each other? How can I create a variable that answers the distance (difference) between responses?

    Many thanks.

  • #2
    Welcome to Statalist. For your future posts, please familiarize yourself with the dataex command for presenting data examples. See FAQ Advice #12 for details.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(hhid idpers hpos p11p69)
    1  1 1  6
    1  2 2  8
    1  3 3  5
    1  4 3  5
    2  5 2  7
    2  6 3  5
    2  7 3  5
    2  8 3  5
    3  9 1 10
    3 10 2  4
    3 11 3  5
    3 12 3  5
    end
    label values hpos lab
    label def lab 1 "head of household", modify
    label def lab 2 "spouse", modify
    label def lab 3 "child", modify
    
    bys hhid: egen val_head= max(cond(hpos==1, p11p69, .))
    bys hhid: egen val_spouse= max(cond(hpos==2, p11p69, .))
    gen wanted= abs(val_head-val_spouse)

    Res.:

    Code:
    . l, sepby(hhid)
    
         +---------------------------------------------------------------------------+
         | hhid   idpers                hpos   p11p69   val_head   val_sp~e   wanted |
         |---------------------------------------------------------------------------|
      1. |    1        1   head of household        6          6          8        2 |
      2. |    1        2              spouse        8          6          8        2 |
      3. |    1        3               child        5          6          8        2 |
      4. |    1        4               child        5          6          8        2 |
         |---------------------------------------------------------------------------|
      5. |    2        5              spouse        7          .          7        . |
      6. |    2        6               child        5          .          7        . |
      7. |    2        7               child        5          .          7        . |
      8. |    2        8               child        5          .          7        . |
         |---------------------------------------------------------------------------|
      9. |    3        9   head of household       10         10          4        6 |
     10. |    3       10              spouse        4         10          4        6 |
     11. |    3       11               child        5         10          4        6 |
     12. |    3       12               child        5         10          4        6 |
         +---------------------------------------------------------------------------+

    Comment

    Working...
    X