History of world_trade_atlas
The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.
[entries] New entry: world_trade_atlas 1d9aca6
diff --git a/entries/world_trade_atlas/__init__.py b/entries/world_trade_atlas/__init__.py
new file mode 100644
index 0000000..a6a867c
--- /dev/null
+++ b/entries/world_trade_atlas/__init__.py
@@ -0,0 +1,138 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from .. import *
+import pandas
+
+title = "World trade networks (Atlas of Economic Complexity, 1962-2024)"
+description = """Yearly networks of international trade in goods between countries and territories, from the trade data of the Atlas of Economic Complexity of the Growth Lab at Harvard University. The data are based on the bilateral trade flows reported to the United Nations Statistical Division (UN Comtrade), and cleaned by the Growth Lab with the Bustos-Yildirim method, which reconciles the values reported by exporters and importers to correct for inconsistent reporting. The Growth Lab publishes the data in four editions, with the goods classified with different systems, which differ in their coverage of years and goods: the Standard International Trade Classification (SITC), Revision 2, which covers the longest period (1962-2024) with about 700 products, and the Harmonized System (HS) in its 1992 (1995-2024), 2012 (2012-2024) and 2022 (2022-2024) versions, with about 5,000 products each. All four editions are included, with one network per edition and year, named after the edition and the year: `sitc_1962`, ..., `sitc_2024`, `hs92_1995`, ..., `hs92_2024`, `hs12_2012`, ..., `hs12_2024`, `hs22_2022`, ..., `hs22_2024`.
+
+Nodes are countries and territories, and a directed edge $(i,j)$ means that $i$ exported goods to $j$ in that year; edges are weighted by the total value of these exports (summed over all products), in current US dollars. Pairs without exports are not connected. The nodes of each network are the countries and territories that appear in that year's trade data (as exporters or importers, including some with no trade above zero in that year).
+
+The data are the files `<edition>_country_country_year.csv` (bilateral trade, summed over products) and `<edition>_country_year.csv` (the country-level measures) of the Harvard Dataverse datasets "International Trade Data (SITC, Rev. 2)" (version 18.0, April 2026), "International Trade Data (HS, 92)" (version 18.0), "International Trade Data (HS, 12)" (version 10.0) and "International Trade Data (HS, 22)" (version 2.0), and the country names from `location_country.csv` of version 12.0 of the Growth Lab's "Classifications Data". The trade data per product, which the datasets also contain (several GB per edition), and the Growth Lab's data on trade in services (which are not bilateral) are not included here.
+
+The networks have the following properties:
+
+- `year`, `classification` (the classification of goods of the edition: `SITC Rev. 2`, `HS 1992`, `HS 2012` or `HS 2022`): graph properties.
+- `name`: the name of the country.
+- `iso3`: the three-letter code of the country (the Growth Lab's augmented version of the ISO 3166-1 alpha-3 codes; e.g. `ANS` for the former Netherlands Antilles).
+- `country_id`: the numeric code of the country (the Growth Lab's augmented version of the UN M49 codes).
+- `former_country`: whether the country no longer exists (e.g. the Netherlands Antilles).
+- `export_value`, `import_value`: the total value of the country's exports and imports of goods in that year, in current US dollars (0 if not available).
+- `eci`: the Economic Complexity Index of the country in that year (NaN if not computed, e.g. for countries outside the Growth Lab's rankings).
+- `coi`: the Complexity Outlook Index of the country in that year (NaN if not computed).
+- `diversity`: the number of products the country exports with a revealed comparative advantage of at least one (-1 if not computed).
+- Edge `weight`: the value of the exports from $i$ to $j$ in that year, in current US dollars."""
+tags = ['Economic', 'Trade', 'Weighted', 'Metadata']
+url = ['https://doi.org/10.7910/DVN/H8SFD2', 'https://doi.org/10.7910/DVN/T4CHWJ',
+ 'https://doi.org/10.7910/DVN/YAVJDF', 'https://doi.org/10.7910/DVN/FTUUJU',
+ 'https://doi.org/10.7910/DVN/3BAL1O', 'https://atlas.hks.harvard.edu/data-downloads']
+citation = [('The Growth Lab at Harvard University, "International Trade Data (SITC, Rev. 2)." Harvard Dataverse, V18 (2026)',
+ 'https://doi.org/10.7910/DVN/H8SFD2'),
+ ('The Growth Lab at Harvard University, "International Trade Data (HS, 92)." Harvard Dataverse, V18 (2026)',
+ 'https://doi.org/10.7910/DVN/T4CHWJ'),
+ ('The Growth Lab at Harvard University, "International Trade Data (HS, 12)." Harvard Dataverse, V10 (2026)',
+ 'https://doi.org/10.7910/DVN/YAVJDF'),
+ ('The Growth Lab at Harvard University, "International Trade Data (HS, 22)." Harvard Dataverse, V2 (2026)',
+ 'https://doi.org/10.7910/DVN/FTUUJU'),
+ ('The Growth Lab at Harvard University, "Classifications Data." Harvard Dataverse, V12 (2026)',
+ 'https://doi.org/10.7910/DVN/3BAL1O')]
+icon_hash = None
+upstream_license = ("Creative Commons Zero v1.0 Universal (CC0 1.0)",
+ "http://creativecommons.org/publicdomain/zero/1.0")
+
+# Harvard Dataverse file ids (a file that changes in a new version of a
+# dataset gets a new id): <classification>_country_country_year.csv and
+# <classification>_country_year.csv of version 18.0 of
+# doi:10.7910/DVN/H8SFD2 (SITC), version 18.0 of doi:10.7910/DVN/T4CHWJ
+# (HS92), version 10.0 of doi:10.7910/DVN/YAVJDF (HS12) and version 2.0 of
+# doi:10.7910/DVN/FTUUJU (HS22), and location_country.csv of version 12.0 of
+# doi:10.7910/DVN/3BAL1O
+upstream_prefix = 'https://dataverse.harvard.edu/api/access/datafile'
+LOCATION_COUNTRY = '13809180'
+# classification: (country_country_year, country_year, years)
+CLASSIFICATIONS = {"sitc": ('13685154', '13685143', range(1962, 2025)),
+ "hs92": ('13685107', '13685109', range(1995, 2025)),
+ "hs12": ('13685174', '13685175', range(2012, 2025)),
+ "hs22": ('13685124', '13685130', range(2022, 2025))}
+files = [((ccy, cy, LOCATION_COUNTRY), f"{c}_{y}", None)
+ for c, (ccy, cy, years) in CLASSIFICATIONS.items() for y in years]
+
+CLASSIFICATION_NAMES = {"sitc": "SITC Rev. 2", "hs92": "HS 1992", "hs12": "HS 2012",
+ "hs22": "HS 2022"}
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+@cache_network()
+@coerce_props(vforce={"name": "string", "eci": "double", "coi": "double"})
+@annotate()
+def parse(alts=None):
+ global files
+ name = __name__.split(".")[-1]
+ data = {}
+ for fnames, alt, fmt in files:
+ if alts is not None and alt not in alts:
+ continue
+ clas, year = alt.split("_")
+ if clas not in data:
+ data.clear() # one classification at a time
+ fccy, fcy, floc = fnames
+ with open_upstream_file(name, fccy, "rb") as f:
+ ccy = pandas.read_csv(f, keep_default_na=False)
+ with open_upstream_file(name, fcy, "rb") as f:
+ cy = pandas.read_csv(f, keep_default_na=False, na_values=[""])
+ with open_upstream_file(name, floc, "rb") as f:
+ loc = pandas.read_csv(f, keep_default_na=False)
+ loc = loc.set_index("country_id")
+ iso3 = dict(zip(ccy.country_id, ccy.country_iso3_code))
+ iso3.update(zip(ccy.partner_country_id, ccy.partner_iso3_code))
+ data[clas] = (ccy.groupby("year"), cy.set_index(["year", "country_id"]),
+ loc, iso3)
+ by_year, cy, loc, iso3 = data[clas]
+ year = int(year)
+ d = by_year.get_group(year)
+ ids = sorted(set(d.country_id) | set(d.partner_country_id))
+ idx = {c: i for i, c in enumerate(ids)}
+ g = Graph(directed=True)
+ g.add_vertex(len(ids))
+ g.gp.year = g.new_gp("int", val=year)
+ g.gp.classification = g.new_gp("string", val=CLASSIFICATION_NAMES[clas])
+ g.vp.name = g.new_vp("string", vals=[loc.country_name.get(c, iso3[c])
+ for c in ids])
+ g.vp.iso3 = g.new_vp("string", vals=[iso3[c] for c in ids])
+ g.vp.country_id = g.new_vp("int", vals=ids)
+ g.vp.former_country = g.new_vp("bool", vals=[str(loc.former_country.get(c, False)) == "True"
+ for c in ids])
+ rows = [cy.loc[(year, c)] if (year, c) in cy.index else None for c in ids]
+ def col(k, default, conv):
+ return [default if r is None or pandas.isna(r[k]) else conv(r[k])
+ for r in rows]
+ g.vp.export_value = g.new_vp("int64_t", vals=col("export_value", 0, int))
+ g.vp.import_value = g.new_vp("int64_t", vals=col("import_value", 0, int))
+ g.vp.eci = g.new_vp("double", vals=col("eci", numpy.nan, float))
+ g.vp.coi = g.new_vp("double", vals=col("coi", numpy.nan, float))
+ g.vp.diversity = g.new_vp("int", vals=col("diversity", -1, int))
+ d = d[d.export_value > 0]
+ g.ep.weight = g.new_ep("int64_t")
+ g.add_edge_list(numpy.column_stack(([idx[c] for c in d.country_id],
+ [idx[c] for c in d.partner_country_id],
+ d.export_value.to_numpy())),
+ eprops=[g.ep.weight])
+ yield alt, g