iotables 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
iotables-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Wouter Wakker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,311 @@
1
+ Metadata-Version: 2.4
2
+ Name: iotables
3
+ Version: 0.1.0
4
+ Summary: A Python package to easily load and work with inter-country input-output data
5
+ Author-email: Wouter Wakker <wouter.wakker@outlook.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/WWakker/iotables
8
+ Project-URL: Repository, https://github.com/WWakker/iotables
9
+ Project-URL: Changelog, https://github.com/WWakker/iotables/blob/main/CHANGELOG.MD
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Operating System :: OS Independent
17
+ Requires-Python: >=3.9
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: curl_cffi>=0.5
21
+ Requires-Dist: numpy<3,>=1.21
22
+ Requires-Dist: pandas>=1.3
23
+ Requires-Dist: matplotlib>=3.4
24
+ Requires-Dist: tqdm>=4.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest; extra == "dev"
27
+ Requires-Dist: pytest-cov; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # iotables
31
+
32
+ ## Description
33
+
34
+ This repository contains Python codes to easily load inter-country input-output data and give access to convenient attributes and methods
35
+ to deal with these data, for example to run demand or supply shocks using Leontief or Ghosh models.
36
+ Baldwin, Freeman & Theodorakopoulos (2022) is recommended as an introduction to input-output tables
37
+ and Miller & Blair (2022) is recommended for background on the theory, but the basics are explained below.
38
+
39
+ Currently the following databases are supported:
40
+ - [OECD](http://oe.cd/icio)
41
+ - [Figaro](https://ec.europa.eu/eurostat/web/esa-supply-use-input-tables)
42
+ - [ExioBase](https://www.exiobase.eu/)
43
+
44
+ ## Installation
45
+ ```bash
46
+ pip install iotables
47
+ ```
48
+
49
+ ## Structure of input-output data
50
+
51
+ Input-output tables model the economy in matrix form. Here, we explain input-output data using OECD data as an example.
52
+ The OECD input-output tables contain inputs and outputs in current million USD for a set of sectors and countries (the
53
+ exact counts depend on the edition; see `config.py`) as well as rest-of-world. China and Mexico data are split into CN1,
54
+ CN2, MX1, and MX2.
55
+
56
+ ![OECD sctructure](res/OECD_structure.png)
57
+ *Source*: OECD
58
+
59
+ **Z** contains the intermediate inputs and outputs between industries. Rows represent outputs and
60
+ columns represent inputs. Of course, not all outputs serve as input for other industries, as some products are final
61
+ products for household consumption, government investment etc. These products are represented in final demand (**FD**) at
62
+ country and category level, where the categories are Household Final Consumption Expenditure; Non-Profit Institutions Serving
63
+ Households; General Government Final Consumption; Gross Fixed Capital Formation; Changes in Inventories and Valuables;
64
+ Direct purchases abroad by residents.
65
+
66
+ The sum of intermediate outputs and final demand is equal to the total country-sector output, which also is equal to total
67
+ country-sector input (**X**). The difference between intermediate inputs and total inputs is gross value added, which is split
68
+ up into taxes less subsidies (**TLS**) and net value added (**V**).
69
+
70
+ ## Theory
71
+
72
+ ### Leontief model
73
+
74
+ Let
75
+
76
+ ```math
77
+ x = \begin{bmatrix}
78
+ x_{1}\\ \vdots\\ x_{n}
79
+ \end{bmatrix},\:
80
+ Z = \begin{bmatrix}
81
+ z_{11} & \dots & z_{1n}\\
82
+ \vdots & \ddots & \vdots\\
83
+ z_{n1} & \dots & z_{nn}\\
84
+ \end{bmatrix},\:
85
+ f = \begin{bmatrix}
86
+ f_{1}\\ \vdots\\ f_{n}
87
+ \end{bmatrix}
88
+ ```
89
+
90
+ where **x** is a column vector representing total output with the total output of each sector, **Z** is a matrix of
91
+ intermediate use of inputs, with columns (*j*) representing inputs and rows (*i*) representing outputs, and **f** is a
92
+ column vector representing final demand for each sector. Total output equals the sum of intermediate output (*Zi*, where
93
+ *i* is a column vector of 1's) and final demand as
94
+
95
+ ```math
96
+ \begin{equation}
97
+ x = Zi + f
98
+ \end{equation}
99
+ ```
100
+
101
+ We define a matrix A by dividing each column in Z by the total input, such that $a_{ij} = z_{ij}/x_{j}$, as
102
+
103
+ ```math
104
+ \begin{equation}
105
+ A = Z\hat{x}^{-1}
106
+ \end{equation}
107
+ ```
108
+
109
+ 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
110
+
111
+ ```math
112
+ \begin{equation}
113
+ x = Ax + f
114
+ \end{equation}
115
+ ```
116
+
117
+ It follows that
118
+
119
+ ```math
120
+ f = x - Ax = (I - A)x \Rightarrow x = (I - A)^{-1}f
121
+ ```
122
+
123
+ Here, $(I - A)^{-1}$ is the so-called Leontief inverse **L**, so the equation can be written as
124
+
125
+ ```math
126
+ \begin{equation}
127
+ x = Lf
128
+ \end{equation}
129
+ ```
130
+
131
+ 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
132
+
133
+ ```math
134
+ \begin{equation}
135
+ \Delta x = L \Delta f
136
+ \end{equation}
137
+ ```
138
+
139
+ ### Ghosh model
140
+
141
+ Where Leontief relates sectoral outputs to the amount of final product, or products leaving the system,
142
+ Ghosh (1958) relates sectoral production to the primary inputs $v'$, or value entering the system. Instead of (1),
143
+ output is then expressed as
144
+
145
+ ```math
146
+ \begin{equation}
147
+ x' = i'Z + v'
148
+ \end{equation}
149
+ ```
150
+
151
+ where v' is the primary inputs or value added.
152
+
153
+ 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*.
154
+
155
+ ```math
156
+ \begin{equation}
157
+ B = \hat{x}^{-1} Z
158
+ \end{equation}
159
+ ```
160
+
161
+ In a similar fashion as done above
162
+
163
+ ```math
164
+ \begin{equation}
165
+ x' = x'B + v'
166
+ \end{equation}
167
+ ```
168
+
169
+ then
170
+
171
+ ```math
172
+ v' = x' - x'B = (I - B)x' \Rightarrow x' = v'(I - B)^{-1}
173
+ ```
174
+
175
+ Similarly, $(I - B)^{-1}$ is called the Ghosh inverse **G**, so the equation can be written as
176
+
177
+ ```math
178
+ \begin{equation}
179
+ x' = v'G
180
+ \end{equation}
181
+ ```
182
+
183
+ This is equivalent to
184
+
185
+ ```math
186
+ \begin{equation}
187
+ x = G'v
188
+ \end{equation}
189
+ ```
190
+
191
+ which can also be written in changes as
192
+
193
+ ```math
194
+ \begin{equation}
195
+ \Delta x = G' \Delta v
196
+ \end{equation}
197
+ ```
198
+
199
+ This is the Ghosh equation, which defines the relation between production output and primary inputs or value added.
200
+
201
+ ## How to use
202
+
203
+ ### Create an instance of the OECD class
204
+
205
+ Creating an instance of the OECD class loads the OECD data and gives access to convenient attributes and methods.
206
+ An instance can be created as follows, specifying an available year for the chosen version (e.g. 1995-2018 for the
207
+ `2021` version, up to 2022 for the `2025` versions).
208
+
209
+ ```python
210
+ import iotables
211
+ oecd = iotables.OECD(version='2025', year=2022, refresh=False)
212
+ ```
213
+
214
+ Similary, an instance can be created for other data, for example Figaro and ExioBase as
215
+
216
+ ```python
217
+ import iotables
218
+ figaro = iotables.Figaro(version='2025', year=2022, kind='industry-by-industry')
219
+ exio = iotables.ExioBase(version='3.81', year=2022, kind='industry-by-industry')
220
+ ```
221
+
222
+ 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:
223
+
224
+ | Attribute or method | Description |
225
+ | --- | --- |
226
+ | `version` | Specified version |
227
+ | `year` | Specified year |
228
+ | `df` | Raw input-output data as pandas dataframe |
229
+ | `regions` | List of regions |
230
+ | `sectors` | List of sectors |
231
+ | `unit` | Unit of datapoints |
232
+ | `rs` | `len(regions)` * `len(sectors)` |
233
+ | `Z` | Intermediate use |
234
+ | `V` | Gross value added |
235
+ | `FD` | Final demand |
236
+ | `X` | Output |
237
+ | `A` | Technical coefficients |
238
+ | `L` | Leontief inverse |
239
+ | `B` | Allocation coefficients |
240
+ | `G` | Ghosh inverse |
241
+ | `FD_REGION` | Region breakdown of final demand |
242
+ | `FD_GRAN` | Granular breakdown of final demand |
243
+ | `ADD` | A dictionary of any granular breakdowns of sub-items that are available in the raw data |
244
+ | `sector_name_mapping` | Sector to name mapping |
245
+ | `demand_items` | Demand items included in the granular final demand matrix |
246
+ | `reference` | Reference |
247
+ | `contact` | Contact |
248
+ | `leontief_demand_shock` | Method to run a Leontief demand shock |
249
+ | `ghosh_supply_shock` | Method to run a Ghosh supply shock |
250
+ | `get_imports_exports` | Method to get imports and exports between regions/sectors
251
+ | `remove_downloaded_files` | Remove the downloaded files saved on the hard drive |
252
+
253
+ All matrices are extended `numpy.ndarray`'s with attributes `info`, `rows` and `columns`, and property `I` for inversion.
254
+
255
+ When running a Leontief or Ghosh shock, the percentage shock to final demand/primary inputs in countries and sectors can be specified as
256
+ ```python
257
+ import iotables
258
+
259
+ oecd = iotables.OECD(version='2025', year=2022)
260
+
261
+ df_l = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
262
+ df_g = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
263
+ ```
264
+
265
+ This will return a pandas dataframe with regions, sectors, original output and shocked output. It is also possible to provide
266
+ a custom shock vector if more flexibility is needed. In case this is supplied it will override the other shock parameters.
267
+
268
+ ```python
269
+ import numpy as np
270
+ custom_shock_vector = np.random.uniform(size=oecd.rs, low=-10, high=10).reshape(-1, 1)
271
+ df = oecd.leontief_demand_shock(custom_shock_vector=custom_shock_vector)
272
+ ```
273
+
274
+ In addition, it is possible to aggregate and plot the results by country or sector. In this case the methods
275
+ will return a matplotlib figure and axis to do post-formatting if needed.
276
+
277
+ ```python
278
+ fig, ax = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
279
+ plot=True, plot_regions=['FR', 'DE'], plot_by='region', show=True)
280
+
281
+ fig, ax = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
282
+ plot=True, plot_regions=['FR', 'DE'], plot_by='sector', show=True)
283
+ ```
284
+
285
+ ## Issues
286
+
287
+ In case you get an error when loading the data caused by `pandas`, it might be that the downloading of the file got interrupted
288
+ and therefore the file is corrupted. To solve this, try downloading the data again with `refresh=True`.
289
+
290
+
291
+ ## References
292
+
293
+ Baldwin, R., Freeman, R., & Theodorakopoulos, A. (2022). [Horses for courses: measuring foreign supply chain exposure](https://www.nber.org/system/files/working_papers/w30525/w30525.pdf), NBER Working Papers 30525, National Bureau of Economic Research, Inc.
294
+
295
+ Ghosh, A. (1958). [Input-Output approach in an allocation system](https://www.jstor.org/stable/pdf/2550694.pdf), Economica, 25 (97), 58-64.
296
+
297
+ Miller, R., & Blair, P. (2022). [Input-Output Analysis: Foundations and Extensions](https://www.cambridge.org/de/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/input-output-analysis-foundations-and-extensions-3rd-edition?format=HB&isbn=9781108484763), Cambridge: Cambridge University Press.
298
+
299
+ OECD (2021). OECD Inter-Country Input-Output Database. http://oe.cd/icio
300
+
301
+ Oosterhaven, J. (1988). [On the plausibility of the supply-driven input-output model](https://onlinelibrary.wiley.com/doi/10.1111/j.1467-9787.1988.tb01208.x), Journal of Regional Science, 28, 203-217.
302
+
303
+ ## Contributors
304
+
305
+ [Simone Boldrini](https://github.com/simoboldrini), 2022
306
+
307
+ ## Author
308
+
309
+ [Wouter Wakker](https://github.com/WWakker), 2022
310
+
311
+ [![Python](https://img.shields.io/static/v1?label=made%20with&message=Python&color=blue&style=for-the-badge&logo=Python&logoColor=white)](#)
@@ -0,0 +1,282 @@
1
+ # iotables
2
+
3
+ ## Description
4
+
5
+ This repository contains Python codes to easily load inter-country input-output data and give access to convenient attributes and methods
6
+ to deal with these data, for example to run demand or supply shocks using Leontief or Ghosh models.
7
+ Baldwin, Freeman & Theodorakopoulos (2022) is recommended as an introduction to input-output tables
8
+ and Miller & Blair (2022) is recommended for background on the theory, but the basics are explained below.
9
+
10
+ Currently the following databases are supported:
11
+ - [OECD](http://oe.cd/icio)
12
+ - [Figaro](https://ec.europa.eu/eurostat/web/esa-supply-use-input-tables)
13
+ - [ExioBase](https://www.exiobase.eu/)
14
+
15
+ ## Installation
16
+ ```bash
17
+ pip install iotables
18
+ ```
19
+
20
+ ## Structure of input-output data
21
+
22
+ Input-output tables model the economy in matrix form. Here, we explain input-output data using OECD data as an example.
23
+ The OECD input-output tables contain inputs and outputs in current million USD for a set of sectors and countries (the
24
+ exact counts depend on the edition; see `config.py`) as well as rest-of-world. China and Mexico data are split into CN1,
25
+ CN2, MX1, and MX2.
26
+
27
+ ![OECD sctructure](res/OECD_structure.png)
28
+ *Source*: OECD
29
+
30
+ **Z** contains the intermediate inputs and outputs between industries. Rows represent outputs and
31
+ columns represent inputs. Of course, not all outputs serve as input for other industries, as some products are final
32
+ products for household consumption, government investment etc. These products are represented in final demand (**FD**) at
33
+ country and category level, where the categories are Household Final Consumption Expenditure; Non-Profit Institutions Serving
34
+ Households; General Government Final Consumption; Gross Fixed Capital Formation; Changes in Inventories and Valuables;
35
+ Direct purchases abroad by residents.
36
+
37
+ The sum of intermediate outputs and final demand is equal to the total country-sector output, which also is equal to total
38
+ country-sector input (**X**). The difference between intermediate inputs and total inputs is gross value added, which is split
39
+ up into taxes less subsidies (**TLS**) and net value added (**V**).
40
+
41
+ ## Theory
42
+
43
+ ### Leontief model
44
+
45
+ Let
46
+
47
+ ```math
48
+ x = \begin{bmatrix}
49
+ x_{1}\\ \vdots\\ x_{n}
50
+ \end{bmatrix},\:
51
+ Z = \begin{bmatrix}
52
+ z_{11} & \dots & z_{1n}\\
53
+ \vdots & \ddots & \vdots\\
54
+ z_{n1} & \dots & z_{nn}\\
55
+ \end{bmatrix},\:
56
+ f = \begin{bmatrix}
57
+ f_{1}\\ \vdots\\ f_{n}
58
+ \end{bmatrix}
59
+ ```
60
+
61
+ where **x** is a column vector representing total output with the total output of each sector, **Z** is a matrix of
62
+ intermediate use of inputs, with columns (*j*) representing inputs and rows (*i*) representing outputs, and **f** is a
63
+ column vector representing final demand for each sector. Total output equals the sum of intermediate output (*Zi*, where
64
+ *i* is a column vector of 1's) and final demand as
65
+
66
+ ```math
67
+ \begin{equation}
68
+ x = Zi + f
69
+ \end{equation}
70
+ ```
71
+
72
+ We define a matrix A by dividing each column in Z by the total input, such that $a_{ij} = z_{ij}/x_{j}$, as
73
+
74
+ ```math
75
+ \begin{equation}
76
+ A = Z\hat{x}^{-1}
77
+ \end{equation}
78
+ ```
79
+
80
+ 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
81
+
82
+ ```math
83
+ \begin{equation}
84
+ x = Ax + f
85
+ \end{equation}
86
+ ```
87
+
88
+ It follows that
89
+
90
+ ```math
91
+ f = x - Ax = (I - A)x \Rightarrow x = (I - A)^{-1}f
92
+ ```
93
+
94
+ Here, $(I - A)^{-1}$ is the so-called Leontief inverse **L**, so the equation can be written as
95
+
96
+ ```math
97
+ \begin{equation}
98
+ x = Lf
99
+ \end{equation}
100
+ ```
101
+
102
+ 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
103
+
104
+ ```math
105
+ \begin{equation}
106
+ \Delta x = L \Delta f
107
+ \end{equation}
108
+ ```
109
+
110
+ ### Ghosh model
111
+
112
+ Where Leontief relates sectoral outputs to the amount of final product, or products leaving the system,
113
+ Ghosh (1958) relates sectoral production to the primary inputs $v'$, or value entering the system. Instead of (1),
114
+ output is then expressed as
115
+
116
+ ```math
117
+ \begin{equation}
118
+ x' = i'Z + v'
119
+ \end{equation}
120
+ ```
121
+
122
+ where v' is the primary inputs or value added.
123
+
124
+ 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*.
125
+
126
+ ```math
127
+ \begin{equation}
128
+ B = \hat{x}^{-1} Z
129
+ \end{equation}
130
+ ```
131
+
132
+ In a similar fashion as done above
133
+
134
+ ```math
135
+ \begin{equation}
136
+ x' = x'B + v'
137
+ \end{equation}
138
+ ```
139
+
140
+ then
141
+
142
+ ```math
143
+ v' = x' - x'B = (I - B)x' \Rightarrow x' = v'(I - B)^{-1}
144
+ ```
145
+
146
+ Similarly, $(I - B)^{-1}$ is called the Ghosh inverse **G**, so the equation can be written as
147
+
148
+ ```math
149
+ \begin{equation}
150
+ x' = v'G
151
+ \end{equation}
152
+ ```
153
+
154
+ This is equivalent to
155
+
156
+ ```math
157
+ \begin{equation}
158
+ x = G'v
159
+ \end{equation}
160
+ ```
161
+
162
+ which can also be written in changes as
163
+
164
+ ```math
165
+ \begin{equation}
166
+ \Delta x = G' \Delta v
167
+ \end{equation}
168
+ ```
169
+
170
+ This is the Ghosh equation, which defines the relation between production output and primary inputs or value added.
171
+
172
+ ## How to use
173
+
174
+ ### Create an instance of the OECD class
175
+
176
+ Creating an instance of the OECD class loads the OECD data and gives access to convenient attributes and methods.
177
+ An instance can be created as follows, specifying an available year for the chosen version (e.g. 1995-2018 for the
178
+ `2021` version, up to 2022 for the `2025` versions).
179
+
180
+ ```python
181
+ import iotables
182
+ oecd = iotables.OECD(version='2025', year=2022, refresh=False)
183
+ ```
184
+
185
+ Similary, an instance can be created for other data, for example Figaro and ExioBase as
186
+
187
+ ```python
188
+ import iotables
189
+ figaro = iotables.Figaro(version='2025', year=2022, kind='industry-by-industry')
190
+ exio = iotables.ExioBase(version='3.81', year=2022, kind='industry-by-industry')
191
+ ```
192
+
193
+ 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:
194
+
195
+ | Attribute or method | Description |
196
+ | --- | --- |
197
+ | `version` | Specified version |
198
+ | `year` | Specified year |
199
+ | `df` | Raw input-output data as pandas dataframe |
200
+ | `regions` | List of regions |
201
+ | `sectors` | List of sectors |
202
+ | `unit` | Unit of datapoints |
203
+ | `rs` | `len(regions)` * `len(sectors)` |
204
+ | `Z` | Intermediate use |
205
+ | `V` | Gross value added |
206
+ | `FD` | Final demand |
207
+ | `X` | Output |
208
+ | `A` | Technical coefficients |
209
+ | `L` | Leontief inverse |
210
+ | `B` | Allocation coefficients |
211
+ | `G` | Ghosh inverse |
212
+ | `FD_REGION` | Region breakdown of final demand |
213
+ | `FD_GRAN` | Granular breakdown of final demand |
214
+ | `ADD` | A dictionary of any granular breakdowns of sub-items that are available in the raw data |
215
+ | `sector_name_mapping` | Sector to name mapping |
216
+ | `demand_items` | Demand items included in the granular final demand matrix |
217
+ | `reference` | Reference |
218
+ | `contact` | Contact |
219
+ | `leontief_demand_shock` | Method to run a Leontief demand shock |
220
+ | `ghosh_supply_shock` | Method to run a Ghosh supply shock |
221
+ | `get_imports_exports` | Method to get imports and exports between regions/sectors
222
+ | `remove_downloaded_files` | Remove the downloaded files saved on the hard drive |
223
+
224
+ All matrices are extended `numpy.ndarray`'s with attributes `info`, `rows` and `columns`, and property `I` for inversion.
225
+
226
+ When running a Leontief or Ghosh shock, the percentage shock to final demand/primary inputs in countries and sectors can be specified as
227
+ ```python
228
+ import iotables
229
+
230
+ oecd = iotables.OECD(version='2025', year=2022)
231
+
232
+ df_l = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
233
+ df_g = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'])
234
+ ```
235
+
236
+ This will return a pandas dataframe with regions, sectors, original output and shocked output. It is also possible to provide
237
+ a custom shock vector if more flexibility is needed. In case this is supplied it will override the other shock parameters.
238
+
239
+ ```python
240
+ import numpy as np
241
+ custom_shock_vector = np.random.uniform(size=oecd.rs, low=-10, high=10).reshape(-1, 1)
242
+ df = oecd.leontief_demand_shock(custom_shock_vector=custom_shock_vector)
243
+ ```
244
+
245
+ In addition, it is possible to aggregate and plot the results by country or sector. In this case the methods
246
+ will return a matplotlib figure and axis to do post-formatting if needed.
247
+
248
+ ```python
249
+ fig, ax = oecd.leontief_demand_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
250
+ plot=True, plot_regions=['FR', 'DE'], plot_by='region', show=True)
251
+
252
+ fig, ax = oecd.ghosh_supply_shock(shock=-10, regions=['FR', 'DE'], sectors=['01T02', '35'],
253
+ plot=True, plot_regions=['FR', 'DE'], plot_by='sector', show=True)
254
+ ```
255
+
256
+ ## Issues
257
+
258
+ In case you get an error when loading the data caused by `pandas`, it might be that the downloading of the file got interrupted
259
+ and therefore the file is corrupted. To solve this, try downloading the data again with `refresh=True`.
260
+
261
+
262
+ ## References
263
+
264
+ Baldwin, R., Freeman, R., & Theodorakopoulos, A. (2022). [Horses for courses: measuring foreign supply chain exposure](https://www.nber.org/system/files/working_papers/w30525/w30525.pdf), NBER Working Papers 30525, National Bureau of Economic Research, Inc.
265
+
266
+ Ghosh, A. (1958). [Input-Output approach in an allocation system](https://www.jstor.org/stable/pdf/2550694.pdf), Economica, 25 (97), 58-64.
267
+
268
+ Miller, R., & Blair, P. (2022). [Input-Output Analysis: Foundations and Extensions](https://www.cambridge.org/de/academic/subjects/economics/econometrics-statistics-and-mathematical-economics/input-output-analysis-foundations-and-extensions-3rd-edition?format=HB&isbn=9781108484763), Cambridge: Cambridge University Press.
269
+
270
+ OECD (2021). OECD Inter-Country Input-Output Database. http://oe.cd/icio
271
+
272
+ Oosterhaven, J. (1988). [On the plausibility of the supply-driven input-output model](https://onlinelibrary.wiley.com/doi/10.1111/j.1467-9787.1988.tb01208.x), Journal of Regional Science, 28, 203-217.
273
+
274
+ ## Contributors
275
+
276
+ [Simone Boldrini](https://github.com/simoboldrini), 2022
277
+
278
+ ## Author
279
+
280
+ [Wouter Wakker](https://github.com/WWakker), 2022
281
+
282
+ [![Python](https://img.shields.io/static/v1?label=made%20with&message=Python&color=blue&style=for-the-badge&logo=Python&logoColor=white)](#)
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "iotables"
7
+ version = "0.1.0"
8
+ description = "A Python package to easily load and work with inter-country input-output data"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Wouter Wakker", email = "wouter.wakker@outlook.com" }]
13
+ requires-python = ">=3.9"
14
+ dependencies = [
15
+ "curl_cffi>=0.5",
16
+ "numpy>=1.21,<3",
17
+ "pandas>=1.3",
18
+ "matplotlib>=3.4",
19
+ "tqdm>=4.0",
20
+ ]
21
+ classifiers = [
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.9",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3.13",
28
+ "Operating System :: OS Independent",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/WWakker/iotables"
33
+ Repository = "https://github.com/WWakker/iotables"
34
+ Changelog = "https://github.com/WWakker/iotables/blob/main/CHANGELOG.MD"
35
+
36
+ [project.optional-dependencies]
37
+ dev = ["pytest", "pytest-cov"]
38
+
39
+ [tool.setuptools.packages.find]
40
+ where = ["src"]
41
+
42
+ [tool.setuptools.package-data]
43
+ iotables = ["py.typed"]
44
+
45
+ [tool.pytest.ini_options]
46
+ testpaths = ["tests"]
47
+ markers = [
48
+ "network: test downloads real data over the network (deselect with '-m \"not network\"')",
49
+ ]
50
+
51
+ [tool.coverage.run]
52
+ source = ["iotables"]
53
+ omit = ["**/adjust_source_in_covxml.py"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+