https://dimewiki.worldbank.org/index.php?title=SurveyCTO_Repeat_Group_Using_Previous_Choices&feed=atom&action=historySurveyCTO Repeat Group Using Previous Choices - Revision history2024-03-28T21:51:04ZRevision history for this page on the wikiMediaWiki 1.37.2https://dimewiki.worldbank.org/index.php?title=SurveyCTO_Repeat_Group_Using_Previous_Choices&diff=8798&oldid=prevZkevala: Redirected page to Repeat Groups and Rosters in SurveyCTO#Repeat Group Using Previous Choices2023-07-20T19:02:57Z<p>Redirected page to <a href="/Repeat_Groups_and_Rosters_in_SurveyCTO#Repeat_Group_Using_Previous_Choices" title="Repeat Groups and Rosters in SurveyCTO" data-bs-title="Repeat_Groups_and_Rosters_in_SurveyCTO">Repeat Groups and Rosters in SurveyCTO#Repeat Group Using Previous Choices</a></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 19:02, 20 July 2023</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">#REDIRECT[[Repeat Groups and Rosters in SurveyCTO#Repeat Group Using Previous Choices]]</ins></div></td></tr>
<tr><td colspan="2" class="diff-side-deleted"></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Best Practice == <onlyinclude></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>== Best Practice == <onlyinclude></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities performed. Here we use an example based on a ''select_multiple'' question of 14 potential crops, where we want to ask follow up questions about those crops selected. </onlyinclude></div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities performed. Here we use an example based on a ''select_multiple'' question of 14 potential crops, where we want to ask follow up questions about those crops selected. </onlyinclude></div></td></tr>
</table>Zkevalahttps://dimewiki.worldbank.org/index.php?title=SurveyCTO_Repeat_Group_Using_Previous_Choices&diff=4559&oldid=prevAdmin at 11:29, 5 April 20182018-04-05T11:29:49Z<p></p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 11:29, 5 April 2018</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l1">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>== Best Practice == </div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>== Best Practice == <ins style="font-weight: bold; text-decoration: none;"><onlyinclude></ins></div></td></tr>
<tr><td class="diff-marker" data-marker="−"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities performed. Here we use an example based on a ''select_multiple'' question of 14 potential crops, where we want to ask follow up questions about those crops selected. </div></td><td class="diff-marker" data-marker="+"></td><td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities performed. Here we use an example based on a ''select_multiple'' question of 14 potential crops, where we want to ask follow up questions about those crops selected. <ins style="font-weight: bold; text-decoration: none;"></onlyinclude></ins></div></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br/></td></tr>
<tr><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Both approaches require the use of the ''index()'' command, which yields the number of the repeat. Note that if ''NO CROPS'' is selected in the select_multiple question, the repeat groups are skipped. Also, it isn't possible to select ''NO CROPS'' and any other crops from the choices. </div></td><td class="diff-marker"></td><td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>Both approaches require the use of the ''index()'' command, which yields the number of the repeat. Note that if ''NO CROPS'' is selected in the select_multiple question, the repeat groups are skipped. Also, it isn't possible to select ''NO CROPS'' and any other crops from the choices. </div></td></tr>
<!-- diff cache key dimeprod_new:diff::1.12:old-4153:rev-4559 -->
</table>Adminhttps://dimewiki.worldbank.org/index.php?title=SurveyCTO_Repeat_Group_Using_Previous_Choices&diff=4153&oldid=prevSteven: Created page with "== Best Practice == There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities perfor..."2018-01-29T14:04:45Z<p>Created page with "== Best Practice == There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities perfor..."</p>
<p><b>New page</b></p><div>== Best Practice == <br />
There are many cases when you want to repeat a set of questions over previously selected responses, such as a set of crops cultivated or activities performed. Here we use an example based on a ''select_multiple'' question of 14 potential crops, where we want to ask follow up questions about those crops selected. <br />
<br />
Both approaches require the use of the ''index()'' command, which yields the number of the repeat. Note that if ''NO CROPS'' is selected in the select_multiple question, the repeat groups are skipped. Also, it isn't possible to select ''NO CROPS'' and any other crops from the choices. <br />
<br />
== Code Example ==<br />
[https://drive.google.com/open?id=1aCnBqwl12RJXZLMIGMtWAC0drNNbeIM8OxNpjH8GqvA Here is a code example] showing the 2 main ways to achieve this. The comments in the labels of the calculate fields describe the steps taken in the SruveyCTO form.<br />
<br />
=== 1) Repeating for all options and adding a constraint inside the group ===<br />
Here we code the repeat group count to cycle through all the possible options of the 'crop' choices - 14 in total - and add a constraint to the questions contained within the repeat group. The set up only needs a variable (''${crop_name1}'') to pull the crop name from the ''select_multiple'' options. <br />
<br />
* + easier to code<br />
* + output links the crop ID to the repeat count<br />
* - can create large number of fields/variables when there are a lot of choices, particularly for nested repeats (e.g. crops within plots within seasons) which can slow down form processing on the tablet<br />
<br />
=== 2) Only repeating for selected options ===<br />
This method utilizes how the ''select_multiple'' fields are stored (e.g. '''1 4 5'''). It selects the corresponding number (i.e. the crop ID) in the list in order through the <code>selected-at(${crops2}, index()-1)</code> calculate expression. Note that the '-1' is needed as the first field in the list is 0 (not 1), as in other programming languages like Python. <br />
<br />
Once we know the crop ID, the crop name is pulled in the same manner as the other example. As the number of repeats is dynamic, we need to tell the repeat group to only repeat the number of times for which there are selected crops, which is: <code>count-selected(${crops2}) </code>. The setup of this method requires calculate fields for the crop ID and the crop name.<br />
<br />
The main advantage in this approach is that it avoids the potential mass of missing data created when there are many choices to select from.<br />
* + more elegant, less missing data<br />
* + runs faster on large forms<br />
* - can be tricker to code<br />
* - output crop IDs do not line up with repeat count, need to account for this in data cleaning<br />
<br />
== Back to Parent ==<br />
This article is part of the topic [[SurveyCTO Coding Practices]]<br />
<br />
[[Category: SurveyCTO Coding Practices ]]</div>Steven