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]
Re: st: Keep observations in 1/100 by country and year
From
Sergiy Radyakin <[email protected]>
To
"[email protected]" <[email protected]>
Subject
Re: st: Keep observations in 1/100 by country and year
Date
Tue, 7 May 2013 11:24:33 -0400
* * * * * * * * * Dear Estrella,
the following code keeps top 3 earners for each group defined by
occupation and marital status:
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
clear
sysuse nlsw88
drop if missing(wage) | missing(married) | missing(occupation)
egen g=group(occupation married)
gsort g -wage
by g: keep if _n<4
keep occupation married wage g
list, sepby(g)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
you can adapt this code for your needs replacing variables occupation
and marital status with country and year. Not sure what is your
"popularity" variable. In the example it is wage.
Best, Sergiy
On Tue, May 7, 2013 at 10:49 AM, Estrella Gomez <[email protected]> wrote:
> Hi, statalisters
>
> I have a dataset with songs by year and country. I would like to keep
> only the top 100 songs for each country each year (there are 18
> countries and 6 years). I have tried the following:
>
> gsort country year -tot_sales
> *because I want the songs with higher number of sales
>
> gen top100=0
> bysort country year: replace top100=1 in 1/100
> *to generate a dummy that takes value one for the top 100 songs, so I
> can drop observations that equals zero
>
> However, Stata says that it's not possible to combine "by" with "in"
>
> Any idea?
> Thanks a lot,
> Estrella
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/