Internet access is basic infrastructure now, so I wanted to know whether countries that were behind in 2010 have been catching up. My question: do countries that started with low internet usage grow faster than countries that were already connected?
Data: World Bank indicator “Individuals using the Internet (% of population)” (IT.NET.USER.ZS), downloaded from https://datacatalog.worldbank.org/.
The World Bank CSV has four lines of header information before the
real column names, so I skipped those with skip = 4.
internet <- read_csv("API_IT.NET.USER.ZS_DS2_en_csv_v2_404267.csv", skip = 4)
metadata <- read_csv("Metadata_Country_API_IT.NET.USER.ZS_DS2_en_csv_v2_404267.csv")
names(internet)[1:6]
## [1] "Country Name" "Country Code" "Indicator Name" "Indicator Code"
## [5] "1960" "1961"
dim(internet)
## [1] 265 71
I only need the country name, the country code, and the two years I
am comparing. I used rename() from dplyr to give the year
columns names that are easier to type.
internet <- internet[, c("Country Name", "Country Code", "2010", "2022")]
internet <- rename(internet, country = `Country Name`, code = `Country Code`,
year2010 = `2010`, year2022 = `2022`)
head(internet)
## # A tibble: 6 × 4
## country code year2010 year2022
## <chr> <chr> <dbl> <dbl>
## 1 Aruba ABW 62 NA
## 2 Africa Eastern and Southern AFE 5.3 26.8
## 3 Afghanistan AFG 4 15.9
## 4 Africa Western and Central AFW 7.3 37.5
## 5 Angola AGO 2.80 35.8
## 6 Albania ALB 45 82.6
The raw file mixes aggregates like “World”, “Euro area” and “Low income” in with actual countries. The metadata file gives a Region for real countries and leaves it blank for aggregates, so I merged the two files on the country code and then dropped any row with a missing Region. I also dropped rows with missing values for either year.
metadata <- metadata[, c("Country Code", "Region")]
metadata <- rename(metadata, code = `Country Code`)
internet <- merge(internet, metadata, by = "code")
internet <- internet[!is.na(internet$Region) &
!is.na(internet$year2010) &
!is.na(internet$year2022), ]
dim(internet)
## [1] 178 5
To answer my question I need to group countries by where they started in 2010. I used a for loop with if / else statements to put each country into one of four tiers, then added that as a new column.
tier <- c()
for(i in 1:nrow(internet)){
x <- internet$year2010[i]
if(x < 15){
tier[i] <- "1. Under 15%"
} else if(x < 40){
tier[i] <- "2. 15 to 40%"
} else if(x < 70){
tier[i] <- "3. 40 to 70%"
} else {
tier[i] <- "4. Over 70%"
}
}
internet$tier <- tier
head(internet)
## code country year2010 year2022 Region
## 3 AFG Afghanistan 4.0 15.86630 Middle East & North Africa
## 5 AGO Angola 2.8 35.83800 Sub-Saharan Africa
## 6 ALB Albania 45.0 82.61368 Europe & Central Asia
## 7 AND Andorra 81.0 94.05170 Europe & Central Asia
## 9 ARE United Arab Emirates 68.0 100.00000 Middle East & North Africa
## 10 ARG Argentina 45.0 88.37536 Latin America & Caribbean
## tier
## 3 1. Under 15%
## 5 1. Under 15%
## 6 3. 40 to 70%
## 7 4. Over 70%
## 9 3. 40 to 70%
## 10 3. 40 to 70%
count(internet, tier)
## tier n
## 1 1. Under 15% 62
## 2 2. 15 to 40% 45
## 3 3. 40 to 70% 44
## 4 4. Over 70% 27
by_tier <- internet %>%
group_by(tier) %>%
summarize(countries = n(),
avg_2010 = round(mean(year2010), 1),
avg_2022 = round(mean(year2022), 1),
growth = round(mean(year2022) - mean(year2010), 1))
by_tier
## # A tibble: 4 × 5
## tier countries avg_2010 avg_2022 growth
## <chr> <int> <dbl> <dbl> <dbl>
## 1 1. Under 15% 62 5.8 42.8 37
## 2 2. 15 to 40% 45 27.6 76.9 49.3
## 3 3. 40 to 70% 44 53.4 87.3 33.9
## 4 4. Over 70% 27 80.9 94.1 13.2
I expected the countries starting under 15% to grow the most, since they had the most room. That is not what happened. Countries starting between 15 and 40% gained about 49 points, the most of any tier, while the bottom tier gained 37 and the top tier only 13.
The top tier makes sense because it was already near saturation. The bottom tier is the interesting one: having room to grow is not enough. It looks like adoption only speeds up once a country is past some baseline level of infrastructure.
by_region <- internet %>%
group_by(Region) %>%
summarize(countries = n(),
avg_2010 = round(mean(year2010), 1),
avg_2022 = round(mean(year2022), 1),
growth = round(mean(year2022) - mean(year2010), 1)) %>%
arrange(desc(growth))
by_region
## # A tibble: 7 × 5
## Region countries avg_2010 avg_2022 growth
## <chr> <int> <dbl> <dbl> <dbl>
## 1 South Asia 6 11 60.6 49.6
## 2 Middle East & North Africa 19 36.7 83.9 47.2
## 3 Latin America & Caribbean 33 33.5 74.3 40.7
## 4 East Asia & Pacific 24 35.2 75.5 40.3
## 5 Sub-Saharan Africa 44 7.2 38.4 31.2
## 6 Europe & Central Asia 50 58.9 87.9 29
## 7 North America 2 76 93.4 17.4
South Asia and the Middle East and North Africa grew the most. North America grew the least because it started at 76% and had nowhere to go. Sub-Saharan Africa started lowest at 7% and still only reached 38%, which is the same pattern as the bottom tier above.
I used gather() to reshape the summary table from wide
to long so that ggplot can map the year to the fill color, the same way
we reshaped the internet usage data in the lecture example.
tier_long <- by_tier %>%
select(tier, avg_2010, avg_2022) %>%
gather(avg_2010:avg_2022, key = "year", value = "usage")
tier_long$year <- ifelse(tier_long$year == "avg_2010", "2010", "2022")
ggplot(tier_long, aes(x = tier, y = usage, fill = year)) +
geom_col(position = "dodge") +
theme_few() +
labs(title = "Internet Usage by 2010 Starting Tier",
subtitle = "Countries in the middle tier closed the most ground by 2022",
x = "Internet usage in 2010",
y = "Average % of population using the internet",
caption = "Source: World Bank (IT.NET.USER.ZS)")