Code:
clear input float firm_id str6 market 1 "a" 1 "b" 1 "c" 1 "d" 2 "b" 2 "c" 2 "f" 3 "a" 3 "b" 4 "c" end
What I would like to accomplish ultimately is generating a column variable that takes the average number of overlapping markets that each firm has with other firms in the dataset. Let's call this column avg_n_overlap. Using firm "1" as an example, firm "1" has 2 overlapping markets with firm "2", 2 overlapping markets with firm "3", and 1 overlapping market with firm "4". Therefore, after taking the average of these numbers, firm "1" will have the value 1.6666 (=(2+2+1)/3).
After calculating this avg_n_overlap, the final dataset that I am trying to create would look like below:
Code:
clear input float firm_id str6 market float avg_n_overlap 1 "a" 1.6666666 1 "b" 1.6666666 1 "c" 1.6666666 1 "d" 1.6666666 2 "b" 1.3333334 2 "c" 1.3333334 2 "f" 1.3333334 3 "a" 1 3 "b" 1 4 "c" .6666667 end
Comment