Compute Variable with if...than....

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)
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Compute Variable with if...than....

Post by Lauri »

Hi,
I am looking for a solution and would be very pleased to receive an answer....thank you!

I would like to calculate a variable and NOT set a filter:
if variable1>5 and variable2<5 use 1 and if variable1>5 and variable2>5 use 2

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

Re: Compute Variable with if...than....

Post by jonathon »

take a look here:

https://blog.jamovi.org/2018/10/23/transforming-variables.html

jonathon
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

Thank you very much for your answer!

But how does it works when there are two variables (so two §sources)?
Syntax in SPSS:

IF (subject of study = 1 and sex = 2) group = 1
If (subject of study = 3 and sex = 1) group = 2


Thank you!
Last edited by Lauri on Thu Dec 01, 2022 4:54 pm, edited 1 time in total.
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

Thank you very much for your answer!

But how does it works when there are two variables (so two §sources)?
Syntax in SPSS:

IF (subject of study = 1 and sex = 2) group = 1
If (subject of study = 3 and sex = 1) group = 2


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

Re: Compute Variable with if...than....

Post by jonathon »

with the transformed variables you can go:

if $source == 1 and sex == 2 use 1
if $source == 3 and sex == 1 use 2

or you could use computed variable, and go:

IF(`subject of study` == 1 and sex == 2, 1, IF(`subject of study` == 3 and sex == 1, 2))

cheers
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

Thank you soooooo much!!!
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

one more time :-)
IF(IJP _036 == 1 or IJP_039 == 1, 1, 0) - > this one works out, but if one of the two cells is empty, I get no value, even if the condition for 1 or 0 is met
so I tried this one:
IF(IJP _036 == 1 or IJP_039 == 1, 1, 0, ignore_missing_1) ---> reply: error

How is it possible that values are output if one of the two conditions is met (IJP_36 == 1 or IJP_39 == 1), even if there is a missing value for one of the conditions?
I look forward to ideas and thank you very much
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Compute Variable with if...than....

Post by jonathon »

hi,

could you attach the .omv file. this seems to be working for me:
Screenshot 2022-12-06 at 10.11.28.png
Screenshot 2022-12-06 at 10.11.28.png (120.39 KiB) Viewed 2527 times
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

It is probably because I have not defined the missing values. My real file is a large data set and it would be very cumbersome to define all the missing values. In fact, if there are no values in A or B, it should also result in a "0" in C. Is there a trick to fill missing values = NA with "0"?

Thank you very much!
Attachments
Question.omv
(2.07 KiB) Downloaded 77 times
Lauri
Posts: 12
Joined: Mon Nov 28, 2022 10:32 am

Re: Compute Variable with if...than....

Post by Lauri »

So for person 3 and 5 a "0" should also appear at C
Post Reply