How to create and switch between datasets

It is possible to create more than one dataset through the create-dataset command. All operations are performed on the last dataset created (the user is automatically switched to the newest dataset). If work on a different dataset is needed, this can be done through the use command.

The example below demonstrates how to create a new dataset dataset2 and to import variables into it, and finally how to switch back to the first dataset. The dataset demography contains all individuals registered with a gender, while dataset2 only includes individuals registered with a marital status per 2021-01-01. Thus, the datasets cover different populations.

Note: The first variable imported decides the population size of the specific dataset (additional variables are merged into the dataset through the left-join principle). Consequently, one should not start out by importing a variable that only measures parts of the analysis population.

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

create-dataset demography
import db/BEFOLKNING_KJOENN as gender

create-dataset dataset2
import db/SIVSTANDFDT_SIVSTAND 2021-01-01 as sivilstatus

use demography