ThGaskin's picture
Dataset card
560a124 verified
|
Raw History Blame Contribute Delete
5.64 kB
---
pretty_name: Migration explorer database
language:
- en
tags:
- migration
- demography
- duckdb
viewer: false
---
# Migration explorer database
The database behind the **Migration explorer**, an interactive explorer for the UN migration flow estimates. For each
country, it holds the estimates together with all the data used as training targets or inputs, the data that were
considered and not used or excluded (with the reason), and where each value comes from.
> **Private, work in progress.** The new estimates (`source_id` `estimates`, `estimates_bilateral`) come from the
> published ensemble fine-tuned on the updated training data. They are preliminary and not a release. The estimates of
> Gaskin & Abel (Nature 2026) are included for comparison as `published_estimates` and `published_estimates_bilateral`.
## Contents
`explorer.duckdb`, the database, which each pipeline run replaces. Alongside it, in `estimates/`, the estimates of
the fine-tuned ensemble as CSV files, in the format of the published estimates (also in the database):
- `estimates/mig_unilateral.csv`: by country and year, net migration (`net`), immigration (`imm`), emigration (`emi`),
and the migrant stocks at the start of the year (`imm_pop`: foreign-born; `emi_pop`: born in the country, living
abroad), as the ensemble mean, with the standard deviation in `<column>_std`
- `estimates/mig_bilateral.csv`: by origin, destination and year, the flows by previous residence (`mig_prev`) and by
country of birth (`mig_brth`), and the bilateral stocks by country of birth at the start of the year (`stock_mean`),
each with its standard deviation (`mig_prev_std`, `mig_brth_std`, `stock_std`)
The database is built by `Explorer/build_db.py` in the
`Migration_flows_extended` repository, from the exports of its notebooks, the estimates, the UNPD candidate targets
and the provenance descriptions in `Explorer/sources.yaml`. The explorer (`Migration_explorer` repository) downloads it
at start and only displays it, without computing anything.
The table layout is defined in `Explorer/schema.sql` of the pipeline repository, which is the interface between the
two repositories. The `meta` table records the build:
| key | value |
|---|---|
| `schema_version` | version of the table layout (increased for changes that break the explorer) |
| `built_at` | time of the build |
| `pipeline_commit` | commit of `Migration_flows_extended` it was built from (`+dirty`: with uncommitted changes) |
## Tables
| Table | Contents |
|---|---|
| `countries` | ISO 3166 alpha-3 code, name, alpha-2 code |
| `sources` | every source (`source_id`), with name, URL, description (markdown) and vintage |
| `country_series` | annual country series: net migration, immigration, emigration, and the migrant stocks `foreign_born` and `born_abroad` |
| `net_migration_consistency` | consistency of each national net migration series with the UN DESA stocks (the basis of its weight) |
| `provenance` | per country and quantity: what is used, what is excluded and why, dated decisions, caveats (markdown) |
| `flows` | bilateral flows by previous residence (`residence`) and by country of birth (`birth`): all flow data, the UNPD candidates, the estimates |
| `flow_source_weights` | the weights of the flow sources by source, reporter and direction |
| `stocks` | bilateral migrant stocks by country of birth: UN DESA revisions, corrected and start-of-year stocks, their changes between stock years (the targets), the estimates |
| `notes` | texts not tied to a country: source descriptions, flow weights, the stock methodology, the change history |
| `covariates` | country covariates (GDP, population, life expectancy, birth and death rates, conflict deaths, EU membership), with the source and kind of source of each value |
| `bilateral_covariates` | trade, refugees, distance, linguistic and religious similarity, colonial ties (non-zero values only) |
| `data_vintages` | the date of every download and of every input placed by hand |
All values are in persons unless the schema says otherwise. Years are calendar years. Stocks and the stock-based series
refer to the start of the year, and the UN DESA revisions to mid-year.
### Status of a value
| `status` | meaning |
|---|---|
| `target` | used as a training target, with its `weight` |
| `reference` | shown for comparison, not a target (e.g. WPP where national data exist) |
| `not_used` | considered but not used, e.g. a usable candidate that was not adopted |
| `excluded` | rejected, with the reason in `reason` |
| `estimate` | model estimate, with `lower` and `upper` (mean ± 1 s.d. of the ensemble) |
| `input` | covariates: the value used by the pipeline |
## Usage
Access needs a Hugging Face token with read access to this repository (`hf auth login`, or `HF_TOKEN`).
```python
import duckdb
from huggingface_hub import hf_hub_download
path = hf_hub_download("ThGaskin/Migration_explorer_db", "explorer.duckdb", repo_type="dataset")
con = duckdb.connect(path, read_only=True)
con.sql("""
SELECT year, source_id, value, status, weight
FROM country_series
WHERE iso = 'DEU' AND quantity = 'net_migration'
ORDER BY year, source_id
""").df()
```
## Sources
The data come from many providers: national statistical offices, UN DESA (WPP 2024, international migrant stocks),
the UNPD flow database, Eurostat, QuantMig, UNHCR, the World Bank, IMF, UCDP, CEPII, USITC and others. The `sources`
table lists each one with its URL and vintage, and their terms of use apply to the values taken from them. This
database is a working tool for the project and is not for redistribution.