Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Re: data management - loop?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Re: data management - loop?
Date   Wed, 23 May 2007 15:04:17 +0100

That is not provided by -egen, mode()-, but 
a first principles approach gets you there: 

Assume identifier -id- and time -time-. 
We want the mode of -myvar-, breaking 
ties for the highest frequency by 
which occurs latest. 

bysort id myvar : gen freq = _N 
replace freq = 0 if missing(myvar) 
bysort id (freq time) : gen mode = myvar[_N] 

Nick 
[email protected] 

David Kantor
 
> At 04:53 PM 5/22/2007, Nick Cox wrote:
> >[...]
> >
> >I don't think there is any obvious way to handle ties
> >for mode. There might be substantive solution(s) to that.
> 
> -egen ... mode()...-
> has some options for handling ties. In case anyone is interested, I 
> wrote a variation that breaks ties by taking the 
> latest-occurring in the data.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index