It seems like I should be able to do this, but I can't seem to figure it out. Suppose I want to compute a new variable based on 2 existing variables, something like this:
If A=1 and B>9 then C=2
If A=1 and (B<10 and B>5) then C=1
Else C=0
Can someone tell me how to do this in Jamovi? Thanks!
Computing variables with If-Then
Re: Computing variables with If-Then
i can't see anything wrong with those rules. if they're not working the way you expect, attach a screenshot.
cheers
jonathon
cheers
jonathon
Re: Computing variables with If-Then
Hi, @DSK.
Do you think the suggestion of this screenshot is what you are looking for? Cheers,
Maurizio
Do you think the suggestion of this screenshot is what you are looking for? Cheers,
Maurizio
Re: Computing variables with If-Then
Hello,
I want to compute a new variable with two calculations like: IF var_1 = "high" then 7- var_2
I hope you can help.
Thanks!
I want to compute a new variable with two calculations like: IF var_1 = "high" then 7- var_2
I hope you can help.
Thanks!
Re: Computing variables with If-Then
Hi @flatliner,
you haven't indicated what the argument will be if the test with IF(test, TRUE, FALSE) results in FALSE.
Anyway I look at the screenshot, where with test TRUE it returns 7-var_2, while with FALSE it returns var_2. Cheers,
Maurizio
you haven't indicated what the argument will be if the test with IF(test, TRUE, FALSE) results in FALSE.
Anyway I look at the screenshot, where with test TRUE it returns 7-var_2, while with FALSE it returns var_2. Cheers,
Maurizio
Re: Computing variables with If-Then
Hi Maurizio,
Thanks a lot, that is exactly what I was looking for and it works!!!
Thanks a lot, that is exactly what I was looking for and it works!!!
-
- Posts: 3
- Joined: Thu Mar 09, 2023 3:31 am
Re: Computing variables with If-Then
Hi All -- Found this thread and tried the syntax structure but it is telling me that my formula is mis-specified? What am I missing here? This is a super simple one -- compute a new variable, and if this other variable = 1, then new variable =1. If other variable is anything else then new variable = 0.
I thought I had the syntax right -- IF (cancertreat=1,1,0)?
Link to image below...
https://snipboard.io/J3p8LG.jpg
I thought I had the syntax right -- IF (cancertreat=1,1,0)?
Link to image below...
https://snipboard.io/J3p8LG.jpg
Re: Computing variables with If-Then
Hey @erosenzweig,
if you take a look at the screenshots in the posts above, you will see that you need == (you only used one) for the formula to be correct and get the result you are looking for.
Cheers,
Maurizio
if you take a look at the screenshots in the posts above, you will see that you need == (you only used one) for the formula to be correct and get the result you are looking for.
Cheers,
Maurizio
-
- Posts: 3
- Joined: Thu Mar 09, 2023 3:31 am
Re: Computing variables with If-Then
Aaaah thank you! I stared at that for so long and still didn't see it. Appreciated.
Re: Computing variables with If-Then
Hi Jonathon!
I have data on one variable (name: L_CL_CR_R with 4 categories) collected in YEAR = 1 and 3. I want to compute the variable based on previous two with the function IF and. This is my formula:
IF(YEAR==1 and L_CL_CR_R==1, 1, IF(YEAR==3 and L_CL_CR_R==1, 2, IF(YEAR==1 and L_CL_CR_R==2, 3, IF(YEAR==3 and L_CL_CR_R==2, 4, IF(YEAR==1 and L_CL_CR_R==3, 5, IF(YEAR==3 and L_CL_CR_R==3, 6, IF(YEAR==1 aJnd L_CL_CR_R==4, 7, IF(YEAR==3 and L_CL_CR_R==4, 8, 0))
Jamovi sais it is mis-specified. Where is the mistake?
Thank you!
I have data on one variable (name: L_CL_CR_R with 4 categories) collected in YEAR = 1 and 3. I want to compute the variable based on previous two with the function IF and. This is my formula:
IF(YEAR==1 and L_CL_CR_R==1, 1, IF(YEAR==3 and L_CL_CR_R==1, 2, IF(YEAR==1 and L_CL_CR_R==2, 3, IF(YEAR==3 and L_CL_CR_R==2, 4, IF(YEAR==1 and L_CL_CR_R==3, 5, IF(YEAR==3 and L_CL_CR_R==3, 6, IF(YEAR==1 aJnd L_CL_CR_R==4, 7, IF(YEAR==3 and L_CL_CR_R==4, 8, 0))
Jamovi sais it is mis-specified. Where is the mistake?
Thank you!