Hi everyone,

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
I tried:
Code:
egen Wanted_count=total(Brand == "Cola"), by (HHNR)
But this just counts Brand "Cola" per household. What I need is the total count of Brand observation, if group HHNR contains "Cola"

I would really appreciate your help!

Thanks in advance, Amelie