Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to use Multiple Choice answers saved to Participant/Token data

More
5 hours 12 minutes ago #273564 by rwinford77
Please help us help you and fill where relevant:
Your LimeSurvey version:   LimeSurvey Community Edition Version 6.16.2+251209
Own server or LimeSurvey hosting:  own
Survey theme/template:  Bootstrap Vanilla
==================

I am using Denis' Plugin  UpdateTokenByResponse.  (very very helpful).  I have it working correctly for the simple case, but now I'm trying to figure out how to use it for a Multiple Choice question.
We collect data every month using the same survey, closed, with about 400 participants.  There are 13 numeric questions and few text questions that are personal data (name, region, etc.)   Those questions I am already updating in the participant/token data. 

We also have one Multiple Choice question with 26 options and 1, 2, or 3 answers are required.  Almost always the answers for each user are the same from month to month, so I would like to update them to the participant/token data, such as ATTRIBUTE_6,  ATTRIBUTE_7, etc.  and then reuse them for the next month.

I don't know if I should reserve 26 ATTRIBUTE fields or only 3.  

I have tried an Equation Question with a very long if/else structure that gets very cumbersome to use, especially since it allows 1 or 2 or 3 answers.  I thought of a loop:   for x = 1 to count('Y', q1.SQ001, q1.SQ002,......q1.SQ026)  then ATTRIBUTE_x = ....
but there's no such construct that I can find.

I thought of using 3 Equation Questions using the relevance of count("Y", q1.SQ001, q1.SQ002, q1.SQ003, etc.) so that only the correct EQ question would be used, based on the number of selections they made.  

Any suggestions?

thanks,
Rick


 

Please Log in to join the conversation.

More
3 hours 7 minutes ago #273565 by Joffm
Hi,
you can do this with one single attribute.
Remembering, that the integer representation of a boolean value is TRUE = "1" and FALSE = "0" you can join the results of the 26 subquestions in an equation like
Code:
{join(intval(Q1_SQ001=="Y"), intval(Q1_SQ002=="Y"), intval(Q1_SQ003=="Y"), intval(Q1_SQ004=="Y"), intval(Q1_SQ005=="Y"), intval(Q1_SQ006=="Y"), intval(Q1_SQ007=="Y"), intval(Q1_SQ008=="Y"), intval(Q1_SQ009=="Y"), intval(Q1_SQ010=="Y"), intval(Q1_SQ011=="Y"), intval(Q1_SQ012=="Y"), intval(Q1_SQ013=="Y"), intval(Q1_SQ014=="Y"), intval(Q1_SQ015=="Y"), intval(Q1_SQ016=="Y"), intval(Q1_SQ017=="Y"), intval(Q1_SQ018=="Y"), intval(Q1_SQ019=="Y"), intval(Q1_SQ020=="Y"), intval(Q1_SQ021=="Y"), intval(Q1_SQ022=="Y"), intval(Q1_SQ023=="Y"), intval(Q1_SQ024=="Y"), intval(Q1_SQ025=="Y"), intval(Q1_SQ026=="Y"))}

You get something like


And to preset your question in the following wave you use
Code:
{Q1_SQ001=if(substr(TOKEN:ATTRIBUTE_1,0,1)==1,"Y","")}
{Q1_SQ002=if(substr(TOKEN:ATTRIBUTE_1,1,1)==1,"Y","")}
{Q1_SQ003=if(substr(TOKEN:ATTRIBUTE_1,2,1)==1,"Y","")}
{Q1_SQ004=if(substr(TOKEN:ATTRIBUTE_1,3,1)==1,"Y","")}
{Q1_SQ005=if(substr(TOKEN:ATTRIBUTE_1,4,1)==1,"Y","")}
{Q1_SQ006=if(substr(TOKEN:ATTRIBUTE_1,5,1)==1,"Y","")}
{Q1_SQ007=if(substr(TOKEN:ATTRIBUTE_1,6,1)==1,"Y","")}
{Q1_SQ008=if(substr(TOKEN:ATTRIBUTE_1,7,1)==1,"Y","")}
{Q1_SQ009=if(substr(TOKEN:ATTRIBUTE_1,8,1)==1,"Y","")}
{Q1_SQ010=if(substr(TOKEN:ATTRIBUTE_1,9,1)==1,"Y","")}
{Q1_SQ011=if(substr(TOKEN:ATTRIBUTE_1,10,1)==1,"Y","")}
{Q1_SQ012=if(substr(TOKEN:ATTRIBUTE_1,11,1)==1,"Y","")}
{Q1_SQ013=if(substr(TOKEN:ATTRIBUTE_1,12,1)==1,"Y","")}
{Q1_SQ014=if(substr(TOKEN:ATTRIBUTE_1,13,1)==1,"Y","")}
{Q1_SQ015=if(substr(TOKEN:ATTRIBUTE_1,14,1)==1,"Y","")}
{Q1_SQ016=if(substr(TOKEN:ATTRIBUTE_1,15,1)==1,"Y","")}
{Q1_SQ017=if(substr(TOKEN:ATTRIBUTE_1,16,1)==1,"Y","")}
{Q1_SQ018=if(substr(TOKEN:ATTRIBUTE_1,17,1)==1,"Y","")}
{Q1_SQ019=if(substr(TOKEN:ATTRIBUTE_1,18,1)==1,"Y","")}
{Q1_SQ020=if(substr(TOKEN:ATTRIBUTE_1,19,1)==1,"Y","")}
{Q1_SQ021=if(substr(TOKEN:ATTRIBUTE_1,20,1)==1,"Y","")}
{Q1_SQ022=if(substr(TOKEN:ATTRIBUTE_1,21,1)==1,"Y","")}
{Q1_SQ023=if(substr(TOKEN:ATTRIBUTE_1,22,1)==1,"Y","")}
{Q1_SQ024=if(substr(TOKEN:ATTRIBUTE_1,23,1)==1,"Y","")}
{Q1_SQ025=if(substr(TOKEN:ATTRIBUTE_1,24,1)==1,"Y","")}
{Q1_SQ026=if(substr(TOKEN:ATTRIBUTE_1,25,1)==1,"Y","")}

Both equation are simple ans straightforward
Joffm

An additional remark.
Please, do not confuse us.
I think you know better and these were typos.
Do not write a QCODES as q1.SQ001, q1.SQ002, q1.SQ003,
QCODES are built with underscores q1_SQ001, q1_SQ002

and show a function like count("Y", q1.SQ001, q1.SQ002,... which is wrong syntax of "count()".
Here you seem to refer to the function countif("Y", q1_SQ001, q1_SQ002,...
By the way: Better/shorter countif("Y", that.q1)

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

More
54 minutes ago #273566 by rwinford77
Thank you, Joffm.  great suggestions.

I would do something like this with the apps I built in the past, but I couldn't think exactly how to do it with LS.  Creating a string of 1s and 0s to indicate the choices is brilliant.  Thanks.

So, I used your code below, and I can get the string map to save in the Participants/Token data fields.  And, I can get the multiple choice question to reflect the 1s and 0s from the saved data.  But, if I have the presets question then I can't get the answers to update and save in the token ATTRIBUTE.

Essentially, I have
Q1 is an Equation Question that sets the Multiple Choice answers.  Based on the ATTRIBUTE_1 variable, based on the suggested code "if(substr(TOKEN:ATTRIBUTE_1......." 
Q2 is the Multiple Choice question with 10 choices.   nothing else added Q3 is an Equation Question that forms the 1/0 array map.  This is the text string that is saved in the TOKEN:ATTRIBUTE_1 data item.  Based on your suggested code, using the join(intval....   code
So, if I have Q1 and Q2 enabled, I get the defaults set correctly.  If I have Q2 and Q3 enabled, I get the data saved correctly. 
But, if I have Q1, Q2, and Q3 all active and working, I don't get the updated data saved.  And, results data records the MC question answers that match the TOKEN:ATTRIBUTE_1 data, not what the user clicks on.  

From what it looks like to me, using the EQ question to set the defaults overrides what the user clicks on.  But, I don't understand the inner workings of LS and the EM to really understand what's happening here.

Thanks for your help.  I think I'm close, but still not quite getting it.....

Rick
yes, I was in a hurry, writing just pseudo code.  Yes, subquestions use an underscore and not a dot.  count() and countif() are close but not the same.  I was using both of them to experiment with and learn, and copied the wrong one into the question.  I promise to do better next time.  :-)

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose