Page 1 of 1

Adding labels to levels of transformed variables

Posted: Mon Apr 15, 2019 9:12 am
by starcrossing
Hi,
I was wondering if it's possible to add labels to levels of transformed variables?
I realize that this can be done by specifying the "name" of the new level in the transform (the --> use '...' part), but I was wondering if there's a way to assign labels after? (also because not in all case you would change all the levels you have in the original variable)

For example, one variable I have is 'type of employment', and I have values from 1 to 7, each corresponding to a different one. I labeled them such as "full time", "part time", etc. But since some of these have a very small number of data, I want to merge categories 6 and 7 (Other) into one. So I can write (I think)
if $source == 5 use 6
else use $source

What I get in the transformed variable are 6 categories, but there is no way to label them... or is there? This is not such a big deal but it would help in understanding tables and graphs more easily.

Thanks,
Simona

Re: Adding labels to levels of transformed variables

Posted: Mon Apr 15, 2019 10:20 am
by jonathon
hi,

you can just use labels in use '...' part. i.e.

if $source == 5 use "part time"

the problem comes where you need to have both the value and the label, i.e. if you're reverse scoring an item, 7 = strongly agree, for some analyses you'll want the numeric value (means), and for others you'll want the label. not sure if that will be a problem here.

cheers

jonathon

Re: Adding labels to levels of transformed variables

Posted: Tue Apr 16, 2019 2:05 pm
by starcrossing
Thank you for your reply.
My issue was more along the lines of whether there is a way of creating a transform such as:

Original variable categories:
1 (label "bus")
2 (label "car")
3 (label "bicycle")
4 (label "on foot")
5 (label "plane")

I want to merge 3 and 4 into a new category (which might be labelled "Other"), because those categories have very low observed counts.

So my transform should be able to a) merge the variable and b) give it a new label
in addition, I was wondering if it was possible to state something like "else, just keep the original value AND its original label"
(because otherwise I will have to define a series of ifs that go like --> if $source == 1 use "bus", if $source == 2 use "car" etc.
Might not be a big deal but it gets a little troblesome when you have a bunch of categories.

Hope I could explain what I'm trying to do?

Re: Adding labels to levels of transformed variables

Posted: Tue Apr 16, 2019 2:15 pm
by starcrossing
Um, I'm replying to my own question with a slightly different example because I just realized something that partly answers my question:

ORiginal variable
1 (label "bus")
2 (label "car")
3 (label "bicycle")
4 (label "on foot")
5 (label "other")

Transform (version 1)
if $source == 4 use 5
else use $source

This gives me a new variable with levels defined as 1, 2, 3, 5

Transform (version 2)
if $source == 4 use 'Other'
else use $source

This gives me a new variable with levels defined as bus, car, bicycle, other

Which is what I wanted to get. I didn't realize that it worked this way.. I thought you had to specify labels one by one. I feel kind of silly now but I guess this might help people having the same question in the future ^^;

Re: Adding labels to levels of transformed variables

Posted: Mon Nov 11, 2019 6:40 pm
by renzo.carriero
Hi everybody,
I found this discussion looking for support about value labels. As a new user of Jamovi, I immediately realized what Jonathon wrote above in response to the first question. Actually, it might become a problem when you transform (i.e. recode) a variable and the new labels do not have corresponding numeric values. For example, if I reverse code a likert type variable using labels, I cannot subsequently use the recoded variable to compute mean scores. Is there (or will be there) a way to fix it?

Re: Adding labels to levels of transformed variables

Posted: Tue Nov 12, 2019 12:06 am
by jonathon
not at the moment. probably the best you can do for the time-being, is to recode the column twice. once for numeric values, and once for labels.

jonathon

Re: Adding labels to levels of transformed variables

Posted: Tue Nov 12, 2019 7:31 am
by renzo.carriero
Yes, this is feasible, though not efficient

Re: Adding labels to levels of transformed variables

Posted: Mon Apr 13, 2020 3:08 pm
by decuser
Came across this in 2020 and thought it worth clarifying for posterity. I'm not sure this is exactly what Jonathan was suggesting, so ymmv with this approach...

To 'transform' a variable with levels, do the transform to numeric levels, then create a new variable and copy/paste the values from the transform into the new variable and delete the transform. The new variable is just a standard variable and will function normally allowing you to assign descriptions to the numeric values, aka label the levels.

Re: Adding labels to levels of transformed variables

Posted: Wed Apr 15, 2020 11:19 am
by jonathon
oh yup. it is naughty. but it will work :P

jonathon

Re: Adding labels to levels of transformed variables

Posted: Tue May 05, 2020 9:48 am
by renzo.carriero
Thanks for your hint, decuser!