help assert
-------------------------------------------------------------------------------
Title
[D] assert -- Verify truth of claim
Syntax
assert exp [if] [in] [, rc0 null]
by is allowed; see [D] by.
Description
assert verifies that exp is true. If it is true, the command produces no
output. If it is not true, assert informs you that the "assertion is
false" and issues a return code of 9; see [U] 8 Error messages and return
codes.
Options
rc0 forces a return code of 0, even if the assertion is false.
null forces a return code of 8 on null assertions.
Examples
---------------------------------------------------------------------------
Setup
. sysuse bplong
. describe
Verify that sex variable is coded as 0 or 1
. assert sex == 0 | sex == 1
Setup
. replace sex = 3 in 1
Verify that sex variable is coded as 0 or 1
. assert sex == 0 | sex == 1
List observation for which assertion is false
. list if sex != 0 & sex != 1
Verify that bp is in [100,200]
. assert bp >= 100 & bp <= 200
---------------------------------------------------------------------------
Setup
. webuse autotech, clear
. merge 1:1 make using http://www.stata-press.com/data/r11/autocost
Confirm _merge is always 3
. assert _merge == 3
---------------------------------------------------------------------------
Also see
Manual: [D] assert
Help: [P] capture, [P] confirm