6.3 Transform

Sometimes we want to take an existing variable and transform it in some way or we want to do a computation across multiple variables (e.g., reverse-score multiple items in a dataset).

I recommend you watch this video by Alexander Swan on transforming variables in jamovi.

If you want to learn more about transforming variables, the jamovi blog has a great blog post on the topic.

Recoding

Sometimes variables need to be recoded. As one example, if you have a text variable with many options, sometimes you want to recode things into a new variable with fewer options. This might mean taking something with 9 categories and collapsing them down to 3 overarching categories. The benefit of transforming through recoding is that you retain the original variable with the 9 categories but you also now have the new variable with 3 categories.

Let’s return to the Big5 dataset and recode the Neuroticism scale into low, moderate, and high neuroticism. The scale ranges from 1-5, so I’m going to say that scores between 1-2.333 are low, 2.334 to 3.666 is moderate, and 3.667 to 5 is high.

  1. Go to the Data tab in jamovi and select the variable that you want to be transformed in the dataset. In this case, ensure Neuroticism is selected.

  2. Click Transform.

  3. Rename the transformed variable to something meaningful. I typically try to write it in such a way that it retains the old variable name. For example, we can transform the Neuroticism variable into the newly transformed variable Neuroticism_cat where “cat” stands for category.

  4. Ensure the correct Source variable is being used. The source variable is the variable that is being transformed; in this case it is Neuroticism.

  5. Under using transform, select Create New Transform... from the drop-down menu. If you have already created the transformation (e.g., you are applying the same transformation to multiple variables) then you can select the transformation from the drop-down menu instead.

Here’s what it should look like prior to creating a new transformation:

  1. Rename the transformation to something meaningful. In this case we are categorizing into three categories so I might rename it Categorize into 3 categories

  2. Add a description if you desire.

  3. Specify the Variable suffix. This is what renames your transformed variable from something really annoying (e.g., Neuroticism - Categorize into 3 categories) into something succinct (e.g., Neuroticism_cat). In this case, the suffix would be _cat. This is particularly helpful if you are transforming multiple variables at once so they don’t all have really long names.

  4. Select Add recode condition for n-1 recodings you are doing. In this case, we have 3 categories so we only need to specify 2 (3-1=2).

Your view should look something like this now:

  1. We now need to specify the recode formulas. First, after the if $source statement we enter < 2.334 and then in the use box we enter 'low'. Note the usage of apostrophes (you can also use quotation marks) which tells jamovi this will be text data. If you don’t wrap things in apostrophes and quotation marks, it will assume it is numeric information (of which you should be putting numbers containing 0-9)

  2. For the second if $source statement we enter <3.667 and then specify to use 'mod'.

  3. For the else use statement at the end, we enter 'high' because we don’t need to specify anything further. If it’s not <2.334 and not <3.667 then its >=3.667 which is all that’s left in this particular data.

  4. Specify the correct Measure type. jamovi automatically guessed that the data was ordinal, but I like to specify it just to be sure. Enter ordinal for our particular data since low < mod < high.

Your data should now look like this:

Just like with computing new variables, when transforming new variables I like to peruse the newly transformed variable to make sure it did what I expected. In this case I see that participant 35 has a Neuroticism score of 1.917 which was correctly coded as low whereas participant 40 has a Neuroticism score of 3.688 which was correctly coded as high. A quick perusall makes me feel confident that I did my transformation correctly!

Reverse-scoring

Sometimes items need to be reverse-scored because the items are in the opposite direction of the rest of the items in the particular scale or subscale.

Let’s imagine we have a Happiness Scale with the following four items:

  1. I am happy.
  2. I am content.
  3. Life is overall positive.
  4. I am unhappy.

The happiness scale suggests that higher scores is higher happiness. However, the fourth item is opposite such that a person scoring higher on that item actually indicate lower happiness. Therefore, we would need to transform that item to reverse-score it such that it’s in the same direction of all the items.

The way we do this is by recoding the levels so the highest score is the lowest score and so on. For example, if it were rated on a 5-point scale then you would need to recode so a 1 = 5, 2 = 4, 3 = 3, 4 = 2, and 5 = 1.

Alternatively, instead of transforming you could use compute where the formula is the maximum value + 1 minus the value. For example, if you have a 5-point scale then you would do “6-variablename” in the computation box.

We can use the same recoding feature as before to do this. The only difference is that we are going to use the double equal sign == (R is a bit weird in that we use == to mean =). See the screenshot below to see how we are specifying that if the source variable equals the value, then use the reverse-scored value. We should add 4 recode conditions in this case and then have the final else use value for the 5th category.

Multiple transformations

Sometimes we want to do a transformation across multiple variables. Perhaps we have multiple items that need to be reverse-scored. Or maybe like in our first example above we want to use our previous Low_mod_high transformation to perform on all the subscales of the Big 5.

We can click a new variable (e.g., Openness), select Transform, rename the variable, and select the Categorize into 3 categories transformation we already used. Voila! The work we did previously can easily be used again in this analysis.

Alternatively, you can select all the variables at once that you want to transform and then specify the same transformation to be used across all four variables.