Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: logic for assigning values across an entire group


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: logic for assigning values across an entire group
Date   Tue, 22 Sep 2009 20:06:13 +0200

<>

**************
clear*

input  GROUP             STATUS
1                 1
1                 1
1                 3
2                 3
3                 1
3                 2
3                 2 
end

compress
list, noobs

bys GROUP: egen maxpergroup=max(STATUS)
**************


HTH
Martin

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Lloyd Dumont
Sent: Dienstag, 22. September 2009 20:00
To: statalist@hsphsun2.harvard.edu
Subject: st: logic for assigning values across an entire group

Hello.  I am battling the logic demons.  There has got to be a way to do
this using -egen- I think...

Let's say I have observations partitioned into groups.  Each observation has
a numeric value for STATUS, something like this...

GROUP             STATUS
1                 1
1                 1
1                 3
2                 3
3                 1
3                 2
3                 2 

I would like to create a third variable, HISTATUS, that takes the highest
value for STATUS within each group, and assigns it to every observation
within that group.  In the example above, HISTATUS would take on the value
of 3 for all obs in GROUP 1, 3 for the obs in GROUP 2, and 2 for all the obs
in GROUP 3.

Can someone please suggest a clever way of doing that?  I am guessing that
it would involve -egen- and the rank option, but I could be wrong about
that.

Thank you for your help.  Lloyd Dumont




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