Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: RE: Assign highest value per group to all members of that group
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: Assign highest value per group to all members of that group
Date
Fri, 4 Feb 2011 18:09:21 +0000
bysort G (X) : gen max_X = X[_N]
would do it if no X were ever missing.
egen max_X = max(X), by(G)
is a safer way to do it.
Nick
[email protected]
Owen Corrigan
My data contains individual observations (taking a value 0-8 on indep
variable X) divided into small unequal groups, where each group is
uniquely identified by a grouping variable (G). I want to identify the
highest value on X in each group uniquely identified by G and generate
a new variable assigning that value to all members of that group. It
should be a simple task, but standard data manipulation commands don't
seem up to it, and I'm not versed in writing code or loops in Stata.
Any quick and simple solutions greatly appreciated.
*
* 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/