Statalist The Stata Listserver


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

st: RE: Sort values in rows


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Sort values in rows
Date   Wed, 7 Feb 2007 14:28:32 -0000

This came up only a few days ago. See the 
thread started by Hui Wang on 4th February. 

In brief, you can -reshape-, -sort- and -reshape-
back, or you can use -rowsort- from SSC. 

gen id = _n 
reshape long v, i(id) j(col) 
bysort id (v) : replace col = _n 
reshape wide v, i(id) j(col) 

Nick 
[email protected] 

Nikolaos A. Patsopoulos
 
> I have a large dataset with 5 variables that contains number 
> in random 
> order:
> v1 v2 v3 v4 v5
> 28    1    25    22    14
> 23    2    3    34    39
> 6    16    8    24    19
> 3    45    8    1    37
> 4    23    27    33    10
> 16    41    33    13    21
> ...................................
> ................................
> 
> 
> 
> I want to sort them in such a way that the 
> v1[i]<v2[i]<v3[i]<v4[i]<v5[i] 
> for each i:
> 
> 1 14 22 25 28
> 2 3 23 34 39
> ......

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