Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Row mode
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Row mode
Date
Thu, 16 May 2013 09:29:53 +0200
On Thu, May 16, 2013 at 8:20 AM, Md. Alauddin Majumder wrote:
> I want to find ROW MODE.
*------------------ begin example ------------------
clear
input Row1 Row2 Row3 Row4
1 3 1 4
3 3 4 1
1 4 2 2
4 4 3 3
end
preserve
// turn the data in long format
gen id = _n
reshape long Row, i(id) j(rownr)
// find the mode(s)
bys id Row : gen freq = _N
bys id : egen max = max(freq)
gen ismode = freq == max
// display the mode
keep if ismode
bys id Row : keep if _n == 1
list id Row freq, sepby(id)
// return the data to its original form
restore
*------------------- end example -------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/