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

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

  • April 23, 2020
  • 11 replies
  • 413 views

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

Best answer by Jose

Thank you! Got it to work!!!

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

11 replies

rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • April 23, 2020

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


  • Author
  • 7 replies
  • April 23, 2020

{"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


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • April 23, 2020

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


  • Author
  • 7 replies
  • April 24, 2020

Perfect, thank you for your answer,

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

Sorry I am new to Qualtrics


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • April 25, 2020

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


  • Author
  • 7 replies
  • April 25, 2020

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


  • Author
  • 7 replies
  • April 26, 2020

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?


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • April 26, 2020

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


  • Author
  • 7 replies
  • Answer
  • April 26, 2020

Thank you! Got it to work!!!

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


rondev
Level 6 ●●●●●●
Forum|alt.badge.img+22
  • Level 6 ●●●●●●
  • 1450 replies
  • April 26, 2020

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


  • Author
  • 7 replies
  • April 26, 2020

Thank you for the help Ron!