Hello,
I have a dataset like this one:
idvar stringvar
1 'word x','word y',...
2 'word z', 'word z', 'word z',...
3 ...
I need a new variable that counts the number of distinct/unique items in stringvar for each observation. Basically, I need to count the number of unique/distinct words, with no repetitions, for each observation. I know that the solutions may be very easy, but I have been struggling with it the whole day. Words are delimited by ' ' and separated by ,. I need a simple one-line solutions. I have been trying more complex approaches, like splitting stringvar into separate words, but it is too complex due to the huge size of my database.
Thank you
M.
I have a dataset like this one:
idvar stringvar
1 'word x','word y',...
2 'word z', 'word z', 'word z',...
3 ...
I need a new variable that counts the number of distinct/unique items in stringvar for each observation. Basically, I need to count the number of unique/distinct words, with no repetitions, for each observation. I know that the solutions may be very easy, but I have been struggling with it the whole day. Words are delimited by ' ' and separated by ,. I need a simple one-line solutions. I have been trying more complex approaches, like splitting stringvar into separate words, but it is too complex due to the huge size of my database.
Thank you
M.

Comment