Code:
clear input id score school_code school_minimum 1 50 5678 54 1 50 3113 60 1 50 1001 45 2 55 4143 52 2 55 5678 54 2 55 3113 60 3 51 3113 60 3 51 3098 50 3 51 1001 45 4 62 3098 50 4 62 3113 60 4 62 8877 62 end
Code:
levelsof school_minimum, local(cutoffs) levelsof id, local(students) gen num_higher_score = . foreach c in `cutoffs' { local count_`c' = 0 foreach id in `students' { if score > `c' local ++count_`c' bysort school_code: replace num_higher_score = `count_`c'' if cutoff == `c' } }
0 Response to Count total number of observations bigger than each value in other variable
Post a Comment