Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: sort won't sort


From   Tom Trikalinos <[email protected]>
To   [email protected]
Subject   Re: st: sort won't sort
Date   Thu, 9 Dec 2004 09:20:31 +0200

Year is a string variable with 5 characters. So you have leading spaces in some observations.
Try
. g year4 = trim(year)
. sort year4

or convert year to a numeric

. destring year , gen(yearNum)
. sort yearNum
tom

trim removes leading and trailing blank spaces in a string.


On Dec 9, 2004, at 12:54 AM, Michael McCulloch wrote:


Hello,
I am sorting a dataset on variable "year", (str5 %9s).
When I list on year, some are out of order.
I've tried re-sorting, or creating a new variable with the same text, but no luck.

. sort year
. list id year if exc==0
+-------------+
| id year |
|-------------|
9. | 43 1997 |
10. | 43 1997 |
79. | 237 2004 |
80. | 237 2004 |
81. | 35 1998 |
82. | 191 1998 |
|-------------|
83. | 22 2000 |
84. | 277 2004 |
+-------------+

.


*
* 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/

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index