New nominal variable from two dichotomous 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
Psych
Posts: 5
Joined: Tue Jul 06, 2021 8:35 am

New nominal variable from two dichotomous variables?

Post by Psych »

Hello all,

I recently came across Jamovi and am very happy with it. However, as part of my research, I ran into a problem that I could not solve myself through trial and error. So I wanted to ask if it is possible to compute a new nominal variable from two dichotomous variables. In the specific case, the two variables are: Anorexia nervosa (1=yes, 2=no) and atypical anorexia nervosa (1=yes, 2=no). I would now like to compute a new variable with (1= Anorexia nervosa, 2= Atypical anorexia nervosa, 3= No anorexia nervosa).
To my limited understanding, this should be logically possible since all AN, atyp AN and no AN are mutually exclusive.

I tried using the filter code, but unfortunately I did not succeed.

IF(AN==1, atypAN==2) gives me all cases with AN.
IF(AtypAN==1, AN==2) gives me all cases with atypical AN.

But somehow I can't combine these two codes together.

Is it possible to compute a new nominal variable from two dichotomous variables?

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

Re: New nominal variable from two dichotomous variables?

Post by jonathon »

you can nest if statements like this:

IF(AN == 'yes', IF(AtypeAN == 'no', 'Anorexia nervosa', 'Atypical anorexia nervosa'), 'No anorexia nervosa')

cheers

jonathon
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: New nominal variable from two dichotomous variables?

Post by MAgojam »

Hi, @Psych.
Do you think the screenshot that I am attaching could be useful to you?
screenshot.png
screenshot.png (48.24 KiB) Viewed 6501 times
Cheers,
Maurizio
Psych
Posts: 5
Joined: Tue Jul 06, 2021 8:35 am

Re: New nominal variable from two dichotomous variables?

Post by Psych »

Hi Jonathon and Maurizio,

Thanks for your answers, you have helped me a lot! I was not even aware of this possibility. Really great to have such an active community!

The first code didn't quite work, so I tried a bit myself and it worked with that

IF('Anorexia nervosa' == 2, IF('Atypical Anorexia' == 2, 'No AN', 'Atypical AN'), 'Anorexia nervosa')

I am very happy that it worked. I don't quite understand the logic behind it yet, unfortunately.

I'll try it:

AN ==2, Atypical AN == 2 if both are true, it is 'No Anorexia Nervosa', IF Atypical AN is not 2 (then it is 1) it is Atypical Anorexia Nervosa, otherwise it's Anorexia Nervosa.

Is there anywhere to learn more about variable generation codes? It's a stupid question, but are these the same codes I would use in R?
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: New nominal variable from two dichotomous variables?

Post by jonathon »

the little fx button beside the formula will give you a list of the different functions available.

when we nest IF()'s we take the result of the inner IF(), i.e.

IF('Atypical Anorexia' == 2, 'No AN', 'Atypical AN')

and the result of that gets substituted into the outer IF(), where the X is:

IF('Anorexia nervosa' == 2, X, 'Anorexia nervosa')

in this way we can take the results of different calculations and build up complex relationships.

the computed variables are designed to be familiar if you're coming from excel ... and no, they won't work in R.

cheers

jonathon
User avatar
MAgojam
Posts: 421
Joined: Thu Jun 08, 2017 2:33 pm
Location: Parma (Italy)

Re: New nominal variable from two dichotomous variables?

Post by MAgojam »

Psych wrote:Is there anywhere to learn more about variable generation codes?
If you've never done, pop in the archives of Jamovi Blog.
https://blog.jamovi.org/archives.html

You will find helpful tips including
Computed variables in jamovi, Transforming and recoding variables in jamovi,
and so on.

Cheers,
Maurizio
Psych
Posts: 5
Joined: Tue Jul 06, 2021 8:35 am

Re: New nominal variable from two dichotomous variables?

Post by Psych »

Thanks a lot again :-)
Post Reply