Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Sorting string variable based on a numeric variable


From   <M.Sanchez-Sache@lse.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Sorting string variable based on a numeric variable
Date   Wed, 10 Oct 2007 19:40:13 +0100

Hi all,
 
I have another problem arranging my dataset. I'm focusing now on two variables of my dataset. "Cars" is a string variable under which I have different car models. The second variable is "Price". I have different prices for the same car model. What I need to do is to sort ascendingly the prices of each car model, because I only want to keep the lowest price of each car model. I tried to use the commands -sort- and -by-, but I didn't succeed. 
 
Suppose my dataset is 
 
CAR                                PRICE
Renault Clio                      10000
Renault Clio                      11000
Renault Clio                      10500
Audi A4                            30000
Audi A4                            27000 
Audi A4                            28000
 
First I want to arrange the dat in this way
 
CAR                                PRICE
Renault Clio                      10000
Renault Clio                      10500
Renault Clio                      11000
Audi A4                            27000
Audi A4                            28000 
Audi A4                            30000
 
and then I only want to keep the first observation of each category
 
CAR                                PRICE
Renault Clio                      10000
Audi A4                            27000
 
Could you help me on that?
 
Thanks again!
 
Marta.

Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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