library(iotables)
library(dplyr, quietly = TRUE)
library(tidyr, quietly = TRUE)
library(testthat, quietly = TRUE)
#>
#> Attaching package: 'testthat'
#> The following object is masked from 'package:tidyr':
#>
#> matches
#> The following object is masked from 'package:dplyr':
#>
#> matches
The United Kingdom Input-Output Analytical Tables 2010 are used for testing the iotables
package, because they are well-documented and detailed, organized data is available with them. The analytical tables are published in an Excel table. A special reader function (which is not exported) was created to read-in all sheets of the Excel table.
It is unlikely that these tables will be required by other purposes than controlling the package. The UK IO tables for other years are available these are consistent with different Blue Books and there could therefore be important methodological and classification changes. Furthermore, ONS currently publishes ESA2010 compatible SIOTs with analytical tables annually.
<- iotables_download ( source = "uk_2010" )
uk_2010_data save ( uk_2010_data, file = file.path('data-raw', 'uk_2010_data.rda'))
<- iotables:::uk_2010_results_get()
uk_test_results #saved as package data
For the actual symmetric input-output table (see ) you can use the download function originally designed for the Eurostat bulk downloader.
<- iotable_get (labelled_io_data = uk_2010_data,
uk_siot source = "uk_2010_siot")
<- iotable_get (labelled_io_data = uk_2010_data,
uk_published_coeff source = "uk_2010_siot")
<- iotable_get (labelled_io_data = uk_2010_data,
uk_published_inverse source = "uk_2010_siot")
The matrix of coefficients is described on page 14-15 and the data can be found in the Matrix of coefficients (product by product) sheet of the Excel file.
<- input_coefficient_matrix_create(data_table = uk_siot)
uk_input_coeff
<- select (uk_input_coeff, 1 ) %>%
uk_coeff_published left_join ( iotable_get ( labelled_io_data = uk_2010_data,
source = "uk_2010_coeff" ) %>%
mutate ( across(where(is.factor), as.character)),
by = "prod_na")
test_that("correct data is returned", {
expect_equal(round(uk_input_coeff[,2:8], 8),
round(uk_coeff_published [,2:8], 8)) })
#> Test passed
Comparing the first 7 columns of the two coefficient matrixes at 8 decimal point precision they are equal. Given the size of the matrixes, not all the matrix is compared here, but such a comparison can be made. However, it is not necessary, because the latter results would show a deviation if parts of the matrix would be different.
The Leontieff-inverse is described on pages 16-17 of the article. Again, comparing the first seven numerical columns with 8-digits precision we see that the re-calculated inverse and the published inverse is the same.
<- leontieff_inverse_create(uk_input_coeff)
uk_calculated_inverse <- select (uk_calculated_inverse, 1 ) %>%
uk_published_inverse left_join ( iotable_get ( labelled_io_data = uk_2010_data,
source = "uk_2010_inverse" ) %>%
mutate ( across(where(is.factor), as.character)),
by = "prod_na")
test_that("correct data is returned", {
expect_equal(round(uk_calculated_inverse[,2:8], 8),
round(uk_published_inverse [,2:8], 8)) })
#> Test passed
<- uk_test_results %>%
employment_effect_results select ( .data$uk_row_label, .data$`Employment cost effects`)
<- coefficient_matrix_create(
primary_inputs_uk data_table = uk_siot,
total = 'output',
return_part = 'primary_inputs')
<- filter (primary_inputs_uk , .data$prod_na == "D1")
employment_input
<- direct_effects_create( employment_input, uk_calculated_inverse) %>%
employment_effects pivot_longer( -all_of("prod_na"), names_to = "prod" ) %>%
mutate ( prod_na = .data$prod ) %>%
select ( -.data$prod ) %>%
left_join ( metadata_uk_2010 %>%
select (all_of(c("prod_na", "uk_row_label"))),
by = "prod_na") %>%
left_join ( employment_effect_results, by = 'uk_row_label') %>%
filter ( !is.na(uk_row_label )) %>%
relocate ( .data$value, .after = .data$uk_row_label )
:::create_knitr_table (
iotablesdata_table = employment_effects[1:10,],
digits = 4,
caption = "Comparison of Calculated And Published Employment Cost Effects",
col.names = c("industry code", "row label", "calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 0,3682 | 0,3682 |
CPA_02 | Products of forestry, logging and related services | 0,4683 | 0,4683 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 0,2234 | 0,2234 |
CPA_05 | Coal and lignite | 0,4644 | 0,4644 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 0,1657 | 0,1657 |
CPA_08 | Other mining and quarrying products | 0,4305 | 0,4305 |
CPA_09 | Mining support services | 0,1993 | 0,1993 |
CPA_10_1 | Preserved meat and meat products | 0,4776 | 0,4776 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 0,5301 | 0,5301 |
CPA_10_4 | Vegetable and animal oils and fats | 0,3786 | 0,3786 |
The comparison of output mulitipliers show that our code gives the same results. Only ten industries are shown.
GVA is not shown in the Excel table explicitly, but can be calculated as the sum of corporate income (Operating surplus and mixed income), household income (Compensation of employees) and net taxes on production (not products.)
<- uk_siot %>%
uk_siot2 filter (.data$prod_na %in% c("B2A3G", "D1", "D29X39")) %>%
summarise ( across(where(is.numeric), sum, na.rm = TRUE) ) %>%
cbind ( data.frame ( prod_na = "GVA"), . ) %>%
rbind ( uk_siot, .)
<- uk_test_results %>%
gva_effect_results select ( .data$uk_row_label, .data$`GVA effects`)
<- coefficient_matrix_create(
gva_input data_table = uk_siot2,
total = 'output',
return_part = 'primary_inputs') %>%
filter ( prod_na == "GVA" )
<- direct_effects_create( gva_input, uk_calculated_inverse ) %>%
gva_effects pivot_longer( -all_of("prod_na"), names_to = "prod" ) %>%
mutate ( prod_na = .data$prod ) %>%
select ( -.data$prod ) %>%
left_join ( metadata_uk_2010 %>%
select (all_of(c("prod_na", "uk_row_label"))),
by = "prod_na") %>%
left_join ( gva_effect_results, by = 'uk_row_label' ) %>%
filter ( !is.na(uk_row_label )) %>%
relocate ( .data$value, .after = .data$uk_row_label )
:::create_knitr_table (
iotablesdata_table = gva_effects[1:10,],
digits = 4,
caption = "Comparison of Calculated And Published GVA Effects",
col.names = c("industry code", "row label", "calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 0,6910 | 0,6910 |
CPA_02 | Products of forestry, logging and related services | 0,7472 | 0,7472 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 0,7076 | 0,7076 |
CPA_05 | Coal and lignite | 0,6631 | 0,6631 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 0,9048 | 0,9048 |
CPA_08 | Other mining and quarrying products | 0,7193 | 0,7193 |
CPA_09 | Mining support services | 0,8963 | 0,8963 |
CPA_10_1 | Preserved meat and meat products | 0,6751 | 0,6751 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 0,7251 | 0,7251 |
CPA_10_4 | Vegetable and animal oils and fats | 0,5628 | 0,5628 |
Turning to multipliers, using the same inputs we get them back with the following code.
<- uk_test_results %>%
empc_multiplier_results select ( .data$uk_row_label, .data$`Employment cost multiplier`)
<- coefficient_matrix_create(
empc_indicator_uk data_table = uk_siot,
total = 'output',
return_part = 'primary_inputs') %>%
filter ( prod_na == 'D1')
<- input_multipliers_create(
empc_multipliers input_requirements = empc_indicator_uk,
%>%
uk_calculated_inverse) pivot_longer( -all_of("prod_na"), names_to = "prod" ) %>%
mutate ( prod_na = .data$prod ) %>%
select ( -.data$prod ) %>%
left_join ( metadata_uk_2010 %>%
select (all_of(c("prod_na", "uk_row_label"))),
by = "prod_na") %>%
left_join ( empc_multiplier_results, by = 'uk_row_label' ) %>%
filter ( !is.na(uk_row_label )) %>%
relocate ( .data$value, .after = .data$uk_row_label )
:::create_knitr_table (
iotablesdata_table = empc_multipliers [1:10,], digits = 4,
caption = "Comparison of Calculated And Published Employment Cost Multipliers",
col.names = c("industry code", "row label", "calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 2,1111 | 2,1111 |
CPA_02 | Products of forestry, logging and related services | 2,3892 | 2,3892 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 2,7088 | 2,7088 |
CPA_05 | Coal and lignite | 1,6419 | 1,6419 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 2,2748 | 2,2748 |
CPA_08 | Other mining and quarrying products | 1,4642 | 1,4642 |
CPA_09 | Mining support services | 3,3424 | 3,3424 |
CPA_10_1 | Preserved meat and meat products | 2,4978 | 2,4978 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 1,8343 | 1,8343 |
CPA_10_4 | Vegetable and animal oils and fats | 1,6153 | 1,6153 |
Following from the GVA effects, after summarizing GVA and adding it to the input requirements we can calculate the GVA multipliers
.
<- input_multipliers_create(
gva_multipliers input_requirements = gva_input,
%>%
uk_calculated_inverse) pivot_longer( -all_of("prod_na"), names_to = "prod" ) %>%
mutate ( prod_na = .data$prod ) %>%
select ( -.data$prod ) %>%
left_join ( metadata_uk_2010 %>%
select (all_of(c("prod_na", "uk_row_label"))),
by = "prod_na") %>%
left_join ( uk_test_results %>%
select ( .data$uk_row_label, .data$`GVA multiplier`), by = 'uk_row_label' ) %>%
filter ( !is.na(uk_row_label )) %>%
relocate ( .data$value, .after = .data$uk_row_label )
:::create_knitr_table (
iotablesdata_table = gva_multipliers [1:10,], digits = 4,
caption = "Comparison of Calculated And Published GVA Multipliers",
col.names = c("industry code", "row label", "calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 1,8838 | 1,8838 |
CPA_02 | Products of forestry, logging and related services | 2,4077 | 2,4077 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 1,5424 | 1,5424 |
CPA_05 | Coal and lignite | 1,8369 | 1,8369 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 1,3203 | 1,3203 |
CPA_08 | Other mining and quarrying products | 1,4682 | 1,4682 |
CPA_09 | Mining support services | 1,4679 | 1,4679 |
CPA_10_1 | Preserved meat and meat products | 3,1429 | 3,1429 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 2,1627 | 2,1627 |
CPA_10_4 | Vegetable and animal oils and fats | 1,7390 | 1,7390 |
:::create_knitr_table (
iotablesdata_table = gva_multipliers [1:10,],
digits = 4,
caption = "Comparison of Calculated And Published GVA Multipliers",
col.names = c("industry code", "row label",
"calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 1,8838 | 1,8838 |
CPA_02 | Products of forestry, logging and related services | 2,4077 | 2,4077 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 1,5424 | 1,5424 |
CPA_05 | Coal and lignite | 1,8369 | 1,8369 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 1,3203 | 1,3203 |
CPA_08 | Other mining and quarrying products | 1,4682 | 1,4682 |
CPA_09 | Mining support services | 1,4679 | 1,4679 |
CPA_10_1 | Preserved meat and meat products | 3,1429 | 3,1429 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 2,1627 | 2,1627 |
CPA_10_4 | Vegetable and animal oils and fats | 1,7390 | 1,7390 |
At last, the comparison of output mulitipliers show that our code gives the same results. Only ten industries are shown.
<- output_multiplier_create(uk_input_coeff) %>%
uk_output_multipliers pivot_longer( -all_of("prod_na"), names_to = "prod" ) %>%
mutate ( prod_na = .data$prod ) %>%
select ( -.data$prod ) %>%
left_join ( metadata_uk_2010 %>%
select (all_of(c("prod_na", "uk_row_label"))),
by = "prod_na") %>%
left_join ( uk_test_results %>%
select ( .data$uk_row_label, .data$`Output multiplier`), by = 'uk_row_label' ) %>%
filter ( !is.na(uk_row_label )) %>%
relocate ( .data$value, .after = .data$uk_row_label )
:::create_knitr_table (
iotablesdata_table = uk_output_multipliers [1:10,],
digits = 4,
caption = "Comparison of Calculated And Published Output Multipliers",
col.names = c("industry code", "row label",
"calculated", "published"),
col_width = c(2,11,3,3))
industry code | row label | calculated | published |
---|---|---|---|
CPA_01 | Products of agriculture, hunting and related services | 1,8312 | 1,8312 |
CPA_02 | Products of forestry, logging and related services | 2,1187 | 2,1187 |
CPA_03 | Fish and other fishing products; aquaculture products; support services to fishing | 1,6284 | 1,6284 |
CPA_05 | Coal and lignite | 1,7891 | 1,7891 |
CPA_06-07 | Crude petroleum and natural gas & Metal ores | 1,4155 | 1,4155 |
CPA_08 | Other mining and quarrying products | 1,5231 | 1,5231 |
CPA_09 | Mining support services | 1,5692 | 1,5692 |
CPA_10_1 | Preserved meat and meat products | 2,2693 | 2,2693 |
CPA_10_2-3 | Processed and preserved fish, crustaceans, molluscs, fruit and vegetables | 1,9499 | 1,9499 |
CPA_10_4 | Vegetable and animal oils and fats | 1,6088 | 1,6088 |