Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Identify observations by occupation
From
Oliver Jones <[email protected]>
To
[email protected]
Subject
st: Identify observations by occupation
Date
Tue, 17 Apr 2012 10:45:43 +0200
Dear Stata-Listers,
I have a dataset containing the number of employed people
for 180 cities and 300 occupations.
Now I want to generate a variable that shows the ranking
of the occupations by the total number of people working
in that occupation.
I have managed to create this variable. But I bet there is
a more elegant and easier way to do it and I hope some one
here can show me how or tell me the appropriate command(s).
Here is what I have done ...
The data looks like this:
city | occupation | n
-----------------------------
001 | nurse | 1222
002 | nurse | 345
. | . | .
. | . | .
. | . | .
180 | nurse | 94
.............................
001 | lawyer | 308
002 | lawyer | 55
. | . | .
. | . | .
. | . | .
180 | lawyer | 15
.............................
001 | teacher | 930
. | . | .
. | . | .
. | . | .
bysort occupation: egen total_occupation = total(n)
bysort total_occupation: gen index = (_n == 1)
sort index total_je_beruf
bysort index: gen top_occupation = _N + 1 - _n
replace top_occupation = . if index == 0
sort top_occupation
* List the biggest 10 occupations
list occupation total_occupation top_occupation if top_occupation <= 10
Best Regards
Oliver Jones
--
Universität Bielefeld
Fakultät für Wirtschaftswissenschaften
Lehrstuhl für Ökonometrie und Statistik
- -
Bielefeld University
Faculty of Business Administration and Economics
Chair of Econometrics and Statistics
- -
Raum / room: V9-108
Tel / phone: +49 (0)521 106 4895
- -
http://www.wiwi.uni-bielefeld.de/oekonometrie.html
---
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/