Hi,
I have panel data similar to example census data in sysuse:
and I would like to select first two in each region with highest divorce in string variable:
so for example in region "NE" would be "NY" and "PA", and record it into variable score, that would have ideally first two entries "NY","PA", then blanks then below for next region "OH","IL" etc.
the only thing that crosses my mind is something like this:
But in my data i have also third level of years in the panel and this loop thing becomes complicated, is there any simpler way to do the same?
Thank you
I have panel data similar to example census data in sysuse:
Code:
sysuse census, clear
Code:
gsort region -divorce
the only thing that crosses my mind is something like this:
Code:
sysuse census.dta, clear levelsof region, local(region) gen score = "" foreach l of local region { sum divorce if region == `l' replace score = state2 if divorce == r(max) & region==`l' sum divorce if region==`l' & score=="" replace score = state2 if divorce == r(max) & region==`l' } gsort region -divorce
But in my data i have also third level of years in the panel and this loop thing becomes complicated, is there any simpler way to do the same?
Thank you
Comment