Dear Stata users,
in my panel dataset I want a dummy for the most occurred value in a variable.
e.g. for a household a variable can take values from 1 to 250, value 15 is the most named
value in one household, so I want a dummy which is 1 when the household named 15
otherwise 0.
I have some idea but I'm lost in getting the proper loop:
tab var, gen(var)
forvalues i=1(1)250 {
bysort household: gen N_`i'=sum(var`i')
bysort household: replace N_`i'=N_`i'[_N]
}
* Now some loop for:
bysort hh: gen dummy=1 if N_1 > N_2 & N_1 > N_3 & N_1 > N_4 ********more
possible values from 1 to 250 but not every number is named************* & var1 ==1
* here all other possibilities...
Some idea or an easier way?
Thanks.
Alex
*
* 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/