Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen

Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

0 votes

I would like to have 100 US respondents and 100 UK respondents and I would like to weed out anyone who does not live in the US or the UK. To do this, I created a question CO04 on the “Res” page with 1 = US, 2 = UK and 3 = other. Is this the correct code I should use? I am especially unsure of the usage of "$Res". (Note: the links are just place holders)

// Residence of respondents
$Res = value('CO04');
// Screenout
if ($Res > 2) {
// Limit of respondents from each country
$limits = array(
  1 => 100,
  2 => 100,
// This code should communicate the number of completed questionnaires from each country of residence 
$nQnr = statistic('count', 'CO04', $Res);
$nMax = $limits[$Res];
// This code should tell the system to redirect only those respondents from the US and UK only once the limit is reached 
if ($nQnr >= $nMax) {
in SoSci Survey (English) by s088994 (110 points)
edited by SoSci Survey

1 Answer

0 votes

This look correct, yes. Please give it some tests in the debug mode and maybe add debug($nQnr); and debug($nMax); at the end to observer what the PHP code does (in the debug information) and see that everything works. In testing mode all records are counted by statistic(), while in the real interview, only MODE=interview records are counted. To testing is no problem for your stats.

$Res is simply a variable to store value('CO04') temporarily. You could as well write value('CO04') instead of $Res every time, but that would be longer (and less efficient).

Just a warning: Your counter will as well count those cases that were screened out after a quota full. Because redirect() will set FINISHED=1. This is no problem for your quota check, as long as you don't need cross-variable quotas and you don't have to raise the quota after it was reached. If you anticipate you'll need either of that, than copy CO04 to an internval variable at the end of the questionnaire, and count that internal variable instead CO04 in statistic().

by SoSci Survey (267k points)