Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Dimitriy V. Masterov" <dvmaster@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: FW: Ranking a string variable |
Date | Mon, 23 Jan 2012 13:20:50 -0500 |
Does "bysort department time: gen rank=_n" do the trick? DVM On Mon, Jan 23, 2012 at 1:11 PM, Peci, Adriana (OAHPP) <Adriana.Peci@oahpp.ca> wrote: > > Hello stata listers, > > I need some help to rank a string variable by two other variables. My > data are in a long form in which one observation is listed more than > once. > The variable of interest is Item purchased which I would like to rank > based on the Department that this item belongs to and > The time whern this item was purchased. > So if departments categories are A, B, C, D etc (string variable) which > are listed more than once in the database and the items are unique > values as x, y, z,.(string variable) etc. > I want to count items of each department by purchased time as 1, 2, 3, > 4, 5. So in case of two items were purchased at the same time I want > them to be randomly ranked as 1, 2 and not 1,1. > > I am trying to use the egen command: bysort department time: egen rank > =rank(item) but it doesn't work for a string variables. > > Can anyone help me with that ? > > > Thank you so much, > > > Adriana Peci > > * > * 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/ * * 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/