Statalist


[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" <[email protected]>
To   <[email protected]>
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,

Shehzad


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 19 June 2008 17:25
To: [email protected]
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. 

Nick
[email protected] 

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
admittedly
not feasible. I bet other listers will provide a better suggestion. 
Note, though, that -ssc d rowsort- can sort for each observation. After
that
-keep- only the first three and last three columns and you have a
perfect
dataset with your desired results...

Shehzad Ali

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

Martin Weiss

Admittedly, I jumped to an early conclusion as -egen- gives you the min
and
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
this
task...

Shehzad Ali

I have a dataset with 11 variables for which I want to find out maximum
3 
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:
*   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