rename the time variable to “country” in the OECD dataframes scope_1_2, scope_2, and scope_3 and the variable “Country Name” to “Country” in the World Bank Datasets
#function to turn everything into ISO names country_regex_to_iso3c <-function(country_string) { country_string |> countrycode::countrycode(origin ="country.name", destination ="iso3c", origin_regex =TRUE)}#function which turns ISO names into Country names iso3c_to_country_name <-function(country_string) { country_string |> countrycode::countrycode(origin ="iso3c", destination ="country.name")} #unique OECD group values could be interesting. #Group values that exist in OECD Data but cannot be matched by functions: #ROW: Rest of the World#APEC: Asia-Pacific Economic Cooperation#ASEAN: Association of South East Asian Nations#EASIA: Eastern Asia#EU27_2020: European Union (27 countries)#EU28: European Union (28 countries)#EU15: European Union (15 countries)#EU13: EU28 excluding EU15#EA19: Euro area (19 countries)#G20: Group of Twenty#ZEUR: Europe#ZASI: East and Southeastern Asia#ZNAM: North America#ZSCA: South and Central America#ZOTH: Other regions#adjust country names in all the datasets and keep the original ones from the OECD Datascope_3 <- scope_3 |>mutate(Country =case_when(Country =="T¸rkiye"~"Turkey",TRUE~ Country)) |>mutate(iso3c =ifelse(is.na(country_regex_to_iso3c(Country)), Country, country_regex_to_iso3c(Country)),country_name =ifelse(is.na(iso3c_to_country_name(iso3c)), Country, iso3c_to_country_name(iso3c)))
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: APEC: Asia-Pacific Economic Cooperation, ASEAN: Association of South East Asian Nations, Data extracted on 09 Mar 2023 01:07 UTC (GMT) from OECD.Stat, EA19: Euro area (19 countries), EASIA: Eastern Asia, EU13: EU28 excluding EU15, EU15: European Union (15 countries), EU27_2020: European Union (27 countries), EU28: European Union (28 countries), G20: Group of Twenty, NONOECD: Non-OECD economies and aggregates, OECD: OECD member countries, ROW: Rest of the World, TUR: Türkiye, ZASI: East and Southeastern Asia, ZEUR: Europe, ZNAM: North America, ZOTH: Other regions, ZSCA: South and Central America
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: APEC: Asia-Pacific Economic Cooperation, ASEAN: Association of South East Asian Nations, Data extracted on 09 Mar 2023 00:56 UTC (GMT) from OECD.Stat, EA19: Euro area (19 countries), EASIA: Eastern Asia, EU13: EU28 excluding EU15, EU15: European Union (15 countries), EU27_2020: European Union (27 countries), EU28: European Union (28 countries), G20: Group of Twenty, NONOECD: Non-OECD economies and aggregates, OECD: OECD member countries, ROW: Rest of the World, TUR: Türkiye, ZASI: East and Southeastern Asia, ZEUR: Europe, ZNAM: North America, ZOTH: Other regions, ZSCA: South and Central America
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: APEC: Asia-Pacific Economic Cooperation, ASEAN: Association of South East Asian Nations, Data extracted on 09 Mar 2023 00:49 UTC (GMT) from OECD.Stat, EA19: Euro area (19 countries), EASIA: Eastern Asia, EU13: EU28 excluding EU15, EU15: European Union (15 countries), EU27_2020: European Union (27 countries), EU28: European Union (28 countries), G20: Group of Twenty, NONOECD: Non-OECD economies and aggregates, OECD: OECD member countries, ROW: Rest of the World, TUR: Türkiye, ZASI: East and Southeastern Asia, ZEUR: Europe, ZNAM: North America, ZOTH: Other regions, ZSCA: South and Central America
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
scope_1_1 <- scope_1_1 |>mutate(Country =case_when(Country =="T¸rkiye"~"Turkey", Country =="France and Monaco"~"France", Country =="Israel and Palestine, State of"~"Israel", Country =="Italy, San Marino and the Holy See"~"Italy", Country =="Serbia and Montenegro"~"Serbia", Country =="Spain and Andorra"~"Spain", Country =="Switzerland and Liechtenstein"~"Switzerland",TRUE~ Country)) |>mutate(iso3c =ifelse(is.na(country_regex_to_iso3c(Country)), Country, country_regex_to_iso3c(Country)),country_name =ifelse(is.na(iso3c_to_country_name(iso3c)), Country, iso3c_to_country_name(iso3c)))
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously: International Aviation, International Shipping
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
#rename the World Bank variables to "Country" instead of "Country Name" ppp_gdp <-ppp_gdp |>mutate(Country =case_when(Country =="Turkiye"~"Turkey", Country =="OECD members"~" OECD: OECD member countries", Country =="Euro area"~"EA19: Euro area (19 countries)",TRUE~ Country)) |>mutate(iso3c =ifelse(is.na(country_regex_to_iso3c(Country)), Country, country_regex_to_iso3c(Country)),country_name =ifelse(is.na(iso3c_to_country_name(iso3c)), Country, iso3c_to_country_name(iso3c)))
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously:
OECD: OECD member countries, Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Channel Islands, EA19: Euro area (19 countries), Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Kosovo, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
population <-population |>mutate(Country =case_when(Country =="Turkiye"~"Turkey", Country =="OECD members"~" OECD: OECD member countries", Country =="Euro area"~"EA19: Euro area (19 countries)",TRUE~ Country)) |>mutate(iso3c =ifelse(is.na(country_regex_to_iso3c(Country)), Country, country_regex_to_iso3c(Country)),country_name =ifelse(is.na(iso3c_to_country_name(iso3c)), Country, iso3c_to_country_name(iso3c)))
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously:
OECD: OECD member countries, Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Channel Islands, EA19: Euro area (19 countries), Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Kosovo, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
nominal_GDP <-nominal_GDP |>mutate(Country =case_when(Country =="Turkiye"~"Turkey", Country =="OECD members"~" OECD: OECD member countries", Country =="Euro area"~"EA19: Euro area (19 countries)",TRUE~ Country)) |>mutate(iso3c =ifelse(is.na(country_regex_to_iso3c(Country)), Country, country_regex_to_iso3c(Country)),country_name =ifelse(is.na(iso3c_to_country_name(iso3c)), Country, iso3c_to_country_name(iso3c)))
Warning: There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `iso3c = ifelse(is.na(country_regex_to_iso3c(Country)), Country,
country_regex_to_iso3c(Country))`.
Caused by warning in `countrycode_convert()`:
! Some values were not matched unambiguously:
OECD: OECD member countries, Africa Eastern and Southern, Africa Western and Central, Arab World, Caribbean small states, Central Europe and the Baltics, Channel Islands, EA19: Euro area (19 countries), Early-demographic dividend, East Asia & Pacific, East Asia & Pacific (excluding high income), East Asia & Pacific (IDA & IBRD countries), Europe & Central Asia, Europe & Central Asia (excluding high income), Europe & Central Asia (IDA & IBRD countries), European Union, Fragile and conflict affected situations, Heavily indebted poor countries (HIPC), High income, IBRD only, IDA & IBRD total, IDA blend, IDA only, IDA total, Kosovo, Late-demographic dividend, Latin America & Caribbean, Latin America & Caribbean (excluding high income), Latin America & the Caribbean (IDA & IBRD countries), Least developed countries: UN classification, Low & middle income, Low income, Lower middle income, Middle East & North Africa, Middle East & North Africa (excluding high income), Middle East & North Africa (IDA & IBRD countries), Middle income, North America, Not classified, Other small states, Pacific island small states, Post-demographic dividend, Pre-demographic dividend, Small states, South Asia, South Asia (IDA & IBRD), Sub-Saharan Africa, Sub-Saharan Africa (excluding high income), Sub-Saharan Africa (IDA & IBRD countries), Upper middle income, World
ℹ Run `dplyr::last_dplyr_warnings()` to see the 3 remaining warnings.
tidy the data (pivot longer, coerce all numbers into numeric form, select variables of interest)