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

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


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

Thanks Nick,

A variation on "levelsof id if <condition>" appears to accomplish what I need.

It is far more efficient with respect to programmer time and effort but I haven't checked whether it is cpu-cycle efficient.

Tom


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



> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Nick Cox
> Sent: Friday, July 22, 2005 3:03 PM
> To: [email protected]
> Subject: st: RE: How to capture record info where "something" 
> about the record is true?
> 
> 
> -findobs- by Sean Becketti is the most substantial 
> work in this area that springs to mind. 
> 
> I can't suggest anything much simpler than 
> 
> gen long id = _n 
> 
> su id if <condition>, meanonly 
> 
> list id if <condition> 
> 
> levelsof id if <condition> 
> 
> Nick 
> [email protected] 
> 
> Steichen, Thomas J.
> 
> > 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?
> 
> *
> *   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/
> 

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