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

Re: st: Column and row maximums


From   "Stephen P. Jenkins" <[email protected]>
To   [email protected]
Subject   Re: st: Column and row maximums
Date   Tue, 19 Nov 2002 14:23:55 +0000 (GMT Standard Time)

On Tue, 19 Nov 2002 14:02:02 -0000 [email protected] wrote:

> Hello statalisters
> 
> I have a datasheet containing the following information (example)
> 
> A	B	C	D	E	F
> 1	2	3	4	5	6
> 2	8	5	4	9	6	
> 3	5	7	8	6	1
> 7	4	5	6	8	1
> 2	4	6	4	1	6
> 
> I need a command that will tell me what the highest number in column E is
> (in this example 9) and also return the value in column B for the same row
> (i.e. in this example 8).


. ge id = _n

. l

            a         b         c         d         e         f         id
  1.        1         2         3         4         5         6          1
  2.        2         8         5         4         9         6          2
  3.        3         5         7         8         6         1          3
  4.        7         4         5         6         8         1          4
  5.        2         4         6         4         1         6          5

. sort e

. replace b = e if _n==_N
(1 real change made)

. l

            a         b         c         d         e         f         id
  1.        2         4         6         4         1         6          5
  2.        1         2         3         4         5         6          1
  3.        3         5         7         8         6         1          3
  4.        7         4         5         6         8         1          4
  5.        2         9         5         4         9         6          2

. sort id

. list

            a         b         c         d         e         f         id
  1.        1         2         3         4         5         6          1
  2.        2         9         5         4         9         6          2
  3.        3         5         7         8         6         1          3
  4.        7         4         5         6         8         1          4
  5.        2         4         6         4         1         6          5

Or have I misunderstood what you were trying to accomplish? (And how do 
you want to treat repeated values for a maximum?)

Stephen
----------------------
Professor Stephen P. Jenkins <[email protected]>
Institute for Social and Economic Research (ISER)
University of Essex, Colchester, CO4 3SQ, UK
Tel: +44 (0)1206 873374. Fax: +44 (0)1206 873151.
http://www.iser.essex.ac.uk

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