[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: how to get a scalar value of the ... mode
Recently Roger adviced us on how to get a scalar value of the column
Works OK, for the most of the statistics, but I need the mode. After
short look on manuals, no funtion returns r(mode). Currently I'm using
egen and picking an observation from the created variable, but there
must be an easy way.
>>> Depends what you call easy. A sufficient reason for no r(mode)
being defined is that even when a mode is interesting and useful, it
be uniquely defined.
Setting aside the possibility of ties, I cannot improve on
egen Mode = mode(varname)
scalar mode = Mode
which is presumably similar to what you did.
The shortest code I can come up with from first principles
bysort varname : gen freq = _N * (varname < .)
scalar mode = varname[_N]
* For searches and help try: