Trouble with 'if' statements and scoring

I want the following questions to return a single score, with the following
3 potential scores: 1, 0, or -999 (-999 if the respondent doesn't know the
answer)

The 2 questions are:

  1. How much did your household earn last month? (If respondent doesn't
    know, write -999) and 2) How much did your household spend last month? (If
    respondent doesn't know, write -999)

If for either question, the respondent doesn't know, I want the scored
value to be -999. However, if question 1 - question 2 > 0, I want the
scored value to be 1, and if it is not greater than 0, the scored value to
be 0.

How do I do this? Any help is very much appreciated!! Thank you!!

Hi Jeremy, Thanks for getting back to me!

I'm writing the if statements in hidden values, but where I'm struggling is
with the number of response options. It looks like in CommCare the if
statement follows the format: IF(evaluative statement, result if
statement is true
,result if statement is false)-- This allows for 2
possible returned values (one if the statement is true and one if the
statement is false)- but I'm hoping to create an if statement that allows
for 3 returned values (Either -999, 1, or 0). If the respondent writes -999
for either question 1 or question 2, return -999, otherwise subtract
question 1 - question 2 and if the answer is greater than 0, return 1,
otherwise return 0.

Any input is much appreciated. Thanks!

Emily

··· On Monday, June 27, 2016 at 2:47:57 PM UTC-7, Emily Epsten wrote: > > I want the following questions to return a single score, with the > following 3 potential scores: 1, 0, or -999 (-999 if the respondent doesn't > know the answer) > > The 2 questions are: > 1) How much did your household earn last month? (If respondent doesn't > know, write -999) and 2) How much did your household spend last month? (If > respondent doesn't know, write -999) > > If for either question, the respondent doesn't know, I want the scored > value to be -999. However, if question 1 - question 2 > 0, I want the > scored value to be 1, and if it is not greater than 0, the scored value to > be 0. > > How do I do this? Any help is very much appreciated!! Thank you!! >

That worked! Thank you!

··· On Monday, June 27, 2016 at 2:47:57 PM UTC-7, Emily Epsten wrote: > > I want the following questions to return a single score, with the > following 3 potential scores: 1, 0, or -999 (-999 if the respondent doesn't > know the answer) > > The 2 questions are: > 1) How much did your household earn last month? (If respondent doesn't > know, write -999) and 2) How much did your household spend last month? (If > respondent doesn't know, write -999) > > If for either question, the respondent doesn't know, I want the scored > value to be -999. However, if question 1 - question 2 > 0, I want the > scored value to be 1, and if it is not greater than 0, the scored value to > be 0. > > How do I do this? Any help is very much appreciated!! Thank you!! >

Hi Emily,

One approach could be to use an if statement in a hidden value to calculate
the value you want to store for each of these. So you would have question 1
(question_1_input) and then a hidden value (question_1_score) which
calculates the stored value based upon the input. I don't quite follow how
you want the scoring to work, but you can find examples here:
https://confluence.dimagi.com/display/commcarepublic/If+Statements+in+Calculations

Hope this helps!

Jeremy

··· On Mon, Jun 27, 2016 at 5:47 PM, Emily Epsten wrote:

I want the following questions to return a single score, with the
following 3 potential scores: 1, 0, or -999 (-999 if the respondent doesn't
know the answer)

The 2 questions are:

  1. How much did your household earn last month? (If respondent doesn't
    know, write -999) and 2) How much did your household spend last month? (If
    respondent doesn't know, write -999)

If for either question, the respondent doesn't know, I want the scored
value to be -999. However, if question 1 - question 2 > 0, I want the
scored value to be 1, and if it is not greater than 0, the scored value to
be 0.

How do I do this? Any help is very much appreciated!! Thank you!!

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.

Hi Emily,

I see - you can nest if statements inside each other for possible options,
like:

if( statement 1, result if 1 is true, else: (statement 2, results if 2 is
true, result if statements are not true))

So you would have something like:

if(question1 = -999 or question2 = -999, -999, if(question1 - question2 >
0, 1, 0))

Jeremy

··· On Tue, Jun 28, 2016 at 11:29 AM, Emily Epsten wrote:

Hi Jeremy, Thanks for getting back to me!

I'm writing the if statements in hidden values, but where I'm struggling
is with the number of response options. It looks like in CommCare the if
statement follows the format: IF(evaluative statement, result if
statement is true
,result if statement is false)-- This allows for 2
possible returned values (one if the statement is true and one if the
statement is false)- but I'm hoping to create an if statement that allows
for 3 returned values (Either -999, 1, or 0). If the respondent writes -999
for either question 1 or question 2, return -999, otherwise subtract
question 1 - question 2 and if the answer is greater than 0, return 1,
otherwise return 0.

Any input is much appreciated. Thanks!

Emily

On Monday, June 27, 2016 at 2:47:57 PM UTC-7, Emily Epsten wrote:

I want the following questions to return a single score, with the
following 3 potential scores: 1, 0, or -999 (-999 if the respondent doesn't
know the answer)

The 2 questions are:

  1. How much did your household earn last month? (If respondent doesn't
    know, write -999) and 2) How much did your household spend last month? (If
    respondent doesn't know, write -999)

If for either question, the respondent doesn't know, I want the scored
value to be -999. However, if question 1 - question 2 > 0, I want the
scored value to be 1, and if it is not greater than 0, the scored value to
be 0.

How do I do this? Any help is very much appreciated!! Thank you!!

--
You received this message because you are subscribed to the Google Groups
"commcare-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to commcare-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Jeremy Wacksman
Dimagi http://www.dimagi.com, Inc.