Suppose three invented scores are 40, 70 and missing, written as a dot in Stata. You want an indicator that is 1 above 50, 0 otherwise, and missing when the score is unknown. The tempting command generate high_wrong = score > 50 gives the missing score a 1: numeric missing values compare greater than every nonmissing number in Stata.
Try this constructed example only in an empty practice session after saving any existing work. Enter the lines in a do-file and run them together:
input score
40
70
.
end
generate high_wrong = score > 50
generate high = score > 50 if score < .
list score high_wrong high
assert high == . if score == .
Read the three columns as score, incorrect indicator and corrected indicator. Their expected rows are 40 0 0, 70 1 1 and . 1 .. The condition if score < . restricts the calculation to nonmissing scores, leaving the new indicator missing for the unknown score. Replacing that unknown with 0 would answer a different question: it would classify it as not above 50.
The final assert checks that the indicator stays missing where the score is missing. A successful assertion normally produces no output; a failed assertion reports an error. This is a check you can keep beside the transformation in your do-file.
For practice, change the threshold to 60 and predict all three rows before rerunning in an empty practice session. Then try 80: the known scores should both have indicator 0, while the unknown remains missing. Being able to explain that distinction is more useful than memorising a command.