Difference between revisions of "SurveyCTO Coding Practices"

Jump to: navigation, search
Line 1: Line 1:
This article discuss solutions to common issues in the SurveyCTO programming language. For a general introduction to how to structure your approach to CAPI programming or best practices settings, see the [[Questionnaire Programming]] topic.
This article discuss solutions to common issues in the SurveyCTO programming language. For a general introduction to how to structure your approach to CAPI programming or best practices settings, see the [[Questionnaire Programming]] topic.


== Read First ==
'''Read First''' All coding examples linked to in this section are stored in Google Drive. SurveyCTO also allows you to pull this code directly to your server, using the URL of the Google Sheet (alternatively, you can copy the code to Excel).
All coding examples linked to in this section are stored in Google Drive. SurveyCTO also allows you to pull this code directly to your server, using the URL of the Google Sheet (alternatively, you can copy the code to Excel).


== Randomization in the field ==
== Randomization in the field ==
The best practice is to prepare the randomization before the field activities start, and preload the result of the randomization into the survey. See [[randomization in SurveyCTO]].
The best practice is to prepare the randomization before the field activities start, and preload the result of the randomization into the survey. See [[randomization in SurveyCTO]].


== Rosters ==
== Repeat Groups / Rosters ==
This sections lists code examples for special requirements in relation to rosters.
This sections lists code examples for special requirements in relation to rosters and repeat groups. These can be used to develop interesting functionality within forms, particularly interacting with the responses from a household, plot or crop roster. Here are some examples of this:


'''Select Member in Roster Based on Criteria'''. In this example we have a roster over children and then we want the respondent to be asked to select the youngest child if the mother is present, if she is not present, we ask the respondent to select the second youngest child if the mother of the child is present, and so fourth. See code example where [[SurveyCTO Select from Roster Age Order|children are selected from roster by age]].
* [[SurveyCTO Select from Roster Age Order|Select Member in Roster Based on Criteria]] - in this example we have a roster over children and then we want the respondent to be asked to select the youngest child if the mother is present, if she is not present, we ask the respondent to select the second youngest child if the mother of the child is present, and so fourth.  
 
*  [[SurveyCTO Conditional Filtering|Filtering on Conditions of Repeat Group Questions]] - this example utilizes responses found inside a repeat group roster as conditions upon which to filter choices for questions further down in a form.
 
* [[SurveyCTO Filtering in Repeated Questions|Filtering in Repeated Choice Questions]] - this example shows how to code a repeating question where the list of choices is reduced if an option was previously selected


== Groups ==
== Groups ==
Use a lot of groups but do not over use them. In general, groups are used to fulfill one of the purposes below:
Use a lot of groups but do not over use them. In general, groups are used to fulfill one of the purposes below:


*Apply a [[Relevance Condition to Multiple Fields|relevance condition to multiple fields]].
* [[Relevance Condition to Multiple Fields|Apply a relevance condition to multiple fields]].
*If you have [[Multiple Questions Displayed at the Same Time |multiple questions displayed at the same time]].
*Frame all the questions on a module in group. Only do this at the highest level of the survey, i.e. do not use this for sub-levels of a module.


== Choice Lists ==
* [[Multiple Questions Displayed at the Same Time |Display multiple questions on the same screen]].
Choice lists are the answer options an enumerator can choose from in a ''select one'' or ''select multiple'' question. They are listed in the choices tab in the SurveyCTO questionnaire. Open Data Kit, the programming language of SurveyCTO, has very few restrictions on how you can code your options. However, there are [[SurveyCTO Choice Lists|choice list best practices]] that matter for data quality.


'''Dynamically Populated Choice Lists - Basic'''. It is possible to program [[SurveyCTO Dynamically Populated Choice Lists|dynamically populated]] choice lists using answers given by the respondents in a previous question.
* Frame all the questions on a module in group. Only do this at the highest level of the survey, i.e. do not use this for sub-levels of a module.


