A common problem for tracking jobs is that the variable descriptions and code labels as delivered by the source system can be unsuitable for analysis.  A typical example for a Gender question with two codes:

Q1 Are you…?
c1 Gender of Respondent: Female
c2 Gender of Respondent: Male

What we want for analysis and for client delivery is just

Q1 Gender
c1 Female
c2 Male

If you use the Dimensions system and import MDD/DDF files to Ruby, then you can select Analysis labels at import time. Of course, this presumes that someone has entered all the analysis labelling beforehand.

For other field systems which often deliver too much untidy text: if you change the description and code labels through DP | Variables then they will be overwritten at the next wave import. If you make safe copies of edited codeframes (*.met files) and replace post-update then the case count is not updated:

 

 

 

 

 

 

 

 

 

 

 

You could update the case counts by global search/replace, but that sort of thing is not good practice.

A better solution to this problem is to script the descriptions and labels.  But nobody wants to write possibly thousands of lines, so we use a script which generates script: \Ruby\Jobs\GenerateSetDescsAndLabels.vbs. This script can be executed against any job, so it is stored in the \Jobs subdirectory. The script generates a SetVarDesc statement and a set of SetCodeLabel statements for each variable, using the current text for both. You then edit the text as required once, and then execute against an updated job to revert the description and label text to what you want.

There are some user parameter settings at the top of the script:

''' User parameters
const varfolder   = ""        ''' vartree folder to process, "" for all
const maxcodes  = 50          ''' don't write code labels if variable has more than maxcodes codes (=0 for vardescs only)
const ignoreafter = " ("      ''' keep only vardesc text to the left of ignoreafter
const syntax      = "VB.Net"  ''' comment/uncomment as required
'const syntax      = "VBScript"

const varfolder  – For jobs with thousands of variables, it may be better to work by vartree folders to avoid administrative variables like Respondent_ID, Interview_StartTime, large blocks of uncoded variables, etc. You can restrict to a vartree folder by assigning to varfolder, eg varfolder = “Demographics” will process only variables in the Demographics folder. 

const maxcodes  – Use this to restrict generating SetCodeLabel statements to only variables with maxcodes or fewer codes.

const ignoreafter  – If you have a common character string to delimit repeated or unwanted tail text, then assign it here. If a variable description is like “Brand Awareness (Please select all brands you have ever heard of or know about)” then with ignoreafter=” (” only “Brand Awareness” is retained.  Another common delimiter is ” – “.

const syntax  – Specify the syntax to match the script environment where the generated statements will be executed.

Running with the above user settings in the Ruby Demo job generates a block of statements for each variable. EXITEMbrx is:

SetVarDesc("EXITEMbrx", "Execution Items BrandX")
SetCodeLabel("EXITEMbrx", 1, "Item detail 1")
SetCodeLabel("EXITEMbrx", 2, "Item detail 2")
SetCodeLabel("EXITEMbrx", 3, "Item detail 3")
SetCodeLabel("EXITEMbrx", 4, "Item detail 4")
SetCodeLabel("EXITEMbrx", 5, "Item detail 5")
SetCodeLabel("EXITEMbrx", 6, "Item detail 6")

But what do I do with this? I hear you ask…

In your script which does variable processing (constructions etc, typically called Variables.vbs or Variables.vb), make a new subroutine something like this:

Sub ResetVarDescsCodeLabels()

End Sub

Then copy/paste the generated output from GenerateSetDescsAndLabels.vbs as required, to give

Sub ResetVarDescCodeLabels()
   SetVarDesc("EXITEMbrx", "Execution Items BrandX")
   SetCodeLabel("EXITEMbrx", 1, "Item detail 1")
   SetCodeLabel("EXITEMbrx", 2, "Item detail 2")
   SetCodeLabel("EXITEMbrx", 3, "Item detail 3")
   SetCodeLabel("EXITEMbrx", 4, "Item detail 4")
   SetCodeLabel("EXITEMbrx", 5, "Item detail 5")
   SetCodeLabel("EXITEMbrx", 6, "Item detail 6")
End Sub

Now edit as required:

Sub ResetVarDescCodeLabels()
   SetVarDesc("EXITEMbrx", "Execution Items for Brand X")
   SetCodeLabel("EXITEMbrx", 1, "Girl chasing ball")
   SetCodeLabel("EXITEMbrx", 2, "Happy dogs")
   SetCodeLabel("EXITEMbrx", 3, "Day at the beach")
   SetCodeLabel("EXITEMbrx", 4, "Martians have landed")
   SetCodeLabel("EXITEMbrx", 5, "Square face")
   SetCodeLabel("EXITEMbrx", 6, "Zebras and Giraffes")
End Sub

And so on for all other variables where you want to lock in the analysis text.

At the next update, the audit file will report on all the differences between the descriptions and labels from the source system and your overrides.  It is wise to check carefully, because it is always possible for the field supplier to change a code’s meaning and forget to tell you.

Categories:

Tags:

Comments are closed