How to create and switch between datasets

It is possible to create more than one dataset through the commando create-dataset. 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 commando use.

The example below demonstrates how to create a new dataset datasett2 and to import variables into it, and finally how to switch back to the first dataset. The dataset demografidata contains all individuals registered with a gender, while datasett2 only includes individuals registered with a marital status per 2010-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 databank
require no.ssb.fdb:1 as fdb1

create-dataset demografidata
import fdb1/BEFOLKNING_KJOENN as sex

create-dataset datasett2
import fdb1/SIVSTANDFDT_SIVSTAND 2010-01-01 as sivstatus

use demografidata