Adding labels to levels of transformed variables

General help and assistance with jamovi. Bug reports can be made at our issues page: https://github.com/jamovi/jamovi/issues . (If you're unsure feel free to discuss it here)
Post Reply
starcrossing
Posts: 7
Joined: Sat Apr 13, 2019 1:34 am

Adding labels to levels of transformed variables

Post 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
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Adding labels to levels of transformed variables

Post 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
starcrossing
Posts: 7
Joined: Sat Apr 13, 2019 1:34 am

Re: Adding labels to levels of transformed variables

Post 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?
starcrossing
Posts: 7
Joined: Sat Apr 13, 2019 1:34 am

Re: Adding labels to levels of transformed variables

Post 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 ^^;
renzo.carriero
Posts: 6
Joined: Mon Nov 11, 2019 6:30 pm

Re: Adding labels to levels of transformed variables

Post 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?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Adding labels to levels of transformed variables

Post 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
renzo.carriero
Posts: 6
Joined: Mon Nov 11, 2019 6:30 pm

Re: Adding labels to levels of transformed variables

Post by renzo.carriero »

Yes, this is feasible, though not efficient
decuser
Posts: 18
Joined: Tue Apr 07, 2020 2:59 am

Re: Adding labels to levels of transformed variables

Post 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.
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Adding labels to levels of transformed variables

Post by jonathon »

oh yup. it is naughty. but it will work :P

jonathon
renzo.carriero
Posts: 6
Joined: Mon Nov 11, 2019 6:30 pm

Re: Adding labels to levels of transformed variables

Post by renzo.carriero »

Thanks for your hint, decuser!
Post Reply