'''Dynamically Populated Choice Lists - From repeated select_one'''. A specific example of dynamically populated choice list is when you populate a select_multiple question with answers from a select_one asked in a repeat group. For example, say that you list crops grown in a repeat group where each repeat is a crop, and later you want to be able to ask "''which crop did you grow the most?''" and only the crops already selected in the repeat group should display. This can be done and is described in the [[SurveyCTO Dynamically Populated Choice Lists From Select One|dynamic choice lists from select_one]].
== Choice Lists ==
Choice lists are the answer options an enumerator can choose from in a ''select_one'' or ''select_multiple'' question. They are listed in the choices tab in the SurveyCTO questionnaire. Open Data Kit, the programming language of SurveyCTO, has very few restrictions on how you can code your options. However, there are [[SurveyCTO Choice Lists|choice list best practices]] that matter for data quality.


== Repeat Groups ==
* [[SurveyCTO Dynamically Populated Choice Lists|Dynamically Populated Choice Lists - Basic]] - it is possible to program dynamically populated choice lists using answers given by the respondents in a previous question.
Repeat groups can be used to develop interesting functionality within forms. Here are some examples of this:


* [[SurveyCTO Conditional Filtering|Filtering on Conditions of Repeat Group Questions]] - this example utilizes responses found inside a repeat group roster as conditions upon which to filter choices for questions further down in a form.
* [[SurveyCTO Dynamically Populated Choice Lists From Select One|Dynamically Populated Choice Lists - from repeated select_one]] - a specific example of dynamically populated choice list is when you populate a ''select_multiple'' question with answers from a ''select_one'' asked in a repeat group. For example, say that you list crops grown in a repeat group where each repeat is a crop, and later you want to be able to ask "''which crop did you grow the most?''" and only the crops already selected in the repeat group should display.  


* [[SurveyCTO Filtering in Repeated Questions|Filtering in Repeated Choice Questions]] - this example shows how to code a repeating question where the list of choices is reduced if an option was previously selected


== Categories to add to this page: ==
=== Categories to add to this page: ===
* Repeat groups
* Household rosters
* Household rosters
** General examples
** General examples

Revision as of 08:25, 22 January 2018

This article discuss solutions to common issues in the SurveyCTO programming language. For a general introduction to how to structure your approach to CAPI programming or best practices settings, see the Questionnaire Programming topic.

Read First All coding examples linked to in this section are stored in Google Drive. SurveyCTO also allows you to pull this code directly to your server, using the URL of the Google Sheet (alternatively, you can copy the code to Excel).

Randomization in the field

The best practice is to prepare the randomization before the field activities start, and preload the result of the randomization into the survey. See randomization in SurveyCTO.

Repeat Groups / Rosters

This sections lists code examples for special requirements in relation to rosters and repeat groups. These can be used to develop interesting functionality within forms, particularly interacting with the responses from a household, plot or crop roster. Here are some examples of this:

  • Select Member in Roster Based on Criteria - in this example we have a roster over children and then we want the respondent to be asked to select the youngest child if the mother is present, if she is not present, we ask the respondent to select the second youngest child if the mother of the child is present, and so fourth.

Groups

Use a lot of groups but do not over use them. In general, groups are used to fulfill one of the purposes below:

  • Frame all the questions on a module in group. Only do this at the highest level of the survey, i.e. do not use this for sub-levels of a module.

Choice Lists

Choice lists are the answer options an enumerator can choose from in a select_one or select_multiple question. They are listed in the choices tab in the SurveyCTO questionnaire. Open Data Kit, the programming language of SurveyCTO, has very few restrictions on how you can code your options. However, there are choice list best practices that matter for data quality.

  • Dynamically Populated Choice Lists - from repeated select_one - a specific example of dynamically populated choice list is when you populate a select_multiple question with answers from a select_one asked in a repeat group. For example, say that you list crops grown in a repeat group where each repeat is a crop, and later you want to be able to ask "which crop did you grow the most?" and only the crops already selected in the repeat group should display.


Categories to add to this page:

  • Household rosters
    • General examples
    • Updating roasters from previous rounds on tablet during interview
  • ID and identification
    • Assigning IDs in the field - both when the sample is know before launch of survey and when respondents are sampled in the field


Additional Resources

Please add here related articles, including a brief description and link.