Statalist


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

RE: st: RE: obs no of max value


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: obs no of max value
Date   Tue, 23 Sep 2008 09:32:41 +0200

Well, thanks, but on a more general level, one should never generate a whole
vector of a constant value in Stata (at least I cannot think of a reasonable
case where you would need it...). You were throwing away resources with your
-egen- line and I avoided that, that`s all.


Best
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ashim Kapoor
Sent: Tuesday, September 23, 2008 9:29 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: RE: obs no of max value

wow! that was impressive. Thank you.

On Tue, Sep 23, 2008 at 12:51 PM, Martin Weiss <martin.weiss1@gmx.de> wrote:
> As long as you do not want to use -by- you can
>
> ***********
> sysuse auto, clear
> su trunk, mean
> g byte maxtag=1 if trunk==r(max)
> ***********
>
> HTH
> Martin
>
> -----Original Message-----
> From: owner-statalist@hsphsun2.harvard.edu
> [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ashim Kapoor
> Sent: Tuesday, September 23, 2008 9:16 AM
> To: statalist@hsphsun2.harvard.edu
> Subject: st: obs no of max value
>
> Hello everyone,
>
> Suppose I have a variable  " Age". I wish to find out at which
> observation does age have a max at. One way to do this is to write a
> while loop. I think that's horrid.
>
> I guess I could do  : -
>
> egen mAge=max(Age)
>
> gen index=_n if Age==mAge
>
> But this puts the right value of _n only in ONE observation. I can
> play around with 0's and use egen total to get this in ALL
> observations  , but I was wondering if anyone knew a DIRECT way of
> doing this in one go.
>
> Thank you,
> Ashim,
> *
> *   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/
>
*
*   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