Selecting observations for analysis

By default Stata commands operate on all observations of the current dataset; the if and in keywords on a command can be used to limit the analysis on a selection of observations (filter observations for analysis).

if Keyword (condition)

if=logical_expression (a logical expression of any complexity)

list country continent urb if infmor>25 Lists only observations where infant mortality is greater than 25
histogram urb if continent != 6Histogram for all countries except those from continent 6
list urb if country=="CH "List value of country "CH "
in Keyword (limits
list urb in 1/10List the first ten observations
list country continent urb in -10/lList the last ten observations (you can use l for last and f for first.
Removing observations from a dataset

If you need to perform many analyses only on a subset it it might be useful to remove observations that are of no interest from the dataset for that particular sequence of analyses

drop if urb>50 Drop all observation with urbanization >50 from the dataset