Your outcome measure has a pre-registered threshold. Scores below it indicate non-response, scores at or above it indicate response. But reviewers also want to flag exceptional responders — scores more than 25% above the threshold. How do you handle three categories in SPSS?
I used is_eligible from Day 6 for a two-category check. Three categories in SPSS means a nested IF in the syntax, which I always get wrong on the first try.
Python's if/elif/else is that nested IF, except it reads left to right and Python checks the conditions in order. The first condition that is true wins; the rest are skipped. Three tiers, three branches:
score = 5.2
threshold = 4.0
if score < threshold:
category = "below threshold"
elif score == threshold:
category = "at threshold"
else:
category = "above threshold"When does the else branch fire? What if score is 4.0 exactly — does it ever reach else?
No — elif score == threshold catches exactly 4.0. The else is the catch-all: it only fires when every condition above it was False. Think of it as a waterfall — the water stops at the first dam it can't pass.
So for the exceptional responders — scores above the threshold — I just let them fall through to else. That's clean.
The reviewer who asked for three-tier categorisation is now getting it on every wave, automatically:
def categorize_outcome(score: float, threshold: float) -> str:
if score < threshold:
result = "below threshold"
elif score == threshold:
result = "at threshold"
else:
result = "above threshold"
print(f"Score {score:.2f} vs threshold {threshold:.2f}: {result}")
return resultI can run this on 300 respondents in a loop. That's Week 2 thinking already.
One trap with == on floats: 4.000000001 == 4.0 is False due to floating-point representation. For fuzzy threshold comparisons in statistical analysis, use abs(score - threshold) < 1e-9 or round both values to consistent precision before comparing.
Python evaluates conditions top to bottom and stops at the first True.
if score < threshold: # checked first
...
elif score == threshold: # only checked if first was False
...
else: # fires if nothing above was True
...== on floats is fragile — 4.000000001 == 4.0 is False. For exact boundary testing in statistical pipelines, round both values to consistent decimal precision before comparing.
Always put the most specific condition first. If else came before elif, the elif would never run.
Your outcome measure has a pre-registered threshold. Scores below it indicate non-response, scores at or above it indicate response. But reviewers also want to flag exceptional responders — scores more than 25% above the threshold. How do you handle three categories in SPSS?
I used is_eligible from Day 6 for a two-category check. Three categories in SPSS means a nested IF in the syntax, which I always get wrong on the first try.
Python's if/elif/else is that nested IF, except it reads left to right and Python checks the conditions in order. The first condition that is true wins; the rest are skipped. Three tiers, three branches:
score = 5.2
threshold = 4.0
if score < threshold:
category = "below threshold"
elif score == threshold:
category = "at threshold"
else:
category = "above threshold"When does the else branch fire? What if score is 4.0 exactly — does it ever reach else?
No — elif score == threshold catches exactly 4.0. The else is the catch-all: it only fires when every condition above it was False. Think of it as a waterfall — the water stops at the first dam it can't pass.
So for the exceptional responders — scores above the threshold — I just let them fall through to else. That's clean.
The reviewer who asked for three-tier categorisation is now getting it on every wave, automatically:
def categorize_outcome(score: float, threshold: float) -> str:
if score < threshold:
result = "below threshold"
elif score == threshold:
result = "at threshold"
else:
result = "above threshold"
print(f"Score {score:.2f} vs threshold {threshold:.2f}: {result}")
return resultI can run this on 300 respondents in a loop. That's Week 2 thinking already.
One trap with == on floats: 4.000000001 == 4.0 is False due to floating-point representation. For fuzzy threshold comparisons in statistical analysis, use abs(score - threshold) < 1e-9 or round both values to consistent precision before comparing.
Python evaluates conditions top to bottom and stops at the first True.
if score < threshold: # checked first
...
elif score == threshold: # only checked if first was False
...
else: # fires if nothing above was True
...== on floats is fragile — 4.000000001 == 4.0 is False. For exact boundary testing in statistical pipelines, round both values to consistent decimal precision before comparing.
Always put the most specific condition first. If else came before elif, the elif would never run.
Mei is analysing outcome scores from a randomised controlled trial. The pre-registered threshold is a fixed value — scores below it indicate non-response, scores exactly at it indicate threshold response, scores above it indicate response. Write `categorize_outcome(score, threshold)` that returns `"below threshold"`, `"at threshold"`, or `"above threshold"`.
Tap each step for scaffolded hints.
No blank-editor panic.