Verification script to check data
http://analysishelp.askia.com/run_verification_script
Description
Companies within the Market Research industry use many different tools to ensure the integrity of the data that has been gathered. Whether considering random data generation, test data, the first few respondents of the live data or even the final data, it is good practice to check the quality of the data.
In order to assist with this requirement we have created a brand new functionality in AskiaTools that allows you to run verification scripts against your data. You can now create a script that will be run on all interviews and whenever a condition is not met, a message is logged.
In order to access the verification script functionality, open your QES file in AskiaTools, then go to Tools->Run a verification script . . .
The toolbar buttons
Once the new verification script window is open you have the options to create a new script, open an existing one or save the current one.
The file extension for saved script files is .txt so you can edit your scripts with whatever text editor you prefer. However, we recommend you edit your scripts in the interface provided as it will highlight any obvious problems/errors (such as invalid variable names or invalid syntax).
The following options are available:
-
Compile the script - this checks if the written script corresponds to the database and the syntax is correct (according to AskiaScript and AskiaScript 2.0). For more information about AskiaScript, please refer to the Design Assistant).
- Generate script for questions not in current script - this will automatically generate a default script. The script generated will adhere to the syntax you have declared in "Tools-> Options-> Generation of verification script". Please refer to the "Generation of verification script" section below for more information.
- Run/continue script - this will run the script for all interviews. If is selected then the script will be interrupted from running further after the first Assert message is shown (first incorrect respondent). To continue you just need to press the run/continue option again. If is selected, the script will take into consideration only the questions present in the current script and will ignore the rest of the database so it runs faster. You can also interrupt the run by pressing on this again.
- Reset run - this resets the errors found in the current run (but does not reset the script).
- Restart current interview - this restarts the step by step run for the current interview.
- Run script step by step - using this option, you can step through each part of the script and view the results in the results section. Please refer to the "Results" section below for more information. Once you have stepped through all parts of the script for a respondent, the script will start from the beginning again for the next respondent. By default, the script will run step-by-step on the first respondent in your file. However, you can navigate to another respondent/interview, using the interview navigation buttons . . .
- Interview navigation buttons - you can position yourself forward or backwards through each single interview or go straight to the last or first interview using these navigation buttons. You can also double-click on the interview position to enter the exact interview you want to go to.
- Completes only - if selected, the script will only run on data for completed respondents.
- Select - by selecting this option, you can write AskiaScript syntax to have the data verified only for a certain selection of respondents (??Gender?? has {1} for example).
-
Speed test - if you have this selected, the Duration and Percentage fields will be populated in the "Results" section when you run your script. Please refer to the "Results" section below for more information. If your script takes a long time to run, you can use the Duration and Percentage information to identify the parts of the script that take a long time to run.
Generation of verification script
Using the new options available from "Tools-> Options->Generation of verification script", you can specify the default syntax to be generated for each of the question types.
You can refer to the current question shortcut using either %q or %s. If the question shortcut contains spaces (or other special characters), the use of %q will ensure the shortcut will be replaced with ^shortcut^. Therefore, the syntax around %q will still be valid so this is the recommended method. Please refer to the "New keywords" section below for more information about new syntax in use and examples. All other syntax used is according to AskiaScript and AskiaScript 2.0. For more information about AskiaScript, please refer to the Design Assistant.
Results
The results section is split into four views. By default, the first view displays, for each part of your script . . .
- Type: indicates the type of keyword question, syntax, variable, function and method.
- Value: indicates the type of the keyword within that category.
- Result: indicates the actual value of the token after it was run.
If you have selected the option, the first view will also display Duration and Percentage information . . .
The second view in the results section displays a list of interviews that have failed your scripted checks (asserts), along with the details.
The third view in the results section displays a summary. For each line in the script, this view displays the line number, the number of interviews checked, the number of interviews that failed a check (assert) and the associated message for that check (assert) when relevant.
The fourth view is a console window. It lets you type some code and immediately see the result.
E.g. q1.Value + { 1 to 3}.
New keywords
As previously mentioned we have %q and %s which can be used in the generation of the verification script.
%q - will reference the current question.
%s - will reference the current shortcut.
Assert - Object used to validate the integrity of the interviews data.
Assert.Check - Evaluate the expression as a Boolean value. If the value of the expression is true, nothing happens. Otherwise the assert returns a false value and the message is displayed. The function should look like this: Assert.Check(expression,message) where the expression is a variant and the message is a string.
Example:
If Country has {1} Then
Assert.Check(Language has {1},"When country is 'UK', 'English' should be selected, but was "+ ^Language^.Answers[1].Caption)
EndIf
Assert.ToString() - returns the string representation of the object/variable.
GoTo - the GoTo statement allows you to skip sections of your script.
Example:
Goto Mark1
If Country has {1} Then
Assert.Check(Language has {1},"When country is 'UK', 'English' should be selected, but was "+ ^Language^.Answers[1].Caption)
EndIf
Mark1:
In this example, the section in orange is skipped because the Goto Mark1 script dictates that everything is skipped until it finds Mark1:
Please note that GoTo can only go forward. It is not possible to use GoTo to go back/up in the script.
Interview - This object can be used to get information about the current interview. You can use it in the following ways:
- Interview.Broker - this returns the Broker ID.
- Interview.BrokerPanelID - this returns the broker panel id as received in askia web (when available).
- Interview.GUID - this returns the global unique identifier for each respondent.
- Interview.IPAddress - this returns the IP address of the interview (if available).
- Interview.Latitude - this returns the latitude for the respondent location. (If not available it will return a 0).
- Interview.Longitude - the same as above except it returns Longitude.
- Interview.PanelID - this returns the Askia Panel ID when available.
- Interview.Progress - this will return the percentage value of progress through the questionnaire.
- Interview.Seed - this returns a pseudo-unique number for each interview used to generate random numbers in the survey.
Question.AllIterations - the AllIterations keyword will return a value that relates to the number of times a looped question exists in the questionnaire.
For example, if Q1 is a question inside a loop with 3 iterations then Q1.AllIterations.Count will return a value of 3.
If Q2 is a question inside a loop within another loop, with 3 and 2 iterations, then Q2.AllIterations.Count will return a value of 6.
Question.HasNoData - This Boolean (true/ false) keyword indicates if there is some data in the question or not.
Question.HasValidData - This indicates if the answer of the current question is valid for open, numeric and closed questions (depending on its type). It checks if there is a value and if that value is compatible with DK settings (for all), min/max number of answers and exclusivity (for multiple variables), size (for open question) and range (for numeric and date variables).
More examples
- Q1 is a multi question inside a loop and you want to check it has valid data on all iterations:
Dim i
For i = 1 to Q1.AllIterations.Count
Assert.Check (Q1.AllIterations[i].HasValidData , "Q1 doesn't have valid data")
Next i
- Q3 is asked only if Q2=1. In this case there are two checks you would need to do: Error if Q2 is 1 and no data in Q3 OR you have data in Q3 but Q2 does not equal 1:
if Q2 has {1} Then
Assert.Check(Q3.HasValidData,"Skip executed when it shouldn't")
else
Assert.Check(Q3.HasNoData,"Skip not executed")
EndIf
Fortunately Askia can compare conditions returns so instead of the above syntax with condition and reversed condition you can just use:
Assert.Check((Q2 has {1})=Q3.HasValidData,"Skip error here")
Considering the message is raised when the condition is false it means both our conditions should be simultaneously true or simultaneously false.
- Q1 is an open question and q2 is a closed (single) question, into which we code the answers type in at q1. We need to check now that q2 was coded correctly. Assuming you have each possible answer at q1 isolated in a file we create a txt file (see "Test.txt" attached). Within "Test.txt", we separate each category/answer to be coded using the "|" character and each possible variation of that category/answer using ",". Note - you can easily create your file with the array of strings within Excel or Word. The way in which we refer to this file and run the check between q1 and q2 is as follows . . .
Dim strOpen
strOpen = ReadTextFile("Local path to your Test.txt file")Dim arrRows = strOpen.Split( "|")
Dim i
For i=1 to arrRows.Count
Dim arrCodes = arrRows[i]
Dim arrSpells = arrCodes.Split(",")
Dim j
For j=1 to arrSpells.Count
If ^q1^.Value.ToLowerCase() = arrSpells[j].ToLowerCase() Then
Assert.Check( ^q2^.Value Has i,"Data is wrong coded for "+ ^q1^.Value)
endif
Next j
Next i
Please also refer to attached "autocode_verification.qes" for example data on which you can test this method.An example of the above script can be found in the attached file "Verif_Autocode_NEW.txt".
Another example of how to verify the coding for q2 can also be found in the attached file "Verif_Autocode.txt". In this version the possible categories/answers and variations are specified as part of the script. The verification scripts for each category/answer are also split out. This is perhaps easier to understand but less efficient.
As previously stated and as you can see from the various examples provided, you can use the same syntax that you use in AskiaScript to group and check your data. Therefore, AskiaTools provides full flexibility and freedom when you want to check your data.