Hi All.
I have data that contains school-level observations. I'd like to count the number of schools that are in the same district_id and serve at least one of the same grades.
For instance, if I had the following observations with school_id, district_id lowest_grade and highest_grade, then I'd like to create the last variable "count_same"
Here you can see observations 0 and 1 both get a "1" because they each have a school in the same district that overlaps with the grades it serves. Observation 2 is in the same district but serves a unique set of grades in that district, so it gets a "0". Observations 3 and 4 are in the same district but don't overlap in grades, so they both get a "0". Observation 5 overlaps with observation 6, so it gets a "1" and observation 6 overlaps with 5 and 7, so it gets a "2" and so on. I hope that's clear enough?
My feeling is that perhaps some form of an egen command might work. Or maybe some clever collapse and merge? Any guidance would be much appreciated!
I have data that contains school-level observations. I'd like to count the number of schools that are in the same district_id and serve at least one of the same grades.
For instance, if I had the following observations with school_id, district_id lowest_grade and highest_grade, then I'd like to create the last variable "count_same"
0 | 0 | 0 | 5 | 1 |
1 | 0 | 2 | 5 | 1 |
2 | 0 | 6 | 8 | 0 |
3 | 1 | 1 | 6 | 0 |
4 | 1 | 7 | 8 | 0 |
5 | 2 | 0 | 4 | 1 |
6 | 2 | 3 | 5 | 2 |
7 | 2 | 5 | 8 | 1 |
8 | 3 | 0 | 3 | 0 |
9 | 3 | 4 | 8 | 0 |
My feeling is that perhaps some form of an egen command might work. Or maybe some clever collapse and merge? Any guidance would be much appreciated!
Comment