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

st: How to capture record info where "something" about the record is true?


From   "Steichen, Thomas J." <[email protected]>
To   <[email protected]>
Subject   st: How to capture record info where "something" about the record is true?
Date   Fri, 22 Jul 2005 14:57:04 -0400

Listers, 
I need to efficiently capture, for example, the record id where something is true about that record.

For example, if I have the following made-up data:

  id x

  a  6
  b  32
  c  6
  d  11

I may want to capture a record id where x = max(x).
I know I can get it via:

  . egen mx = max(x)
  . gen rx = 1 if x == mx
  . sort rx 
  . local id_info = id   (or, more accurately, id[1])
  . di "ID info: `id_info'"
ID info: b

But an egen, gen, and sort seems to be an expensive way to do this with a large dataset.

The above solution will, of course, only capture one record id, where x=max(x).

If I had wanted x=min(x), it would be nice if id_info contained "a c". This is doable also, but becomes even more expensive in
computing time.

Can someone propose a more efficient way or point out a built-in command that I've missed?

Tom

Thomas J. Steichen
[email protected]
----------------------------------------------------------------------------
  Facts do not cease to exist because they are ignored. - Aldous Huxley
----------------------------------------------------------------------------


-----------------------------------------
CONFIDENTIALITY NOTE:  This e-mail message, including any  attachment(s),
contains information that may be confidential,  protected by the attorney-
client or other legal privileges, and/or  proprietary non-public
information.  If you are not an intended  recipient of this message or an
authorized assistant to an intended  recipient, please notify the sender by
replying to this message and  then delete it from your system.  Use,
dissemination, distribution,  or reproduction of this message and/or any of
its attachments (if  any) by unintended recipients is not authorized and
may be unlawful.


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