Hi,
I have a dataset that looks like this. The real data set has 100,000 observations and around 4000 firms and 800 job categories.
Firm JobCategory year city
A 1 2019 NYC
A 1 2019 BOS
A 1 2019 ATL
A 2 2018 NYC
B 2 2018 NYC
B 3 2019 NYC
C 3 2018 NYC
I need to count how many unique rivals each firm has. Firm X has a rival if another firm has the same job category in the same city. For example, Firm A has 1 rival- Firm B, Firm B has 2 rivals- Firm A,B, and Firm C has 1 rival-Firm B. Is there a way to write code that will give me a variable that contains how many rivals each firm has? I keep double-counting rivals and even counting the own firm as a rival with my code.
Thanks!
Best,
Reeves
I have a dataset that looks like this. The real data set has 100,000 observations and around 4000 firms and 800 job categories.
Firm JobCategory year city
A 1 2019 NYC
A 1 2019 BOS
A 1 2019 ATL
A 2 2018 NYC
B 2 2018 NYC
B 3 2019 NYC
C 3 2018 NYC
I need to count how many unique rivals each firm has. Firm X has a rival if another firm has the same job category in the same city. For example, Firm A has 1 rival- Firm B, Firm B has 2 rivals- Firm A,B, and Firm C has 1 rival-Firm B. Is there a way to write code that will give me a variable that contains how many rivals each firm has? I keep double-counting rivals and even counting the own firm as a rival with my code.
Thanks!
Best,
Reeves
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str1 firm float(JobCategory year) str3 city "A" 1 2019 "NYC" "A" 1 2019 "BOS" "A" 1 2019 "ATl" "A" 2 2018 "NYC" "B" 2 2018 "NYC" "B" 3 2019 "NYC" "C" 3 2018 "NYC" "D" 4 2019 "ATL" "D" 4 2019 "BOS" "D" 1 2018 "SLC" "D" 2 2018 "ATL" "D" 1 2019 "BOS" end
Comment