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
import BEFOLKNING_FOEDSELS_AAR_MND as faarmnd

generate alder = 2010 - int(faarmnd / 100)

keep if alder >= 16 & alder < 67