How to create an if statement to ensure that the numerical value of a variable will be bigger | XM Community
Solved

How to create an if statement to ensure that the numerical value of a variable will be bigger


Hello everyone ,

What I am trying to do is create two variables that will be randomized numbers that will be rounded off. These two numbers are to be piped into two answer choices on a survey (one answer choice will contain one randomized and rounded number). I want to ensure that one number ("rand" is always greater then "rand2"). I have tried using the "Then Branch if" feature several times to re-play the randomization if "rand" is less than "rand2........ until "rand" is bigger than "rand2", however I still can't get it to reflect that on the survey preview (that in almost half of the occasions the number that rand2 is greater than rand number)

Does anyone know how to do this? Thank you in advance for your time and attention

Screenshot_2020-04-23 Edit Survey Qualtrics Survey Software.pngScreenshot_2020-04-23 Edit Survey Qualtrics Survey Software(1).png

icon

Best answer by Jose 26 April 2020, 20:55

View original

11 replies

Userlevel 7
Badge +22

Why are we not generating random numbers in different range like for rand has greater number range and for rand2 small number range, wherein the min of rand rand range is max of rand2

{"embed-error": true}Thank you for your reply. However, I cannot change the ranges of this number as it would lead to selected bias on my survey, because the range I choose will be a value judgment and not entirely random. I also need both numbers to be in the entire range, I only want the condition that rand is greater than rand2

That is why I need both numbers to have the same range

Userlevel 7
Badge +22

Then create two temp embedded data (temp1, temp2) assign them with random number of same range. Use branch logic to get greater number and assign that to rand and other to rand2. Like if temp1 is greater then assign temp1 value to rand and temp2 value to rand2

Perfect, thank you for your answer,

Are the two temp embedded data created via the survey flow?

Sorry I am new to Qualtrics

Userlevel 7
Badge +22

Yes temp embedded data are created in the survey using same range

This is how I have it set up. However now, what's happening is that when I call either rand or rand two as piped text in the answer choices (${e://Field/rand} and ${e://Field/rand2} respectively, they no longer show the value. Could you tell me how to improve this? Thank you for your time
Screenshot_2020-04-25 Edit Survey Qualtrics Survey Software.png

It appears as if my branch logic is not correct. When i do if tempr1> tempr2 am I comparing the numbers are stored in these variables?

Userlevel 7
Badge +22

The branch logic and assignment of embedded data should look something similar to below:
image.png

Thank you! Got it to work!!!

Could not beleive the solution was simple. I guess qualtrics does not store values of the variable?

Userlevel 7
Badge +22

It does stores the value, the way to assign it is different i.e. we need to do pipe text.

Thank you for the help Ron!

Leave a Reply