Transformed variable - if source contains

Discuss the jamovi platform, possible improvements, etc.
Post Reply
coce
Posts: 3
Joined: Wed Nov 27, 2019 11:36 am

Transformed variable - if source contains

Post by coce »

Hi,
I'd like to recode some variables so if a source contains a certain text I'd like to use a number for it.

Example:

Source
id1: Dog, Cat, Mouse
id2: Dog
id3: Dog, Cat
id4: Dog, Mouse

New variable 1:
If source contains Dog use 1
Then with this all the ids would use 1.

Right now I can only see the Equal to operator but that'll only work for id2.

I assume with a function it's doable, but I'm not so familiar with functions. Any ideas?

Thanks!
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Transformed variable - if source contains

Post by jonathon »

hmm,

we've not encountered this sort of use case before. perhaps we need to consider it.

you'll need to use computed variables for this:

IF(CONTAINS('Dog', variableName), 1, IF(CONTAINS('Cat', variableName), 2, ... ))

jonathon
coce
Posts: 3
Joined: Wed Nov 27, 2019 11:36 am

Re: Transformed variable - if source contains

Post by coce »

Thanks jonathon!

Mhmm, maybe I'm doing something wrong, but it doesn't seem to work. i use Version 1.0.8.0 on a MacOS Catalina.

https://i.imgur.com/Mq3Do56.png
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Transformed variable - if source contains

Post by jonathon »

oh yeah, you'll need a more recent version.

jonathon
coce
Posts: 3
Joined: Wed Nov 27, 2019 11:36 am

Re: Transformed variable - if source contains

Post by coce »

Pefect, thank you so much!
SoZ
Posts: 2
Joined: Thu Oct 06, 2022 9:41 pm

Re: Transformed variable - if source contains

Post by SoZ »

jonathon wrote:hmm,

we've not encountered this sort of use case before. perhaps we need to consider it.

you'll need to use computed variables for this:

IF(CONTAINS('Dog', variableName), 1, IF(CONTAINS('Cat', variableName), 2, ... ))

jonathon
Hi Jonathon, how many if can I concatenate in the same expression?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Transformed variable - if source contains

Post by jonathon »

i don't think there's a limit

jonathon
Wake
Posts: 43
Joined: Tue Jun 26, 2018 8:31 am

Re: Transformed variable - if source contains

Post by Wake »

jonathon wrote: Thu Nov 28, 2019 1:12 am we've not encountered this sort of use case before. perhaps we need to consider it.
I've just installed version 2.3.21 and come across the same issue. I'm trying to transform job titles into whether they are technical or not. I'd just switched to using COMPUTE but I thought I'd Google before going any further.
Post Reply