A Python package to easily load and work with inter-country input-output data
Project description
iotables
Description
This repository contains Python codes to easily load inter-country input-output data and give access to convenient attributes and methods to deal with these data, for example to run demand or supply shocks using Leontief or Ghosh models. Baldwin, Freeman & Theodorakopoulos (2022) is recommended as an introduction to input-output tables and Miller & Blair (2022) is recommended for background on the theory, but the basics are explained below.
Currently the following databases are supported:
Installation
pip install iotables
Structure of input-output data
Input-output tables model the economy in matrix form. Here, we explain input-output data using OECD data as an example.
The OECD input-output tables contain inputs and outputs in current million USD for a set of sectors and countries (the
exact counts depend on the edition; see config.py) as well as rest-of-world. China and Mexico data are split into CN1,
CN2, MX1, and MX2.
Source: OECD
Z contains the intermediate inputs and outputs between industries. Rows represent outputs and columns represent inputs. Of course, not all outputs serve as input for other industries, as some products are final products for household consumption, government investment etc. These products are represented in final demand (FD) at country and category level, where the categories are Household Final Consumption Expenditure; Non-Profit Institutions Serving Households; General Government Final Consumption; Gross Fixed Capital Formation; Changes in Inventories and Valuables; Direct purchases abroad by residents.
The sum of intermediate outputs and final demand is equal to the total country-sector output, which also is equal to total country-sector input (X). The difference between intermediate inputs and total inputs is gross value added, which is split up into taxes less subsidies (TLS) and net value added (V).
Theory
Leontief model
Let
x = \begin{bmatrix}
x_{1}\\ \vdots\\ x_{n}
\end{bmatrix},\:
Z = \begin{bmatrix}
z_{11} & \dots & z_{1n}\\
\vdots & \ddots & \vdots\\
z_{n1} & \dots & z_{nn}\\
\end{bmatrix},\:
f = \begin{bmatrix}
f_{1}\\ \vdots\\ f_{n}
\end{bmatrix}
where x is a column vector representing total output with the total output of each sector, Z is a matrix of intermediate use of inputs, with columns (j) representing inputs and rows (i) representing outputs, and f is a column vector representing final demand for each sector. Total output equals the sum of intermediate output (Zi, where i is a column vector of 1's) and final demand as
\begin{equation}
x = Zi + f
\end{equation}
We define a matrix A by dividing each column in Z by the total input, such that $a_{ij} = z_{ij}/x_{j}$, as
\begin{equation}
A = Z\hat{x}^{-1}
\end{equation}
Each entry in A represents the share of sector j's input that comes from sector i, which is needed to produce a unit of sector j's output. These coefficients are called technical coefficients. Combining (1) and (2), and given that sector inputs are equal to sector outputs, output can be represented as
\begin{equation}
x = Ax + f
\end{equation}
It follows that
f = x - Ax = (I - A)x \Rightarrow x = (I - A)^{-1}f
Here, $(I - A)^{-1}$ is the so-called Leontief inverse L, so the equation can be written as
\begin{equation}
x = Lf
\end{equation}
This is the Leontief equation, which defines the relation between output and final demand, and can be used to assess how output changes in each sector following a change in demand in specified sectors. The equation can be specified in levels as in (4), or in differences as
\begin{equation}
\Delta x = L \Delta f
\end{equation}
Ghosh model
Where Leontief relates sectoral outputs to the amount of final product, or products leaving the system, Ghosh (1958) relates sectoral production to the primary inputs $v'$, or value entering the system. Instead of (1), output is then expressed as
\begin{equation}
x' = i'Z + v'
\end{equation}
where v' is the primary inputs or value added.
In the demand side equation, A is obtained by dividing each column entry by the total output of that sector. For Ghosh's supply side equation, B is obtained by dividing each row entry by the total sector output. Instead of technical coefficients these are called allocation coefficients, which represent the shares of sector i's output and their distribution across sectors j.
\begin{equation}
B = \hat{x}^{-1} Z
\end{equation}
In a similar fashion as done above
\begin{equation}
x' = x'B + v'
\end{equation}
then
v' = x' - x'B = (I - B)x' \Rightarrow x' = v'(I - B)^{-1}
Similarly, $(I - B)^{-1}$ is called the Ghosh inverse G, so the equation can be written as
\begin{equation}
x' = v'G
\end{equation}
This is equivalent to
\begin{equation}
x = G'v
\end{equation}
which can also be written in changes as
\begin{equation}
\Delta x = G' \Delta v
\end{equation}
This is the Ghosh equation, which defines the relation between production output and primary inputs or value added.
How to use
Create an instance of the OECD class
Creating an instance of the OECD class loads the OECD data and gives access to convenient attributes and methods.
An instance can be created as follows, specifying an available year for the chosen version (e.g. 1995-2018 for the
2021 version, up to 2022 for the 2025 versions).
import iotables
oecd = iotables.OECD(version='2025', year=2022, refresh=False)
Similary, an instance can be created for other data, for example Figaro and ExioBase as
import iotables
figaro = iotables.Figaro(version='2025', year=2022, kind='industry-by-industry')
exio = iotables.ExioBase(version='3.81', year=2022, kind='industry-by-industry')
Creating an instance of a database class downloads and loads the data into memory, creates standard input-output matrices, and gives access to the following attributes and methods:
| Attribute or method | Description |
|---|---|
version |
Specified version |
year |
Specified year |
df |
Raw input-output data as pandas dataframe |
regions |
List of regions |
sectors |
List of sectors |
unit |
Unit of datapoints |
rs |
len(regions) * len(sectors) |
Z |
Intermediate use |
V |
Gross value added |
FD |
Final demand |
X |
Output |
A |
Technical coefficients |
L |
Leontief inverse |
B |
Allocation coefficients |
G |
Ghosh inverse |
FD_REGION |
Region breakdown of final demand |
FD_GRAN |
Granular breakdown of final demand |
ADD |
A dictionary of any granular breakdowns of sub-items that are available in the raw data |
sector_name_mapping |
Sector to name mapping |
demand_items |
Demand items included in the granular final demand matrix |
reference |
Reference |
contact |
Contact |
leontief_demand_shock |
Method to run a Leontief demand shock |
ghosh_supply_shock |
Method to run a Ghosh supply shock |
get_imports_exports |
Method to get imports and exports between regions/sectors |
remove_downloaded_files |
Remove the downloaded files saved on the hard drive |
All matrices are extended numpy.ndarray's with attributes info, rows and columns, and property I for inversion.
When running a Leontief or Ghosh shock, the percentage shock to final demand/primary inputs in countries and sectors can be specified as
import iotables
oecd = iotables.OECD(version='2025', year=2022)
df_l = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
df_g = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
This will return a pandas dataframe with regions, sectors, original output and shocked output. It is also possible to provide a custom shock vector if more flexibility is needed. In case this is supplied it will override the other shock parameters.
import numpy as np
custom_shock_vector = np.random.uniform(size=oecd.rs, low=-10, high=10).reshape(-1, 1)
df = oecd.leontief_demand_shock(custom_shock_vector=custom_shock_vector)
In addition, it is possible to aggregate and plot the results by country or sector. In this case the methods will return a matplotlib figure and axis to do post-formatting if needed.
fig, ax = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
plot=True, plot_regions=['FR', 'DE'], plot_by='region', show=True)
fig, ax = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
plot=True, plot_regions=['FR', 'DE'], plot_by='sector', show=True)
Issues
In case you get an error when loading the data caused by pandas, it might be that the downloading of the file got interrupted
and therefore the file is corrupted. To solve this, try downloading the data again with refresh=True.
References
Baldwin, R., Freeman, R., & Theodorakopoulos, A. (2022). Horses for courses: measuring foreign supply chain exposure, NBER Working Papers 30525, National Bureau of Economic Research, Inc.
Ghosh, A. (1958). Input-Output approach in an allocation system, Economica, 25 (97), 58-64.
Miller, R., & Blair, P. (2022). Input-Output Analysis: Foundations and Extensions, Cambridge: Cambridge University Press.
OECD (2021). OECD Inter-Country Input-Output Database. http://oe.cd/icio
Oosterhaven, J. (1988). On the plausibility of the supply-driven input-output model, Journal of Regional Science, 28, 203-217.
Contributors
Simone Boldrini, 2022
Author
Wouter Wakker, 2022
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file iotables-0.1.0.tar.gz.
File metadata
- Download URL: iotables-0.1.0.tar.gz
- Upload date:
- Size: 34.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1719379eb5de93678161b1edcf10125af46cf087a469fa48af645abbf693ec3
|
|
| MD5 |
e13d9fa3d69ef6c550aa9f5821001030
|
|
| BLAKE2b-256 |
e88a4b00429a41f6386d43beb7428c51456321a3ef5a12fcab6ddf8f3bb74b3a
|
Provenance
The following attestation bundles were made for iotables-0.1.0.tar.gz:
Publisher:
deploy.yml on WWakker/iotables
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iotables-0.1.0.tar.gz -
Subject digest:
a1719379eb5de93678161b1edcf10125af46cf087a469fa48af645abbf693ec3 - Sigstore transparency entry: 1740658062
- Sigstore integration time:
-
Permalink:
WWakker/iotables@2d04eaff188a20311faacf1c4c97c4b1a66f04dc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/WWakker
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@2d04eaff188a20311faacf1c4c97c4b1a66f04dc -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file iotables-0.1.0-py3-none-any.whl.
File metadata
- Download URL: iotables-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afc000c926e03e0e8d96e06722c783ca7d9ad62803a3f36f807246e293d6c6b6
|
|
| MD5 |
0114452d1289af203bc100ef58480e89
|
|
| BLAKE2b-256 |
f18b34fe3d50c9c7bb3913cc29119acb4922ddfa3399006c33649ffe2f9a8944
|
Provenance
The following attestation bundles were made for iotables-0.1.0-py3-none-any.whl:
Publisher:
deploy.yml on WWakker/iotables
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iotables-0.1.0-py3-none-any.whl -
Subject digest:
afc000c926e03e0e8d96e06722c783ca7d9ad62803a3f36f807246e293d6c6b6 - Sigstore transparency entry: 1740658067
- Sigstore integration time:
-
Permalink:
WWakker/iotables@2d04eaff188a20311faacf1c4c97c4b1a66f04dc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/WWakker
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@2d04eaff188a20311faacf1c4c97c4b1a66f04dc -
Trigger Event:
workflow_dispatch
-
Statement type: