Hello,
input hid day_bought min_day str20 product str20 manufacturer
hid day_bought min_day product manufacturer
1. 1 10 5 "A" "a"
2. 1 8 5 "A" "a"
3. 1 5 5 "A" "a"
4. 1 7 7 "B" "a"
5. 1 8 7 "B" "a"
6. 1 11 11 "C" "c"
7. 1 12 11 "C" "c"
8. 2 12 9 "A" "a"
9. 2 9 9 "A" "a"
10. 2 11 3 "C" "c"
11. 2 3 3 "C" "c"
12. 2 4 3 "C" "c"
13. 3 4 2 "B" "a"
14. 3 2 2 "B" "a"
15. 4 19 2 "A" "a"
16. 4 15 2 "A" "a"
17. 4 2 2 "A" "a"
18. 4 16 16 "B" "a"
19. 4 18 16 "B" "a"
20. end
I am trying to compute a few descriptive variables. First, a "manufexp" variable which counts how many time was the household (hid) exposed to a product of the same manufacturer (that isn't the same product). Here's an example for what this new variable should look like
manufex~y
1. 0
2. 0
3. 0
4. 1
5. 1
6. 0
7. 0
8. 0
9. 0
10. 0
11. 0
12. 0
13. 0
14. 0
15. 1
16. 0
17. 0
18. 1
19. 1
Which mentions in this example purchase 4. and 5., since household 1 was exposed to manufacturer "1" through his purchase 3. and purchase 15., since household 4 was exposed to manufacturer "a" by day 19 through purchase 19 and also 18 and 19 since he was exposed to manufacturer "a" when purchasing "B" through purchase 16.
Second, I want a variable which mentions the number of exposures to the same manufacturers before each fist purchase for all products (the manufexp) to be the same for every household and every product (just like min_day is the same min_day).
I tried this
bysort hid prod: egen manufexp = count(manufacturer) if day_bought<min
and it doesn't work as I get only missing values everywhere.
Thank you very much in advance,
Sincerely,
SA
Related Posts with Condition on bysort and count across all observations by group
reghdfe: saving fixed effect + its standard errorHi everyone, I am estimating a triple Difference-in-Differences model in STATA to analyse the effe…
xtset and xtreg with all coefficients zeroHi everyone, I am new to using panel data on stata so I had a few questions. I am using the India …
Duplicates - keep first and sometimes second...Hello I am working with a large dataset in Stata with 40,000 stroke patients admitted to a hospital…
statistical analysis on two-eye datasetHi everyone, I am very new to stata and I am trying to do an analysis with both eyes of one individu…
Testing robustnessHello, I'm writing my thesis on the effect of nationality diversity on firm performance. I'm using …
Subscribe to:
Post Comments (Atom)
0 Response to Condition on bysort and count across all observations by group
Post a Comment