Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: Compute Modus accross variablesCompute Modus accross variables


From   Nick Cox <n.j.cox@durham.ac.uk>
To   "'statalist@hsphsun2.harvard.edu'" <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Compute Modus accross variablesCompute Modus accross variables
Date   Mon, 6 Dec 2010 11:15:14 +0000

I don't know of code for another way to do it. 

I think the best way to do it without a -reshape- would be to write a Mata function. You'd need to handle ties in frequency with some recipe. 

Nick 
n.j.cox@durham.ac.uk 

Christian Hunkler

I am looking for a command / ado that allows to compute the mode accross 
variables, possibly also for strings.

E.g. if  I had these data:

id     var1      var2       var3
1     1991     1992     1991
2     1960     1961     1961
3     1920     1920     1921

I would like to compute a variable storing the mode across lines:
id     mode
1     1991
2     1961
3     1920

I know this can easily done by some simple reshaping using -egen mode 
by- collapsing and merging the data again, but we deal with pretty large 
datasets (reshaping takes minutes) and we have to do this for a couple 
of variables. And we have to do this for variables storing names (which 
is possible with -egen mode by-).

Maybe there is something available to do this, I haven't found yet?

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