Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Keep observations in 1/100 by country and year


From   Estrella Gomez <estrellastata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Keep observations in 1/100 by country and year
Date   Tue, 7 May 2013 16:49:39 +0200

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index