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

st: RE: RE: RE: maximum 3 and minmium 3 values

From   "Shehzad Ali" <>
To   <>
Subject   st: RE: RE: RE: maximum 3 and minmium 3 values
Date   Thu, 19 Jun 2008 17:42:16 +0100

Thanks, Nick. These suggestions are helpful. I have followed -rowsort- help
file and it has done the trick, albeit in two steps.

Thank you,


-----Original Message-----
[] On Behalf Of Nick Cox
Sent: 19 June 2008 17:25
Subject: st: RE: RE: maximum 3 and minmium 3 values

You are referring to my -rowsort-.  

The comment about missing values here is cryptic. I imagine that you are
referring to the fact that missing values are (as is standard in Stata)
sorted to the high end by default. That will mess up your determination
of maxima and high order statistics generally. 

The help for -rowsort- indicates a way of dealing with this. Call
-rowsort- with the -missing()- option. You may need to call -rowsort-
twice, once for the three smallest, and once for the three largest with
the -missing- option specified. 

Jeff Arnold's -sortrows- from SSC is yet more general than -rowsort-. 

Although Martin earlier suggested -xpose-, that is not I think a good
alternative. Rather, -reshape- would seem greatly preferable. But as you
can do this in place no restructuring is necessary. 


Shehzad Ali

Thanks, Martin. - rowsort - does the trick, though the issue of missing
values is a pain but I can live with that. 

Martin Weiss

Actually, you got my suggestion right, but with 15.000 obs it is
not feasible. I bet other listers will provide a better suggestion. 
Note, though, that -ssc d rowsort- can sort for each observation. After
-keep- only the first three and last three columns and you have a
dataset with your desired results...

Shehzad Ali

Thanks, Martin. In the xpose file, do you mean I should sort for each
separately? If this is the case, then it will take forever with my
observations. Maybe I misunderstood your suggestion.

Martin Weiss

Admittedly, I jumped to an early conclusion as -egen- gives you the min
max per observation, but you asked for the three smallest and largest
values. You could -save- your data, then -xpose, clear- which leaves you
with columns representing observations in the original data. Then -sort-
according to each column and extract the three highest and lowest values
into a -postfile-. Other listers may be aware of packages that automate

Shehzad Ali

I have a dataset with 11 variables for which I want to find out maximum
and minimum 3 values for each observation. I am aware that we can use 
max(x1, x2..., xn) to get the first maximum or similarly first minimum. 
Please advise on how to get subsequent maximum and minimum values.

*   For searches and help try:

*   For searches and help try:

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