Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Row mode

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: Row mode Date Thu, 16 May 2013 08:31:17 +0100

```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!
>
> 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/
```

• Follow-Ups:
• References:
• st: Row mode
• From: "Md. Alauddin Majumder" <mm4v@mtmail.mtsu.edu>