Calculated variables by automation script
Automation scripts now provide the ability to create derived variables. Whether it’s a variable with many responses or many variables, they can be done in a quick and efficient way in one go.
So far there are three derived variable types which can be created automatically. The first screenshot shows how the basic scripts for these are set-up:
Click on the image to download the script. You can use this new functionality in Analyse 5.6.1.0 onward with the example QES file downloadable here.
Sometimes there might be errors in your script e.g. you’re creating a variable with shortcut which already exists in the questionnaire or you’re referring to a variable that doesn’t exist in the script you’re setting for the variable.
The second screenshot below shows the script set-up with the Debug.Trace() to output error messages that can help you figure out what’s wrong:
The error messages are fully customisable so you can put in more detail like the name of the variable being created (see line 45 in first screenshot). The DebugTrace.txt file is created in the .dat folder belonging to the QES or QEW.
In the next script we show how to create a variable with many responses. The responses are taken from an existing variable ^8. Top of mind^ and used to create another variable with an additional condition for each response:
^8. Top of mind^.Value Has " + i + " AND ^Department^.Value > 0"
In the final script we see how to create many variables in one go:
If you’re using a QES or QEW file you might notice that the creation of several variables in one go stalls before fully completing. In this case it’s recommended to create a fast metadata (FMD) version of your QES or QEW. Removing MS Access from the equation means we can create many variables lightning fast all in one go.
E.g. for QES files . . .
- Let’s call the original file: qes.
- With the inverted .qes file open in Analyse > Edit > Generate fast metadata.
- Now in the directory of the data file you will see a .qex named: filename-meta.qex.
- Copy/paste the folder dat and rename it to be filename-meta.dat.
- Now open filename-meta.qex in Analyse.
E.g. for QEW files . . .
- Let’s call the original file: qew.
- With the inverted .qew file open in Analyse > Edit > Generate fast metadata.
- Now in the directory of the data file you will see a .qewx named: qew-meta.qewx.
- This will create the qew-meta.dat folder for you, no need to copy/paste/rename this time.
- Now open qew-meta.qewx in Analyse.
Check that your Analyse option for fast metadata is set to ‘Yes’ . . .
More info on FMD here.
Updates:
1./
In case you need to set some additional options like the level or sub-population, we added some new keywords around the middle of July 2022 which can be used for this purpose:
var.Level = "Items"
var.SetSubPopulation("Males")
2./
Since then we have also added the ability to create three new variable types which can be accessed using var.Type = 4, 5 or 6