[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Re: data management - loop?
The same approach is taken further in -egen, mode()-. It is
careful about missing values, and offers some handles for
alternative definitions of modes in the presence of ties.
A way in would be
bysort household : egen modevar = mode(var), <options>
gen byte dummyvar = var == modevar if var < .
I don't think there is any obvious way to handle ties
for mode. There might be substantive solution(s) to that.
There's a much easier way -- without creating the 250 dummies or any
bysort household var: gen count=_N
bysort household (count): gen byte dummy=count==count[_N]
In the event of ties (two values of var with equal frequency), then both
will be included by the dummy.
> in my panel dataset I want a dummy for the most occurred value in a
> e.g. for a household a variable can take values from 1 to 250, value
> the most named
> value in one household, so I want a dummy which is 1 when the
> otherwise 0.
* For searches and help try: