I am working with a scanner household panel and want to count all observations(purchases) of Brands, if the grouped HHNR (Household number) contains a certain Brand.
"HHNR" and "Brand" are given. And I want to get the values of the column "Wanted_Count"
E.g. The household who bough Cola, did in total 6 purchases of any Brand
HHNR | Brand | Wanted_Count |
1 | Cola | 6 |
1 | Fanta | 2 |
2 | Sprite | 2 |
2 | Water | 5 |
3 | Cola | 6 |
3 | Cola | 6 |
3 | Cola | 6 |
3 | Water | 5 |
Code:
egen Wanted_count=total(Brand == "Cola"), by (HHNR)
I would really appreciate your help!
Thanks in advance, Amelie

0 Response to Counting number of total observation if group contains a certain value
Post a Comment