Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | "Md. Alauddin Majumder" <mm4v@mtmail.mtsu.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | RE: st: Row mode |
Date | Thu, 16 May 2013 11:30:42 +0000 |
Thanks Nick and Maarten for your instructive suggestions! Majumder ________________________________________ From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Nick Cox [njcoxstata@gmail.com] Sent: Thursday, May 16, 2013 2:31 AM To: statalist@hsphsun2.harvard.edu Subject: Re: st: Row mode See http://www.stata.com/statalist/archive/2013-04/msg00301.html for a comment on expressions like "a data". The easiest way I know is to -reshape- before and after. Note that -egen, mode()- won't play with your 4th example, where 3 and 4 tie for mode, so you need a rule such as -minmode-. . l +---------------------------+ | row1 row2 row3 row4 | |---------------------------| 1. | 1 3 1 4 | 2. | 3 3 4 1 | 3. | 1 4 2 2 | 4. | 4 4 3 3 | +---------------------------+ . gen id = _n . reshape long row, i(id) (note: j = 1 2 3 4) Data wide -> long ----------------------------------------------------------------------------- Number of obs. 4 -> 16 Number of variables 5 -> 3 j variable (4 values) -> _j xij variables: row1 row2 ... row4 -> row ----------------------------------------------------------------------------- . egen mode = mode(row), by(id) minmode . reshape wide (note: j = 1 2 3 4) Data long -> wide ----------------------------------------------------------------------------- Number of obs. 16 -> 4 Number of variables 4 -> 6 j variable (4 values) _j -> (dropped) xij variables: row -> row1 row2 ... row4 ---------------------------------------------------------------------- Nick njcoxstata@gmail.com On 16 May 2013 07:20, Md. Alauddin Majumder <mm4v@mtmail.mtsu.edu> wrote: > Dear Statalist, > I have a data like the following: > > Row1 Row2 Row3 Row4 > 1 3 1 4 > 3 3 4 1 > 1 4 2 2 > 4 4 3 3 > > I want to find ROW MODE. Any help will be greatly appreciated! > > Thanks in advance > Majumder > > > > > > > > > > > > > > > > > > > > > > > > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/