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 220.127.116.11 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.
In case you need to set some additional options like the level of sub-population we must employ a workaround using FMD since the automation scripts don’t have these options yet.
Set the first variable’s options:
- Go to the folder: filename-meta.dat orqew-meta.dat.
- Take a copy of the file xml and put it somewhere safe as a back-up.
- Open xml in a text editor such as notepad++.
- Find: </Guid>.
- Replace with: </Guid><Level>Items</Level><SubPopulation>All respondents (US)</SubPopulation>.
- Save the changes to the xml and reopen filename-meta.qex in Analyse.
- This will update all variables with the same sub-pop and level setting but it might still be quicker in the text editor if you have several to apply across many variables.