Title: | Value Added in Exports and Other Input-Output Table Analysis Tools |
---|---|
Description: | Analysis of trade in value added with international input-output tables. Includes commands for easy data extraction, matrix manipulation, decomposition of value added in gross exports and calculation of value added indicators, with full geographical and sector customization. Decomposition methods include Borin and Mancini (2023) <doi:10.1080/09535314.2022.2153221>, Miroudot and Ye (2021) <doi:10.1080/09535314.2020.1730308>, Wang et al. (2013) <https://econpapers.repec.org/paper/nbrnberwo/19677.htm> and Koopman et al. (2014) <doi:10.1257/aer.104.2.459>. |
Authors: | Enrique Feas [aut, cre] |
Maintainer: | Enrique Feas <[email protected]> |
License: | GPL-3 |
Version: | 0.9.0 |
Built: | 2024-11-16 03:18:59 UTC |
Source: | https://github.com/cran/exvatools |
Produces a block diagonal matrix version of block matrix, i.e., a matrix in which the diagonal blocks are non-zero and the off-diagonal blocks are zero
bkd(df)
bkd(df)
df |
A block matrix with named rows and columns. Names of countries and sectors are automatically identified. |
Block diagonal version of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) # Block diagonal version of Y (coincides with Yd) bkd(wio$Y)
wio <- make_wio("wiodtest", quiet = TRUE) # Block diagonal version of Y (coincides with Yd) bkd(wio$Y)
Diagonalize each block of a block matrix, so sectors of origin become also
sectors of destination. Blocks of dimension NxN
will remain
NxN
, but diagonalized, and blocks of dimensions Nx1
will
be expanded to NxN
and then diagonalized.
bkdiag(df)
bkdiag(df)
df |
A block matrix with named rows and columns. |
Matrix df
with blocks of dimension NxN
diagonalized.
wio <- make_wio("wiodtest", quiet = TRUE) # Normal version of matrix Y wio$Y # Diagonal version (show first columns only) bkdiag(wio$Y)[, 1:6]
wio <- make_wio("wiodtest", quiet = TRUE) # Normal version of matrix Y wio$Y # Diagonal version (show first columns only) bkdiag(wio$Y)[, 1:6]
Produces a block off-diagonal matrix version of block matrix, i.e., a matrix in which the diagonal blocks are zero and the off-diagonal blocks are non-zero.
bkoffd(df)
bkoffd(df)
df |
A block matrix with named rows and columns. Names of countries and sectors are automatically identified. |
Block off-diagonal version of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) # Block off-diagonal version of Y (coincides with Ym) bkoffd(wio$Y)
wio <- make_wio("wiodtest", quiet = TRUE) # Block off-diagonal version of Y (coincides with Ym) bkoffd(wio$Y)
Transpose a matrix by blocks, so block(s,r)
becomes block(r,s)
, but
elements within each block are not transposed.
bkt(df)
bkt(df)
df |
A block matrix with named rows and columns. Names of countries and sectors are automatically identified. |
bkt()
takes a matrix of c1 x c2
blocks where each
block has a dimension s1 x s2
and transposes its blocks. Block
B21
becomes B12
, B31
becomes B13
, etc., but
blocks are not altered internally. For instance, a matrix with rows
5 exporting countries of 4 sectors each and columns with 3
importing countries with 2 aggregated sectors, i.e., a
(5 x 4) x (3 x 2), matrix will become a (3 x 4) x (5 x 2) matrix. The
rows will now show the importing countries and the sectors they import
from, and the columns will show the the exporting countries and the
sectors they export from.
Block transposed version of df
.
wio <- make_wio("wiodtest", quiet = TRUE) # Matrix Ym (exports of final products) wio$Ym # Block transposed version of Ym (imports of final products) bkt(wio$Ym)
wio <- make_wio("wiodtest", quiet = TRUE) # Matrix Ym (exports of final products) wio$Ym # Block transposed version of Ym (imports of final products) bkt(wio$Ym)
Block transpose matrix and then transpose each block. block(s,r)
is
transformed into block(r,s)
and then internally transposed. This is not
equivalent to directly transpose the matrix.
bktt(df)
bktt(df)
df |
A square block matrix with named rows and columns.
Names of countries and sectors are automatically identified. Unlike
|
Block transposed version of df
with elements transposed.
wio <- make_wio("wiodtest", quiet = TRUE) # Block-transpose Z and transpose blocks (show first elements only) bktt(wio$Z)[1:6, 1:6] # Note that directly transposing Z produces a different result: t(wio$Z)[1:6, 1:6]
wio <- make_wio("wiodtest", quiet = TRUE) # Block-transpose Z and transpose blocks (show first elements only) bktt(wio$Z)[1:6, 1:6] # Note that directly transposing Z produces a different result: t(wio$Z)[1:6, 1:6]
Improved version of colSums()
for matrix output. The sum of columns is
kept as a row vector with column names and the resulting row can be
named in the same command.
csums(df, row_name = NULL)
csums(df, row_name = NULL)
df |
A matrix with named rows and columns. |
row_name |
String, name to assign to resulting row. |
A row matrix (with rows and column names)
wio <- make_wio("wiodtest", quiet = TRUE) csums(wio$Y, "TOTAL_Y")
wio <- make_wio("wiodtest", quiet = TRUE) csums(wio$Y, "TOTAL_Y")
Makes a diagonal matrix with the sums of columns of a matrix.
Diagonalizes the sums of each column of a matrix.
diagcs(df) diagcs(df)
diagcs(df) diagcs(df)
df |
A matrix with named rows and columns. |
A diagonal matrix with the sums of columns in the diagonal.
A diagonal matrix with the sums of columns in the diagonal.
wio <- make_wio("wiodtest") diagcs(wio$W %*% wio$Bd) wio <- make_wio("wiodtest") diagcs(wio$W %*% wio$Bd)
wio <- make_wio("wiodtest") diagcs(wio$W %*% wio$Bd) wio <- make_wio("wiodtest") diagcs(wio$W %*% wio$Bd)
Fast multiplication of a diagonal matrix by another matrix, taking taking advantage of the properties of diagonal matrices.
dmult(matrix1, matrix2)
dmult(matrix1, matrix2)
matrix1 |
A diagonal matrix. |
matrix2 |
An ordinary matrix. |
dmult()
will turn matrix1
into a vector and multiply it
horizontally by every rows in matrix2
. This saves precious computing
time.\
The number of rows and columns of the diagonal matrix1
must be
equal to the number of rows of matrix1
.
Product of matrix1 and matrix2.
wio <- make_wio("wiodtest") dmult(wio$W, wio$Bd)
wio <- make_wio("wiodtest") dmult(wio$W, wio$Bd)
Extracts exporting country and sector and destination data from a specific
variable in an exvatools
object.
get_data( exvatools_object, var, exporter, sector = "TOTAL", importer = "WLD", demand_comp = "TOTAL", custom = FALSE )
get_data( exvatools_object, var, exporter, sector = "TOTAL", importer = "WLD", demand_comp = "TOTAL", custom = FALSE )
exvatools_object |
An |
var |
String for the selected variable included in the |
exporter |
String vector with codes of the exporting countries.\
If the |
sector |
A character vector with sector codes, e.g. |
importer |
String vector with importing country or country group codes,
e.g. |
demand_comp |
A character vector of demand components, e.g.,
|
custom |
Boolean specifying whether custom-made groups of countries
or sectors are present in the environment to be used. For instance, a
custom |
A two-dimensional matrix with sector and geographical data of a variable.
wio <- make_wio("wiodtest") get_data(wio, "EXGR", exp = "ESP", sec = "MANUF") get_data(wio, "EXGR", exp = "ESP", sec = c("TOTAL", "MANUF", "SRVWC"), imp = c("USA", "FRA"))
wio <- make_wio("wiodtest") get_data(wio, "EXGR", exp = "ESP", sec = "MANUF") get_data(wio, "EXGR", exp = "ESP", sec = c("TOTAL", "MANUF", "SRVWC"), imp = c("USA", "FRA"))
Detail from an exvadec
decomposition of a country by sector and
by destination
get_exvadec_bkdown( exvadec_object, exporter = "WLD", sector = "TOTAL", importer = "WLD" )
get_exvadec_bkdown( exvadec_object, exporter = "WLD", sector = "TOTAL", importer = "WLD" )
exvadec_object |
An |
exporter |
A character string with the code for the exporting country |
sector |
Character code of sector |
importer |
Character code of importer |
Print result to console
wio <- make_wio("wiodtest", quiet = TRUE) exvadec <- make_exvadec(wio, quiet = TRUE) get_exvadec_bkdown(exvadec, "ESP", "MANUF")
wio <- make_wio("wiodtest", quiet = TRUE) exvadec <- make_exvadec(wio, quiet = TRUE) get_exvadec_bkdown(exvadec, "ESP", "MANUF")
Gets the ISO3 codes of standard country groups available for the
different input-output tables. The resulting format can be used to
extract elements of a matrix using grep
.
get_geo_codes(geo_id, wiotype = "icio2023", icio_extend = FALSE)
get_geo_codes(geo_id, wiotype = "icio2023", icio_extend = FALSE)
geo_id |
String, country group id. Available |
wiotype |
String, type of input-output table. |
icio_extend |
Boolean. If |
Codes of country/countries ready to grep, e.g. AUS|ARG|BEL
# Get the codes of EU27 countries get_geo_codes("EU27", "icio2023") # Gets the codes for NAFTA and extends MEX to MX1|MX2 get_geo_codes("NAFTA", "icio2023", icio_extend = TRUE)
# Get the codes of EU27 countries get_geo_codes("EU27", "icio2023") # Gets the codes for NAFTA and extends MEX to MX1|MX2 get_geo_codes("NAFTA", "icio2023", icio_extend = TRUE)
Gets the ISO3 codes of standard sector groups available for the
different input-output tables. The resulting format can be used to
extract elements of a matrix using grep
.
get_sec_codes(sector_id, wiotype = "icio2023", remove_letter = FALSE)
get_sec_codes(sector_id, wiotype = "icio2023", remove_letter = FALSE)
sector_id |
String, sector or sector group code. Available
|
wiotype |
String, type of input-output database. |
remove_letter |
Boolean. If |
Codes of sector ready to grep, e.g. _01|_02|_03
.
# Get sector codes for manufactures in the icio2023 database. get_sec_codes("MANUF", "icio2023") # Get sector codes for services (including construction) get_sec_codes("SRVWC", "icio2023") # Get sector codes for manufacturing, removing the first letter so # the result can be used with `grep` to select specific sectors from # a matrix get_sec_codes("MANUF", "icio2023", remove_letter = TRUE)
# Get sector codes for manufactures in the icio2023 database. get_sec_codes("MANUF", "icio2023") # Get sector codes for services (including construction) get_sec_codes("SRVWC", "icio2023") # Get sector codes for manufacturing, removing the first letter so # the result can be used with `grep` to select specific sectors from # a matrix get_sec_codes("MANUF", "icio2023", remove_letter = TRUE)
Origin of value added in gross exports. It combines a
make_exvadir()
command and a get_data()
command to obtain
a result equivalent to the OECD's Origin of Value added in Gross Exports
EXGR_BSCI
, but with much more flexible geographical and sector options.
get_va_exgr( wio_object, va_type = "FC", geo_orig = "WLD", sec_orig = "TOTAL", geo_export, sec_export = "TOTAL", as_numeric = TRUE )
get_va_exgr( wio_object, va_type = "FC", geo_orig = "WLD", sec_orig = "TOTAL", geo_export, sec_export = "TOTAL", as_numeric = TRUE )
wio_object |
An object of class |
va_type |
Character string specifying the output as domestic
content ( |
geo_orig |
Character string with code of country or country group of origin of value added |
sec_orig |
Character string with code of sector or sector group
of origin of value added. Combinations (with |
geo_export |
Character string with code of exporting country or country group. |
sec_export |
Character string with code of exporting sector or
sector group. Combinations (with |
as_numeric |
Boolean specifying whether to return a numeric value or
matrix ( |
A matrix, vector or data frame with export value added data.
wio <- make_wio("iciotest") # Exports of manufactures of Spain using foreign VA from France get_va_exgr(wio, "FC", "FRA", "TOTAL", "ESP", "MANUF")
wio <- make_wio("iciotest") # Exports of manufactures of Spain using foreign VA from France get_va_exgr(wio, "FC", "FRA", "TOTAL", "ESP", "MANUF")
Get exports in terms of final absorption by origin of
value added and final destination. It combines a make_exvadir()
command and a get_data()
command to obtain a result equivalent to
that of the OECD's Gross Exports by Origin of Value Added and
Final destination (FD_EXGR_VA
, FD_EXGRFNL_VA
and FD_EXGRINT_VA
),
but with much more flexible geographical and sector options.
get_va_exgry( wio_object, va_type = "TC", flow_type = "EXGRY", geo_orig = "WLD", geo_export, sec_export = "TOTAL", geo_fd = "WLD", as_numeric = TRUE )
get_va_exgry( wio_object, va_type = "TC", flow_type = "EXGRY", geo_orig = "WLD", geo_export, sec_export = "TOTAL", geo_fd = "WLD", as_numeric = TRUE )
wio_object |
An object of class |
va_type |
String for domestic content ( |
flow_type |
String specifying the type of flow in terms of absorption.
It can be total gross exports ( |
geo_orig |
Character string with code of country or country group of origin of value added. |
geo_export |
Character string with code of exporting country or country group. |
sec_export |
Character string with code of exporting sector or
sector group. Combinations (with |
geo_fd |
String character with code of country or country group of final destination of exports |
as_numeric |
Boolean. If |
A matrix, vector or data frame with data of exports
# What part of French value added exported as US final intermediate # manufactures ends up absorbed by Spain? wio <- make_wio("iciotest") get_va_exgry(wio, flow_type = "EXGRY_INT", geo_orig = "FRA", geo_export = "USA", sec_export = "MANUF", geo_fd = "ESP")
# What part of French value added exported as US final intermediate # manufactures ends up absorbed by Spain? wio <- make_wio("iciotest") get_va_exgry(wio, flow_type = "EXGRY_INT", geo_orig = "FRA", geo_export = "USA", sec_export = "MANUF", geo_fd = "ESP")
Details of both geographical and sector origin of the
VA incorporated in exports induced by final demand. Equivalent to the
OECD's Origin of Value added in Final Demand (FDVA_BSCI
), but with much
more flexible geographical and sector options.
get_va_fd( wio_object, va_type = "TOTAL", geo_orig = "WLD", sec_orig = "TOTAL", geo_fd = "WLD", sec_fd = "TOTAL", intra = FALSE )
get_va_fd( wio_object, va_type = "TOTAL", geo_orig = "WLD", sec_orig = "TOTAL", geo_fd = "WLD", sec_fd = "TOTAL", intra = FALSE )
wio_object |
A |
va_type |
String character with the type of VA induced (VA domestically
absorbed |
geo_orig |
String character with code of country or country group
generating value added, i.e., exporter. Default is |
sec_orig |
String character with code of sector or sector group
generating value added. Default: |
geo_fd |
String character with code of country (or country group) of final demand (inducing the generation of VA) |
sec_fd |
String character with code of sector (or sector group) of final demand (inducing the generation of VA) |
intra |
Boolean for inclusion of intra-regional exports
(default: |
Matrix with source and destination of value added.
wio <- make_wio("iciotest") # Get USA's total VA in services induced by China's manufacturing get_va_fd(wio, geo_orig = "USA", sec_orig = "SRVWC", geo_fd = "CHN", sec_fd = "MANUF") # Get world VA exported (VAX), i.e., world VA induced by the rest of # the world not domestically absorbed get_va_fd(wio, "VAX", "WLD", "TOTAL", "WLD", "TOTAL")
wio <- make_wio("iciotest") # Get USA's total VA in services induced by China's manufacturing get_va_fd(wio, geo_orig = "USA", sec_orig = "SRVWC", geo_fd = "CHN", sec_fd = "MANUF") # Get world VA exported (VAX), i.e., world VA induced by the rest of # the world not domestically absorbed get_va_fd(wio, "VAX", "WLD", "TOTAL", "WLD", "TOTAL")
Creates a global extraction matrix Anots
of an exporter and its inverse
Bnots
.
get_xmatrix( wio, exporter, perim = "country", partner = "WLD", sector = "TOTAL", inverse = TRUE )
get_xmatrix( wio, exporter, perim = "country", partner = "WLD", sector = "TOTAL", inverse = TRUE )
wio |
A class |
exporter |
String, code of country or country group |
perim |
String: |
partner |
String: code of country or country group for bilateral perspectives (only with country). |
sector |
Character string: code of sector or sector group for sector perspectives (only with country). |
inverse |
Boolean, if |
The global (inverse) extraction matrix of the specified exporter.
Hadamard product, i.e., element by element product of matrix df1
and matrix df2
(by blocks). Both matrices must be block matrices, and the
number and dimension of blocks in matrix df1
and df2
must be
compatible.
hmult(df1, df2)
hmult(df1, df2)
df1 |
A block matrix with named rows and columns (country/sector) |
df2 |
A block matrix with named rows and columns (country/sector) |
In a Hadamard product, matrices are multiplied block by block,
i.e., block (s,r) %*% block(s,r)
.
Hadamard product of the two matrices.
An example of an ICIO-type input-output table, with rows for MEX
and CHN
disaggregated into MX1
and MX2
and CN1
and CN2
, respectively.
iciotest_data
iciotest_data
A matrix of 30 by 42, composed of two sub-matrices:
Sub-matrix Z
, intermediate inputs: 30 by 30 (10 countries with 3
sectors each). 4 of those 10 are the extensions of CHN
and MEX
).
Sub-matrix Yfd
, final demand: 30 by 12 (10 countries with 3 sectors
each in rows, 6 countries by 2 demand components each in columns).
Data were randomly generated with an uniform distribution.
Show available countries and country groups in a specific Input-Output table
info_geo(wiotype = "icio2023", lang = "en")
info_geo(wiotype = "icio2023", lang = "en")
wiotype |
Character string specifying the world input-output database. |
lang |
Character string for the language of the descriptive text:
|
Prints country codes and descriptive text in the console.
info_geo("icio2023")
info_geo("icio2023")
Show available sectors and sector groups included in a specific Input-Output table
info_sec(wiotype = "icio2023", lang = "en")
info_sec(wiotype = "icio2023", lang = "en")
wiotype |
Character string specifying the world input-output database |
lang |
Character string for the language of the descriptive text:
|
Prints ids, sector codes and descriptive text
info_sec("icio2023")
info_sec("icio2023")
Creates a list object of class wio
containing the typical
international input-output matrices in a standardized format, as well as a
list of code names (countries, sectors and demand components) and a list
of dimensions (number of countries, sectors and demand components), using
custom data.
make_custom_wio( df, g_names, n_names = NULL, fd_names = NULL, year = NULL, quiet = FALSE )
make_custom_wio( df, g_names, n_names = NULL, fd_names = NULL, year = NULL, quiet = FALSE )
df |
A data frame or matrix containing data for intermediate inputs and final demand. |
g_names |
A string vector with names of countries. |
n_names |
A string vector with names of sectors. If missing, sectors
will be |
fd_names |
A string vector with names of final demand components.
If missing, demand components will be |
year |
Integer. If missing, the current year will be used. |
quiet |
Boolean, if |
make_custom_wio()
creates a wio
from custom input-output data provided
as a single matrix of dimension GxN x GxFD
, i.e., the matrix Z
of
intermediate inputs (dimension GxN x GxN
) bound with the matrix Yfd
of
final demand (dimension GxN x GxFD
). The matrices of total output X
and
value added VA
will be automatically generated, so should not be
included. Data must be exclusively numeric.
A string vector with the names of countries is required. Number of countries will be calculated from this vector. Names for sectors and final demand components can be provided or will otherwise be automatically generated. All names must be composed of alphabetic characters (no special characters are allowed).
A wio
object of wiotype = "custom"
.
df <- as.data.frame(matrix(c(19:36), nrow = 3)) wio <- make_custom_wio(df, g_names = c("C01", "C02", "C03"))
df <- as.data.frame(matrix(c(19:36), nrow = 3)) wio <- make_custom_wio(df, g_names = c("C01", "C02", "C03"))
Calculates the decomposition of value added in exports of a country or a group of countries according to different methodologies.
make_exvadec( wio_object, exporter = "all", method = "bm_src", output = "standard", quiet = FALSE, ... )
make_exvadec( wio_object, exporter = "all", method = "bm_src", output = "standard", quiet = FALSE, ... )
wio_object |
An object of class |
exporter |
String with a country or a country group code
(e.g., |
method |
A string specifying the export VA decomposition method:
|
output |
Type of matrices in output:
|
quiet |
Boolean, if |
... |
Additional parameters for targeted value-added perspectives
and for sector breakdown. Targeted value-added perspectives are only
available for the
|
A list object of class exvadec
with several matrices
plus metadata.
Borin, A., & Mancini, M. (2023). Measuring What Matters in Value-Added Trade. Economic Systems Research, 1-25.
Koopman, R., Wang, Z., & Wei, S.-J. (2014). Tracing Value-Added and Double Counting in Gross Exports. American Economic Review, 104(2), 459–494.
Miroudot, S., & Ye, M. (2021). Decomposing Value Added in Gross Exports. Economic Systems Research, 33(1), 67–87.
Wang, Z., Wei, S.-J., & Zhu, K. (2013). Quantifying International Production Sharing at the Bilateral and Sector Levels (NBER Working Paper No. 19677). National Bureau of Economic Research, Inc.
# Create a test wio wio <- make_wio("iciotest") # Make Borin and Mancini (2023) source decomposition for Spain exvadec <- make_exvadec(wio, exporter = "ESP", method = "bm_src") # Make Wang et al. (2013) decomposition for all countries # expressed in the traditional 16 terms exvadec <- make_exvadec(wio, method = "wwz", output = "terms")
# Create a test wio wio <- make_wio("iciotest") # Make Borin and Mancini (2023) source decomposition for Spain exvadec <- make_exvadec(wio, exporter = "ESP", method = "bm_src") # Make Wang et al. (2013) decomposition for all countries # expressed in the traditional 16 terms exvadec <- make_exvadec(wio, method = "wwz", output = "terms")
Direction of value added in exports, i.e., details of both geographical and sector origin of the VA incorporated in exports and of the final destination (in gross terms or in terms of final absorption).
make_exvadir( wio_object, exporter, va_type = "TC", flow_type = "EXGR", orig_geo = "all", sec_orig = "all", via = "any", perspective = "exporter", intra = FALSE )
make_exvadir( wio_object, exporter, va_type = "TC", flow_type = "EXGR", orig_geo = "all", sec_orig = "all", via = "any", perspective = "exporter", intra = FALSE )
wio_object |
A |
exporter |
Country code (or country group code) of exporting country |
va_type |
VA total content ( |
flow_type |
Gross exports ( |
orig_geo |
Geographical origin of value added (default: |
sec_orig |
Code of sector of origin of value added (default: |
via |
Code of intermediate importing country (default: |
perspective |
Sector perspective, |
intra |
Boolean for inclusion of intra-regional exports
(default: |
Matrix with source and destination of value added in exports
wio <- make_wio("wiodtest", quiet = TRUE) # Foreign services content of value added incorporated in exports of Spain, # by country of origin and final destination, expressed in gross terms # (equivalent to OECD TiVA’s indicator EXGR_SERV_FVA). exvadir <- make_exvadir(wio, va = "FC", flow="EXGR", exp="ESP", sec_orig="SRVWC") summary(exvadir)
wio <- make_wio("wiodtest", quiet = TRUE) # Foreign services content of value added incorporated in exports of Spain, # by country of origin and final destination, expressed in gross terms # (equivalent to OECD TiVA’s indicator EXGR_SERV_FVA). exvadir <- make_exvadir(wio, va = "FC", flow="EXGR", exp="ESP", sec_orig="SRVWC") summary(exvadir)
Creates a list object of class wio
containing the typical
international input-output matrices in a standardized format, as well as a
list of code names (countries, sectors and demand components) and a list
of dimensions (number of countries, sectors and demand components). It
can use source files from well-known databases or internal data (test
data).
make_wio(wiotype = "icio2023", year = NULL, src_dir = NULL, quiet = FALSE)
make_wio(wiotype = "icio2023", year = NULL, src_dir = NULL, quiet = FALSE)
wiotype |
String specifying the name and edition of the
input-output tables to be used:
* |
year |
Integer specifying reference year. If |
src_dir |
String specifying the source directory where the source file
of the international input-output tables is saved, normally as a zip file
(containing |
quiet |
Boolean, if |
make_wio()
directly unzips and processes the original source files
for the different international input-output tables and returns a list
with the traditional matrices, including the coefficient matrix A
, the
Leontief global inverse matrix B
, the Leontief matrix of local inverse
matrices Ld
and others.
Original source files can be obtained from the OECD's ICIO web page, the University of Groningen's WIOD web page, the Eurostat web page or the Asian Development Bank MRIO web page
If source files are used, they must be previously downloaded and placed in an accessible folder in disk, without renaming them. The following name pattern is expected:
XXXX-XXXX.zip
for "icio2023"
(.csv
files)
XXXX-XXXX_SML.zip
for "icio2023s"
(.csv
files)
ICIO_XXXX-XXXX.zip
for "icio2021"
(.csv
files)
ICIO2018_XXXX.zip
for "icio2018"
(.csv
files)
ICIO2016_XXXX.zip
for "icio2016"
(.csv
files)
WIOTS_in_R.zip
for "wiod2016"
(.RData
files)
WIOTS_in_EXCEL.zip
for "wiod2013"
(.xlsx
files). Requires
package openxlsx
.
lr_wiod_wiot_final_filled.csv
for "lrwiod2022"
. Requires
packages data.table
and reshape2
.
matrix_eu-ic-io_ind-by-ind_2Xed_XXXX.csv
for "figaro202Xi
and
matrix_eu-ic-io_prod-by-prod_2Xed_XXXX.csv
for "figaro202Xp
(.csv
files).
ADB-MRIO[XX]-XXXX_xxx2023.xlsx
for the "mrio62-202X"
, "mrio72-202X"
and ADB MRIO XXXX, at constant 2010 prices.xlsx
for the
"mrio62-202Xk"
tables (with some exceptions).
The input-output framework follows the traditional demand model of Leontief (1936), which makes assumptions about the stability of inputs (and therefore value-added) as a proportion of production. This allows production and value-added to be expressed as the result of variations in final demand.
Details about the content of the world input-output object (wio
)
produced by make_wio()
can be obtained with the command
summary(wio_object)
.
A list object of class wio
including input-output
matrices, dimensions, and names.
wio <- make_wio("iciotest") summary(wio) ## Not run: # The following examples require the previous download of the source # files in the working directory or in a directory specified by `src_dir`. wio <- make_wio("icio2023", 2020) wio <- make_wio("wiod2021", 2018) wio <- make_wio("wiod2023", 2020, src_dir = "C:/Users/John/R/") ## End(Not run)
wio <- make_wio("iciotest") summary(wio) ## Not run: # The following examples require the previous download of the source # files in the working directory or in a directory specified by `src_dir`. wio <- make_wio("icio2023", 2020) wio <- make_wio("wiod2021", 2018) wio <- make_wio("wiod2023", 2020, src_dir = "C:/Users/John/R/") ## End(Not run)
Meld ICIO
matrix with extended countries.
Melds countries CHN
and MEX
from their extended versions
e.g., CN1
and CN2
are melded into CHN
.
meld(df, meld_rows = TRUE, meld_cols = TRUE)
meld(df, meld_rows = TRUE, meld_cols = TRUE)
df |
A block matrix. |
meld_rows |
Boolean, true to meld rows. |
meld_cols |
Boolean, true to meld cols. |
Melded version of ICIO
matrix.
Fast multiplication of a matrix by a diagonal matrix, taking advantage of the properties of diagonal matrices.
multd(matrix1, matrix2)
multd(matrix1, matrix2)
matrix1 |
An ordinary matrix. |
matrix2 |
A diagonal matrix. |
multd()
will turn matrix2
into a vector and multiply it
horizontally by every row in matrix1
. This saves precious computing
time.\
The number of columns of matrix1
must be equal to the rows and
columns of diagonal matrix2
.
The product of matrix1 and matrix2.
wio <- make_wio("wiodtest") multd(wio$B, wio$E)
wio <- make_wio("wiodtest") multd(wio$B, wio$E)
exvadec
classPrint method for exvadec
class
## S3 method for class 'exvadec' print(x, ...)
## S3 method for class 'exvadec' print(x, ...)
x |
An object of class |
... |
Additional arguments |
Printout to console
exvadir
classPrint method for exvadir
class
## S3 method for class 'exvadir' print(x, ...)
## S3 method for class 'exvadir' print(x, ...)
x |
An object of class |
... |
Additional arguments |
Printout to console
wio
classPrint method for wio
class
## S3 method for class 'wio' print(x, ...)
## S3 method for class 'wio' print(x, ...)
x |
An object of class |
... |
Additional arguments |
Printout to console
Improved version of rowSums()
for matrix output. The sum of rows is kept
as a column vector with rows names and the resulting column can be
named in the same command.
rsums(df, col_name = NULL)
rsums(df, col_name = NULL)
df |
A matrix with named rows and columns. |
col_name |
String, name to assign to resulting column. |
A column matrix (with rows and column names)
wio <- make_wio("wiodtest", quiet = TRUE) rsums(wio$Y, "Y")
wio <- make_wio("wiodtest", quiet = TRUE) rsums(wio$Y, "Y")
Sets to zero specific rows and columns of a matrix, to include and exclude specific geographical and sector effects.
set_zero(df, orig = NULL, dest = NULL, wiotype = NULL, invert = FALSE)
set_zero(df, orig = NULL, dest = NULL, wiotype = NULL, invert = FALSE)
df |
A matrix with named rows and columns. |
orig |
A vector of integers with position of rows or a list of strings with codes of country and sector of origin. |
dest |
A vector of integers with position of columns or a list of strings with codes of country and sector of destination. |
wiotype |
String, type of |
invert |
Boolean: FALSE (default) to set to zero the specified countries and sectors, or TRUE to set to zero the non-specified countries and sectors. |
The same matrix with specific rows and columns set to zero.
wio <- make_wio("wiodtest") # Set to zero Spanish exports of intermediates of manufacturing to # non EU27 countries (for any sector of destination) in the coefficient # matrix A set_zero(wio$A, list("ESP", "MANUF"), list("NONEU27", "TOTAL"), "wiodtest") # Set to zero Spanish exports of intermediates (extraction matrix of Spain) set_zero(wio$A, list("ESP", "TOTAL"), list("WLDxESP", "TOTAL"), "wiodtest")
wio <- make_wio("wiodtest") # Set to zero Spanish exports of intermediates of manufacturing to # non EU27 countries (for any sector of destination) in the coefficient # matrix A set_zero(wio$A, list("ESP", "MANUF"), list("NONEU27", "TOTAL"), "wiodtest") # Set to zero Spanish exports of intermediates (extraction matrix of Spain) set_zero(wio$A, list("ESP", "TOTAL"), list("WLDxESP", "TOTAL"), "wiodtest")
Groups a matrix by columns, by summing blocks of columns of size n each. Matrix columns should be multiple of n.
sumgcols(df, n, col_names = NULL)
sumgcols(df, n, col_names = NULL)
df |
A matrix with named rows and columns. |
n |
Integer, specifying the size of each group. |
col_names |
String vector of length n, with names to assign to the resulting columns. |
A matrix where each column is the sum of groups of n columns of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) sumgcols(wio$Yfd, wio$dims$FD, wio$names$g_names)
wio <- make_wio("wiodtest", quiet = TRUE) sumgcols(wio$Yfd, wio$dims$FD, wio$names$g_names)
Groups a matrix by rows, summing blocks of rows of size n each. Matrix rows should be multiple of n.
sumgrows(df, n, row_names = NULL)
sumgrows(df, n, row_names = NULL)
df |
A matrix with named rows and columns. |
n |
Integer, specifying the size of each group. |
row_names |
String vector of length n, with names to assign to the resulting rows. |
A matrix where each row is the sum of groups of n rows of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) sumgrows(wio$Y, wio$dims$N, wio$names$g_names)
wio <- make_wio("wiodtest", quiet = TRUE) sumgrows(wio$Y, wio$dims$N, wio$names$g_names)
exvadec
classSummary method for exvadec
class
## S3 method for class 'exvadec' summary(object, ...)
## S3 method for class 'exvadec' summary(object, ...)
object |
An object of class |
... |
Additional arguments. |
Printout to console
exvadir
classSummary method for exvadir
class
## S3 method for class 'exvadir' summary(object, ...)
## S3 method for class 'exvadir' summary(object, ...)
object |
An object of class |
... |
Additional arguments. |
Printout to console
wio
classSummary method for wio
class
## S3 method for class 'wio' summary(object, ...)
## S3 method for class 'wio' summary(object, ...)
object |
An object of class |
... |
Additional arguments |
Printout to console
Groups a matrix by columns, summing every Nth column. Matrix should be multiple of N.
sumncol(df, N, col_names = NULL)
sumncol(df, N, col_names = NULL)
df |
A matrix with named rows and columns. |
N |
Integer, specifying the resulting number of columns. |
col_names |
String vector of length N, with names to assign to the resulting columns. |
A matrix with N columns, where each columns is the sum of every Nth column of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) sumncol(wio$Yfd, wio$dims$FD, paste0("WLD", "_", wio$names$fd_names))
wio <- make_wio("wiodtest", quiet = TRUE) sumncol(wio$Yfd, wio$dims$FD, paste0("WLD", "_", wio$names$fd_names))
Groups a matrix by rows, summing every Nth
row. Matrix should be multiple
of N
.
sumnrow(df, N, row_names = NULL)
sumnrow(df, N, row_names = NULL)
df |
A matrix with named rows and columns. |
N |
Integer, specifying the resulting number or rows. |
row_names |
String vector of length |
A matrix with N
rows, where each row is the sum of every Nth
row
of the original matrix.
wio <- make_wio("wiodtest", quiet = TRUE) sumnrow(wio$Y, wio$dims$N, paste0("WLD", "_", gsub("^D", "", wio$names$n_names)))
wio <- make_wio("wiodtest", quiet = TRUE) sumnrow(wio$Y, wio$dims$N, paste0("WLD", "_", gsub("^D", "", wio$names$n_names)))
An example of a WIOD-type input-output table.
wiodtest_data
wiodtest_data
A matrix of 18 by 30, composed of two sub-matrices:
Sub-matrix Z
, intermediate inputs: 18 by 18 (10 countries with 3
sectors each).
Sub-matrix Yfd
, final demand: 18 by 12 (6 countries with 3 sectors
each in rows, 6 countries by 2 demand components each in columns).
Data were randomly generated with an uniform distribution.