Hello, I have been attempting to generate a new variable to store multiple modes (at least the top two) from an existing string variable using the mode function of -egen- command. Would be best to be able to keep all the modes (all repeating values, appearing more then once per group). I want to obtain the modes by groups defined by three other variables (address and datayear are stored as string, code is numeric). I am getting an error message. Below is my code segment:
I then do a -collapse- (by address datayear code) with keeping the first non-missing value of the variable 'mostcommoncrime' for each group.
Code:
bysort address datayear code: egen mostcommoncrime = mode(crime) if crime!="", miss num(2) option nummode() may not be combined with by r(190);
Comment