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

Re: st: sort won't sort


From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: sort won't sort
Date   Wed, 08 Dec 2004 18:12:43 -0500

A wild guess, but are there leading spaces in the year variable for some of your cases?

Consider (and note the leading space in the replace statement):
------------------------------------------------------
. set obs 2
obs was 0, now 2

. gen str year="1900" in 1
(1 missing value generated)

. replace year=" 1901" in 2
year was str4 now str5
(1 real change made)

. sort year

. list

+-------+
| year |
|-------|
1. | 1901 |
2. | 1900 |
+-------+

.
----------------------------------------------------


At 02:54 PM 12/8/2004 -0800, you 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/
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601

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