Announcement

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

  • Identifying observations in a panel

    Hi Statausers!

    I have a panel where I identify items with variable code, I have also 2 supermarket chains (sup_chain) and several waves:

    code sup_chain wave price
    001 A 1 10
    002 A 1 8
    001 B 1 10
    002 B 1 8
    001 A 2 12
    002 A 2 10
    001 B 2 12
    001 A 3 12
    002 A 3 12
    001 B 3 14
    So my question would be: How can I get the average price of those observations that appear in all the waves and in both supermarket chains? (in this case it would be only the observations identified with code 001 given that the one identified with 002 is not listed in wave 2 and 3 for sup_chain B).

    Cheers

  • #2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 code str1 sup_chain byte(wave price)
    "001" "A" 1 10
    "002" "A" 1 8
    "001" "B" 1 10
    "002" "B" 1 8
    "001" "A" 2 12
    "002" "A" 2 10
    "001" "B" 2 12
    "001" "A" 3 12
    "002" "A" 3 12
    "001" "B" 3 14
    end
    
    
    sort code wave sup_chain
    
    egen tag = tag(code wave sup_chain )
    
    egen count = total(tag), by(code)
    
    su price if count == 6
    
    list, sepby(code)
    
    +----------------------------------------------+
    | code sup_ch~n wave price tag count |
    |----------------------------------------------|
    1. | 001 A 1 10 1 6 |
    2. | 001 B 1 10 1 6 |
    3. | 001 A 2 12 1 6 |
    4. | 001 B 2 12 1 6 |
    5. | 001 A 3 12 1 6 |
    6. | 001 B 3 14 1 6 |
    |----------------------------------------------|
    7. | 002 A 1 8 1 4 |
    8. | 002 B 1 8 1 4 |
    9. | 002 A 2 10 1 4 |
    10. | 002 A 3 12 1 4 |
    +----------------------------------------------+
    .

    Comment

    Working...
    X