Page 1 of 2

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

Posted: Mon Nov 28, 2022 10:45 am
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

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

Posted: Tue Nov 29, 2022 10:40 pm
by jonathon
take a look here:

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

jonathon

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

Posted: Thu Dec 01, 2022 4:05 pm
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!

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

Posted: Thu Dec 01, 2022 4:49 pm
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!

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

Posted: Thu Dec 01, 2022 9:59 pm
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

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

Posted: Fri Dec 02, 2022 2:40 pm
by Lauri
Thank you soooooo much!!!

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

Posted: Sun Dec 04, 2022 11:47 am
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

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

Posted: Mon Dec 05, 2022 11:13 pm
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 2995 times

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

Posted: Fri Dec 09, 2022 9:18 am
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!

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

Posted: Fri Dec 09, 2022 9:20 am
by Lauri
So for person 3 and 5 a "0" should also appear at C