Hello!
I'm trying to combine a number of dichotomous variables into a single categorical variable. This is data from qualtrics where participants selected all applicable race/ethnicity categories that applied to them. This results in a number of variables (one for each response option). If they selected the option the variable has data, if not the variable data is missing. Example below
I have seen solutions when the data in the columns are mutually exclusive or if people want to only keep one of the responses. Here instead I want to have the variable reflect their race/ethnicity selected BUT if they selected more than one response, then I want it to create a new category (i.e., "Multiracial").
I have done this in SPSS myself, but I have students in my class use Jamovi and I've not been able to advise them how to make this work for their data they have collected. This is the SPSS code that I use, for reference.
COMPUTE ethnicity=sysmis.
IF Q10_1=1 ethnicity=1.
IF Q10_11=1 ethnicity=2.
IF Q10_12=1 ethnicity=3.
IF Q10_14=1 ethnicity=4.
IF Q10_7=1 ethnicity=5.
IF Q10_8=1 ethnicity=6.
IF Q10_13=1 ethnicity=7.
IF Q10_3=1 ethnicity=8.
IF ((Q10_11=1) & (Q10_1=1)) ethnicity=9.
IF ((Q10_11=1) & (Q10_12=1)) ethnicity=9.
IF ((Q10_12=1) & (Q10_1=1)) ethnicity=9.
IF ((Q10_1=1) & (Q10_14=1)) ethnicity=9.
IF ((Q10_12=1) & (Q10_14=1)) ethnicity=9.
IF ((Q10_1=1) & (Q10_12=1)) ethnicity=9.
IF ((Q10_12=1) & (Q10_7=1)) ethnicity=9.
Execute.
Is there are way to do this in Jamovi? I tried some responses from ChatGPT for doing a computed variable but they didn't work with my data file.
Combine Multiple Non-Mutually Exclusive Variables
Re: Combine Multiple Non-Mutually Exclusive Variables
Hi,
thanks for raising this. so called "multiple response variables" are something of an area of weakness in jamovi at the moment.
i've made a couple of changes to jamovi to better support this; i've added an ignore_missing argument to the HLOOKUP() function, and i've added a COUNT() function too. these will go out in the next release. (I assume we're probably too late for your class, but let me know if it would be helpful if i pushed the new version out now).
IF(
COUNT(Q10_1, Q10_11, Q10_12, Q10_14, Q10_7, Q10_8, Q10_13, Q10_3) > 1,
"Multi-racial",
HLOOKUP(1, Q10_1, Q10_11, Q10_12, Q10_14, Q10_7, Q10_8, Q10_13, Q10_3, ignore_missing=1))
the HLOOKUP(1, ... finds the first value in Q10_1, Q10_11, etc. and when called with ignore_missing=1, it finds the first non missing value.
jonathon
thanks for raising this. so called "multiple response variables" are something of an area of weakness in jamovi at the moment.
i've made a couple of changes to jamovi to better support this; i've added an ignore_missing argument to the HLOOKUP() function, and i've added a COUNT() function too. these will go out in the next release. (I assume we're probably too late for your class, but let me know if it would be helpful if i pushed the new version out now).
IF(
COUNT(Q10_1, Q10_11, Q10_12, Q10_14, Q10_7, Q10_8, Q10_13, Q10_3) > 1,
"Multi-racial",
HLOOKUP(1, Q10_1, Q10_11, Q10_12, Q10_14, Q10_7, Q10_8, Q10_13, Q10_3, ignore_missing=1))
the HLOOKUP(1, ... finds the first value in Q10_1, Q10_11, etc. and when called with ignore_missing=1, it finds the first non missing value.
jonathon
Re: Combine Multiple Non-Mutually Exclusive Variables
Currently, this works, though it's not very concise . . .
-
-
Re: Combine Multiple Non-Mutually Exclusive Variables
Oh this worked!! Thank you so much @reason180.
I would look forward to a simpler solution in the future, but I will happily save this as a solution for now. I appreciate it!
Thank you Jonathan for keeping this in mind as a future fix.
I would look forward to a simpler solution in the future, but I will happily save this as a solution for now. I appreciate it!
Thank you Jonathan for keeping this in mind as a future fix.