Hello Community,
I've been struggling with this one. I have a dataset which is a questionnaire, in this dataset there are variables that include more than one answer. For example one of the questions is "what new product would you like to see" and the answers are multiple choice but the interviewee can answer as many different options as they prefer.
This variable is new_products. It is imported as a string variable with delimiter "," for those who have answered with multiple options. I am trying to encode it into a numeric value but when I do that each combination of answers is given a different value, instead of each option given a number then delimited by "," for those with multiple answers.
Instead, I used split to split up the variable which created 22 new variables. I then encoded the new variables using the same label, now I want to be able to tabulate across all of these variables, how can I do that? Is there a better way to encode a string variable with a delimiter or am I on the right track? I want to be able to analyze the data now, i.e what percentage of people chose option 1, etc..
Here is my code for this variable:
split newproducts, gen(new_products_split)
encode new_products_split1, gen(new_prod1) label(prods)
encode new_products_split2, gen(new_prod2) label(prods)
encode new_products_split3, gen(new_prod3) label(prods)
encode new_products_split4, gen(new_prod4) label(prods)
encode new_products_split5, gen(new_prod5) label(prods)
encode new_products_split6, gen(new_prod6) label(prods)
encode new_products_split7, gen(new_prod7) label(prods)
encode new_products_split8, gen(new_prod8) label(prods)
encode new_products_split9, gen(new_prod9) label(prods)
encode new_products_split10, gen(new_prod10) label(prods)
encode new_products_split11, gen(new_prod11) label(prods)
encode new_products_split12, gen(new_prod12) label(prods)
encode new_products_split13, gen(new_prod13) label(prods)
encode new_products_split14, gen(new_prod14) label(prods)
encode new_products_split15, gen(new_prod15) label(prods)
encode new_products_split16, gen(new_prod16) label(prods)
encode new_products_split17, gen(new_prod17) label(prods)
encode new_products_split18, gen(new_prod18) label(prods)
encode new_products_split19, gen(new_prod19) label(prods)
encode new_products_split20, gen(new_prod20) label(prods)
encode new_products_split21, gen(new_prod21) label(prods)
encode new_products_split22, gen(new_prod22) label(prods)
Any tips would be much appreciated!
Best,
Yousef
0 Response to encoding a string variable with a delimiter
Post a Comment