assert
Stops with an error unless something you believe is true of every row.
What we have
- any condition, checked on every row
- it says how many rows failed, not just that one did
Coming later
Nothing known to be missing.
How you write it
assert condition
Square brackets mean optional. A vertical bar means choose one.
What it does
assert age >= 0 says: I am certain no age is negative. If one is, Virata stops and tells you, instead of carrying on and producing a plausible-looking wrong answer.
It is the cheapest tool here and the most underused. Put your assumptions in writing at the top of a do-file and the file will refuse to run the day the data changes underneath it.
Try it
Every example below was run after sysuse vira.sample02, clear.
. assert age >= 0
The same thing in pandas and in R
R
# no R form for `assert` yet -- see docs/r-equivalents.md