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: Flagging most frequent occurrence
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Flagging most frequent occurrence
Date
Thu, 24 Oct 2013 09:40:23 +0200
On Thu, Oct 24, 2013 at 8:03 AM, Steven Archambault wrote:
> I have panel data, where observations occur in different years. I want
> to flag the year that occurs the most often.
*------------------ begin example ------------------
// input some example data
clear all
input ///
id year
1 2008
1 2008
1 2009
2 2009
2 2009
2 2010
2 2010
3 2009
3 2009
3 2010
end
// compute the flag
bys year : gen flag = _N
sum flag, meanonly
replace flag = (flag == r(max))
// admire the result
sort id year
list, sepby(id)
*------------------- end example -------------------
* (For more on examples I sent to the Statalist see:
* http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
---------------------------------
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/