Removing units from a dataset

Before carrying out analyses on a data set, it is usually desirable to trim it down by removing people you do not want to include. This can be done through the drop and keep commands in combination with standard IF conditions.

In the example below, the sample is trimmed down to contain people between 16 and 66.

//Connect to datastore
require no.ssb.fdb:23 as db

create-dataset demography
import db/BEFOLKNING_KJOENN as gender
import db/BEFOLKNING_FOEDSELS_AAR_MND as birth_year_month

generate age = 2021 - int(birth_year_month / 100)

keep if age >= 16 & age < 67