The "if" Suffix
The "if" command suffix is used to restrict on which data a command is run. If you add an if
statement, the command will only be run on the data for which the "if" statement is true. A command can only have one "if" statement but multiple parameters can be specified using the &
For example, say I wanted to summarize gpa
for a data set. Then I decide I am particularly interested in girls, coded in this data set numerically as "1". So the command becomes summarize gpa if gender==1"
Now say I want to only look at girls in 11th grade, I can simply add the &
so now the full command would be summarize if gender==1 & grade==11
To see more functions, including those that might be useful in crafting if statements, type help functions
Almost every command in Stata can be modified using the if
suffix but you can always type help [command] to check.
Back to Syntax