I have searched far and wide and can’t seem to get the syntax correct for a crop cut survey.
If the target parcel is divided into multiple fields and meet certain criteria from the roster (1. growing the crops of interest 2. not intercropped). We need to randomly select one of these fields and then use the name of that field to populate further questions in the section.
I have tried different methods for randomizing, but the two issues I keep running into are 1. That I am trying to randomize based on two criteria (E4 and E5_culture) and 2. getting the actual name of the chosen field to %populate%.
I would love help on syntax that can randomly select one of the eligible fields from the roster and syntax that will pull the name of that field (as a string variable or otherwise) into the next question.
I will try to give a try at your questionnaire, but let me see if I can help you by explaining how we have done this in the past in Belize.
Just like you, we have had the need to select a random element from a roster based on specific criteria. In our case, it was a selection of a random household member over the age of 18. This is how we approached it, adapting the syntax/documentation that the Survey Solutions team has previously shared (such as here). Let me illustrate how we achieved this, using the example of a randomly selected person of 18 years or over.
Identify the number of eligible elements, based on your criteria. For us, the criteria was that the age is >= 18. Save this in a variable called num_eligible.
MEMBER_ROSTER.Count(x=>x.AGE >= 18)
Select a random index based on your count at step 1. (Example, if you have 5 eligible elements, select a random number from 1 to 5). Save this in a variable called rnd_index
(long)Math.Floor(Quest.IRnd()*num_eligible.Value)
Get the rowcode (actual position in the roster) that belongs to the element you will randomly select. We again specify the criteria of eligibility when fetching roster items here. Save this in a variable rnd_rowcode.
Afterwards, you will define another roster with the questions you want to ask to the selected element. This roster will have the same source as your roster with all eligibile elements, but you can add an enabling condition to only ask to the randomly selected element based on the @rowcode. For example: @rowcode == rnd_rowcode.
The code described in steps 1-3 could be refactored and collapsed, but I wanted to break it down to illustrate the different steps.
@giansib, This works perfectly, but how do I format the syntax for Step 1 in cases of two criteria? For example if your criteria was age >= 18 and gender= 1?
@giansib, This works well for selecting one field to display- but to address an issue later in the survey where we need to select three random rows of trees within the field. (Ex. They have 7 rows of trees, rows 1,4,7 are randomly selected and then open a roster for each). It might not be possible, but is there at least a way to generate 3 numbers with the upper bound based on a numeric question? I have searched the forum but I can’t seem to get any of those situations to apply.
@sergiy, I am not pulling from a roster- I simply need to pull from a numeric question: “How many rows of trees are there?” and the enumerator should then be given 3 random numbers based on the response.
Like this case, but three numbers instead of one.