Dynamically referencing x number of previous questions

Hi there,

I have a module (CREDI) which is more than 100 questions long. Each question is single select yes/no/dk. The rules are that no further questions should be asked once respondent answers no/dk to five in a row.

I know how to make this work manually with a different enabling condition for each question - but out of interest / developing coding skills, was just wondering if anyone could think of an efficient way to do this maybe using a macro or a looping variable or something?


In socio-economic surveys we skip the questions when they are not applicable to the respondent. For example, we don’t ask the question of employment for 2-year-old children. In this case the skipping is a conscious action of deciding that employment question is irrelevant for the young children, simply because they cannot be employed.

Your question hints at a totally different context. It indicates that there are no such logical dependency between the questions. Moreover, the ‘stopping’ criterion depends not only on which questions are asked before which, but also which questions follow which in sequence. (Simply by introducing an unrelated question in between the two existing will result in a different behavior of the questionnaire.)

Lachlan has specified that this is a CREDI module. I don’t know what specific CREDI he meant, but in all likelihood it can be Caregiver Reported Early Childhood Development Instruments. Note that I would not be able to call it a ‘survey’. It is indeed an ‘instrument’. Instrument for a particular purpose. Because of the described stopping behavior the questions, which appear later in the schedule have less chances of being asked, and hence the picture of the population derived from these questions is no longer representative. Still this is a valid approach if the instrument is used for a particular purpose, such as determining if a child has developmental problems. The trade-off is that this instrument allows to shorten the interview by asking only the necessary minimal number of questions to determine that the child has developmental problems, while a survey would go over all the questions, then let the analyst to derive different measures (simulating the different stopping behaviors on the full dataset).

In terms of efficiency,

  • Since any question 6…N is at-risk of being switched off, there must be a condition for each. Perhaps the CountValue() function is useful in writing such conditions.
  • Since the stopping may occur at any question, all conditions are necessarily different.
  • Survey Solutions allows referencing the questions only by variable name, not by position (there is no reference to previous or next question). Hence every condition must mention the 5 previous questions specifically by their variable names.

In terms of efficiency compared with other software, I think they are facing the exact same issue, as evidenced by the questionnaire fragment for ODK:


Hope this helps.

Hi Sergiy,

Thanks for taking the time for the detailed response. Indeed it is the Caregiver Reported Early Childhood Development Instrument, which is administered as part of a larger survey being conducted. Just thought I would check in and see if you had any ideas to do it in a clever way before I write more than 100 enabling conditions :slight_smile: but that’s fine - understand the limitations. ODK i can see would have the same limitations- in CSPro it would probably be do-able as you can use arrays and loops there.




Suppose you could use arrays and loops. How would that help for the task at hand?

I’m not sure exactly maybe something like write a function which holds all of the variable names in the CREDI as an array and then after each question pass in a counter and have the function return the five previous variable names… will give it a go one day when I have some spare time!

If you define $m=new[]{q1,q2,q3,q4,q5,q6,q7,q8,q9,10} then $m[6] will give you the value of q6. In the end, you don’t need the name of the previous question, you need the value of the previous question. But I don’t see how writing $m[1]+$m[2]+$m[3]+$m[4]+$m[5] is somehow superior to writing q1+q2+q3+q4+q5.

The problem with this approach is that Survey Solutions will not let you compile such a questionnaire. This is because qi is mentioned in the array, which is used to generate the enabling condition for qi. In other words, this creates a circular reference, which is not allowed in Survey Solutions. So you can’t construct an array of ALL questions/answers and then enable some of THEM. You may, though, construct an array of previous answers, but that will be N different arrays. Hence no savings in typing.

It is possible, however, to look, let’s say, from section B into section A and see if that pattern is observed among the questions there, but this is not your case.

I see, interesting to know an array can be held in a Macro

Lucky for me the questionnaire designer has decided to instead use the short form of CREDI - just ~20 questions instead of > 100 so not so laborious with the enabling conditions now. Thanks!