Welcome to the LimeSurvey Community Forum

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

setting data for hidden variables

  • naz1mb20
  • naz1mb20's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 weeks 6 days ago #266693 by naz1mb20
setting data for hidden variables was created by naz1mb20
Please help us help you and fill where relevant:
LimeSurvey version: 6.6.2
Own server or LimeSurvey Cloud: Cloud
Survey theme/template: Default/ inherited
==================
I am new to LimeSurvey and have mostly used ConfirmIt and especially Decipher in my career. I need some help with what I think is a very basic concept (hidden or dummy variables and setting their data based on other questions).

Here is my example for a start
Q1
Open Numeric
What is your age?

dQ1
Hidden single choice question (do not show to the respondent, this will get prefilled)
0-17
18-24
25-34
35-44
45-54
55-64
65+

So in Decipher I would loop over the answers in dQ1, match that age range with the value provided in 'Q1' and set that datapoint if it matches. I can't seem to find any examples of this on the KB or forums? I've seen something about ExpressionScript which seems very long winded imo (unless im misunderstanding it's power)? How would I set data for a grid type question like that? If somebody can point me in the write direction with this age example that would be ever so useful. I would much rather not have type up seperate 'IF' statements that go through each possible value as that would get very time consuming.

Please Log in to join the conversation.

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 weeks 6 days ago - 2 weeks 6 days ago #266708 by holch
Replied by holch on topic setting data for hidden variables
I don't know how Conformit does it, but I expect also some kind of scripting.

I've seen something about ExpressionScript which seems very long winded imo (unless im misunderstanding it's power)?


ExpressionManager/Script is the way to go. Might look intimitating at the beginning, but it isn't all that bad. Your example is actually relatively simple.

Let's assume you have the following scenario:

Q1: What is your age? (OE)
Q2: What is your age? (Single response - hidden via GUI)
[1] 0-17
[2] 18-64
[3] 65+
Q3: Equation type question.

Then you will "loop". You create some if clauses in Limesurvey. I simplified it to 3 answer options (below 18, 18-64 and 65+), for demonstration. Don't want to loop "a thousand" times here.

This is just an example to start from. I have not tested it, also because you did not provide a LSS example of your structure and I am too lazy now to create one. So this might not work straight out of the box, but you will understand how it works.

I highly recommend to have a look at  manual.limesurvey.org/Expression_Manager . You don't need to read it all, but it will give you an idea of what you can do with it. It works very similar to many other script languages, a little bit like formulas in excel.

The if clause works like this: if([condition to be met], [if condition is met, what should LS do], [else, if condition is not met, what should limesurvey do?]). 

In your case you need to put addition if clauses in the "else" section, because you have more than 2 age brackets. Something like this: 

Code:
{if(Q1<18, Q2==1, if(Q1<65, Q2==2, Q2==3))}


So basically you check if the answer in Q1 is smaller than 18, if so you asign the answer "1" to Q2. If not, you continue and check if the number is smaller than 65, if so you can apply code 2, because if it would have been smaller than 18 it would already have been asigned a 1 and the if loop would have finished. So the person must have given a number between 18 and 64. And then "else" the number must be 65 above, because it is not smaller than 18 and not smaller than 65. So it must be bigger than 65.

But actually, not sure why you even need the hidden single punch question. You could just write the answer codes into the equation. OK, to work with it you would need to know what each code means, but I assume you would remember that. :-)

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 2 weeks 6 days ago by holch.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose