Statalist


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

Re: st: how to generate row mode


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: how to generate row mode
Date   Wed, 23 Jan 2008 10:29:58 -0500

At 10:12 AM 1/23/2008, Fernando wrote:
Hello

I am trying to compute the equivalent to a rowmode, a function similar to rowmean in the egen command. i think the ado for a rowmode function (which may compute the mode across several variables) does not exist, does it? as an alternative i thought to reshape the data and collapse it using the mode but the mode is not a function to collapse the data.
is there a way to compute the mode across a set of variables for each subject?
[...]
I don't know of any such routine or function. And I suspect it is very hard to program it in Stata directly. Perhaps it is somewhat easier in mata. (?)

I would also warn you that the mode is potentially an ambiguous calculation; you need a tie-breaking decision rule. E.g., suppose your values are 3,3,4,4; what's the mode?

Putting that aside, I might suggest that you reshape your data into long form; then take the mode using the egen mode function; then reshape back to wide (or just select one record per unit-of-observation). The egen mode function has several options for tie-breaking. (I also have an alternative variant for yet another tie-breaking option -- to take the latest-occurring value.)

I hope this helps.
--David




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