In DataDynamic the concept of recoding a variable is strictly related to the fact of creating a new calculated variable, based on the usage of simple formulas assigning criteria to transform values of existing variables into a new one. For this reason, recoding a variable could be done in 2 ways, depending on the situation:

1) When recoding variables using the 'Recode variable' button in the Edit toolbar, you can use the Custom formula field to define the recode categories.

The valid formats for recoding categorical variables are:

 (old values 1), new value 1, (old values 2), new value 2 etc.

 (old values )=1, new value 1, (old values) =2, etc.

An example of customized formula is: "(1,2),1,(3,4,),2", which recode a categorical variable with four categories into a variable with two categories (example below).


2) When Recoding numerical variables into categorical ones is done using the same 'Recode variable' button, you can use the same formula format as for categorical variables (described above). 

However, since this implies defining the new categories one value at a time, this can be quite time-consuming in the case of numerical variables with a wide range of values. 

For example: when recoding age in years into a variable with categories such as 18-29, 30-39 etc., you don't want to have to name all the years individually (in the example above it would be):

"(18,19,20,21,22,23,24,25,26,27,28,29),1",(30,31,32,33,34,35,36,37,38,39),2" etc.

There are shortcuts, using operators such as > (greater than) etc.

To use this type and other more complex formulas, instead of Recoding button you better use the 'Add calculated variable' command and its structure to the formula field.

When using the command 'Add a new (calculated) variable' in the formula field, you can define a new variable using Visual Basic scripting language. 

A full description of Visual Basic scripting is beyond the scope of this tutorial, but the most commonly used formula types are:

+ the '"Label" function'

+ the '"In" function'

+ the '"If" function'.


For a detailed description of this functions and some useful examples, please consult DataDynamic user Manual.

You can follow the steps described above by checking the video on our Youtube channel: