I'm not clear on why you want the mode
or what you want to do with it, so
advice is difficult. Let's look
at data accessible to all:
. sysuse auto, clear
Suppose you notice that -rep78-
contains missing values and, faute de mieux,
you decide to impute those by the mode.
Then
. egen mode = mode(rep78)
. tab mode
shows that the variable is a constant,
the mode for all the values, so that if you were to
. replace rep78 = mode if missing(rep78)
that would copy the mode into missing values.
But hang on: this is very crude. For example,
a tabulation of -foreign- and -rep78- makes
it clear that knowing -foreign- makes a difference
to the distribution of -rep78-. So a better guess
would be the mode of -rep78- given -foreign-. That
is
. egen mode2 = mode(rep78), by(foreign)
except that, as trying it will show, you now have
to start thinking about appropriate choices.
-mode()- was in the first instance written because
people asked for it, and -- just as saner people
practise the piano, or play card games, or make millions --
the author likes little programming problems. But I've never
found the mode enormously useful in practice...
Nick
[email protected]
peter harper
> Thank you Nick for your help. I am a little uncertain
> as to what I do next. My variable is increase in wage
> settlements occuring each year. I have done
> . egen modeinc = mode (incres)
> The variable modeinc appears on my variable list. I am
> not sure what I do next. I have tried various things
> but I do not appear to get the mode of this variable.
> Doing it manually is out of the question as I have an
> extremely large dataset.
> I would be be grateful, if you would let me know,
> references on how I obtain mode.
> Thanks in advance
>
> --- Nick Cox <[email protected]> wrote: > This
> isn't a simple question at all. If your
> > variable is discrete, two or more values may tie
> > for mode. If your variable is continuous, how
> > to define the mode is an open issue. Nevertheless,
> > -search mode- points to an -egen- function =mode()-
> > and a user-written command -modes-. From your
> > question
> > the first may be closer to what you want.
> >
> > The Statalist FAQ contains advice on using -search-
> > and other facilities.
> >
> > Nick
> > [email protected]
> >
> > peter harper
> >
> > > I wondered
> > > if anyone can tell me how do I obtain 'mode'(of
> > > course, it is term like mean, median etc.) of a
> > > variable for individual years. I have a dataset
> > for 21
> > > years.
> >
*
* 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/