Statalist


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

st: RE: sorting a variable list within each obs.(row)


From   "Rajesh Tharyan" <R.Tharyan@exeter.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: sorting a variable list within each obs.(row)
Date   Tue, 26 Aug 2008 04:29:09 +0100

Hi,

One way would be to use egen. -help egen - however, the negative values will
be picked up. To avoid that I create a new variable for each old one with
missing values replacing values<0.

* create new variables & replace negative with missing values

foreach var of varlist  v1- v4 {
gen `var'i=`var'
replace `var'i=. if `var'i<0
}

* use egen  to get the minimum of the row
egen min=rowmin(v1i- v4i)

* drop unnecessary variables
drop v*i

rajesh



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Murali
Kuchibhotla
Sent: 26 August 2008 03:34
To: statalist@hsphsun2.harvard.edu
Subject: st: sorting a variable list within each obs.(row)


Hello,
      I have a dataset that looks like this:

Obs.  V1  V2  V3  V4
1     -1  -2  3   5
2     4    5  7   9

I would like to create a variable that picks out the minimum positive value 
from each row, i.e. one that picks out 3 from row 1 and 4 from row 2.How do
I 
accomplish this? Thanks.


Murali


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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