Removing units from a dataset

In order to perform statistical analysis on a dataset, there is often a need to trim the dataset by removing unwanted units. This can be done by using the commandos drop or keep in combination with standard IF-conditions.

In the example below, the data population is trimmed into persons between 16 and 66 years of age.

create-dataset demografidata
import BEFOLKNING_KJOENN as kjønn

generate alder = 2010 - int(faarmnd / 100)

keep if alder >= 16 & alder < 67