I have this problem: Find the university with the largest number of students aged 12 years old. What is the number of 12 years old students in this university?
and I am using this code:
keep if age==12
by id_uni, sort: gen new_var = _N
gsort -new_var
Is there a better way of doing this in Stata?
Here is another way to do it that is not destructive.
In principle you should check that the highest value occurs for only one university.
I am alarmed at the thought of any university with students 12 years old.