Load the Libraries

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.4     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(knitr)

Read the Data

The data can be downloaded from this link

micro_world <- read_csv("micro_world.csv")
## Rows: 154923 Columns: 105
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr   (3): economy, economycode, regionwb
## dbl (102): pop_adult, wpid_random, wgt, female, age, educ, inc_q, emp_in, fi...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Overall Account Ownership

overall_account <- micro_world %>%
  group_by(economy) %>%
  summarise(account = round(weighted.mean(account, wgt) * 100))

# Print the first few lines of the table
head(overall_account)

Difference in Account Ownership by Gender

account_gap_female <-
  micro_world %>%
  group_by(economy, female) %>%    # Group data by economy and gender
  # Calculate % of account ownership
  summarise(account = 100 * weighted.mean(account, w = wgt)) %>%  
  # Format into wide format so that each country’s data is in a single row
  pivot_wider(id_cols = economy, 
              names_from = female,
              values_from = account) %>%
  # Rename columns
  rename(Male = `1` , Female = `2`) %>%
  # Calculate the difference in acount ownership between men and women
  mutate(gap_female = Male - Female) %>%
  # Select only the columns economy and gap_female
  select(economy, gap_female)
## `summarise()` has grouped output by 'economy'. You can override using the
## `.groups` argument.
head(account_gap_female)

Account Ownership for Different Income Groups

account_gap_inc <- 
  micro_world %>%
  # Create a new variable lower_inc 
  mutate(lower_inc = inc_q <= 2) %>% 
  group_by(economy, lower_inc) %>% 
  summarize(account = 100 * weighted.mean(account, w = wgt)) %>%
  pivot_wider(id_cols = economy, 
              names_from = lower_inc, 
              names_prefix = "lower_inc", 
              values_from = account) %>% 
  mutate(gap_inc = lower_incFALSE - lower_incTRUE) %>%
  select(economy, gap_inc)
## `summarise()` has grouped output by 'economy'. You can override using the
## `.groups` argument.
head(account_gap_inc)

Indicator Table

Create the indicator table by joining the above 3 tables (overall_account, account_gap_female, and account_gap_inc). Join by the variable economy.

indicator_table <- overall_account %>%
    full_join(account_gap_female, by = "economy") %>%
    full_join(account_gap_inc, by = join_by(economy)) %>%
    mutate(account = round(account), 
           gap_female = round(gap_female), 
           gap_inc = round(gap_inc))

The margin of error is used to assess if the gaps in income between the richer and the poorer are statistically significant. If the gap is less than the margin of error, then it is significant. However, if is gap is more than the margin of error, then it is not statistically significant, and is thus ignored (-)

moe <-
  micro_world %>%
  group_by(economy, pop_adult) %>%
  # Design effect is first estimated, then the moe
  summarize(design_effect = n() * sum(wgt^2) / (sum(wgt)^2),
            moe = 100 * sqrt(0.25 / n()) * 1.96 * sqrt(design_effect))
## `summarise()` has grouped output by 'economy'. You can override using the
## `.groups` argument.
# auxiliary table
aux_indicator_table <-
  full_join(overall_account,
            account_gap_female,
            by = "economy") %>%
  full_join(account_gap_inc,
            by = "economy") %>%
  full_join(moe,
            by = "economy") %>%
  mutate(account = round(account),
         gap_female = 
           case_when(
           abs(gap_female) > moe ~ as.character(round(gap_female)),
             TRUE ~ "-"
           ),
         gap_inc =
           case_when(
             abs(gap_inc) > moe ~ as.character(round(gap_inc)),
             TRUE ~ "-"
           )) %>%
  select(economy, account, gap_female, gap_inc)

kable(aux_indicator_table, 
      booktabs = TRUE,
      col.names = c(
        "Economy",
        "Adults with an account(%)", 
        "Gap between men and women (percentage points)",
        "Gap between richer and poorer (percentage points)"),
      align = "lccc",
      caption = "Global Findex Indicator Table - 2017")
Global Findex Indicator Table - 2017
Economy Adults with an account(%) Gap between men and women (percentage points) Gap between richer and poorer (percentage points)
Afghanistan 15 15 -
Albania 40 4 29
Algeria 43 27 13
Argentina 49 -4 18
Armenia 48 15 22
Australia 100 - -
Austria 98 - -
Azerbaijan 29 - 17
Bahrain 83 11 11
Bangladesh 50 29 17
Belarus 81 - 11
Belgium 99 - -
Benin 38 20 11
Bolivia 54 - 19
Bosnia and Herzegovina 59 8 19
Botswana 51 9 27
Brazil 70 5 22
Bulgaria 72 - 29
Burkina Faso 43 17 27
Cambodia 22 - 12
Cameroon 35 9 16
Canada 100 - -
Central African Republic 14 8 8
Chad 22 14 13
Chile 74 6 12
China 80 8 20
Colombia 46 7 18
Congo, Dem. Rep. 26 - 14
Congo, Rep. 26 10 13
Costa Rica 68 15 16
Cote d’Ivoire 41 11 12
Croatia 86 7 9
Cyprus 89 - 8
Czech Republic 81 5 17
Denmark 100 - -
Dominican Republic 56 4 23
Ecuador 51 18 30
Egypt, Arab Rep. 33 12 21
El Salvador 30 13 18
Estonia 98 - -
Ethiopia 35 12 21
Finland 100 - -
France 94 6 -
Gabon 59 10 15
Georgia 61 -5 25
Germany 99 - -
Ghana 58 8 16
Greece 85 - 7
Guatemala 44 4 23
Guinea 23 8 6
Haiti 33 5 25
Honduras 45 9 20
Hong Kong SAR, China 95 - 5
Hungary 75 6 12
India 80 6 5
Indonesia 49 -5 20
Iran, Islamic Rep. 94 5 -
Iraq 23 6 7
Ireland 95 - 4
Israel 93 - 12
Italy 94 5 5
Japan 98 - -
Jordan 42 30 16
Kazakhstan 59 - 16
Kenya 82 8 18
Korea, Rep. 95 - 5
Kosovo 52 17 13
Kuwait 80 10 15
Kyrgyz Republic 40 - 7
Lao PDR 29 -6 19
Latvia 93 - 8
Lebanon 45 24 25
Lesotho 46 - 22
Liberia 36 15 15
Libya 66 11 12
Lithuania 83 4 8
Luxembourg 99 - -
Macedonia, FYR 77 7 16
Madagascar 18 - 9
Malawi 34 8 21
Malaysia 85 5 8
Mali 35 20 7
Malta 97 - 4
Mauritania 21 11 13
Mauritius 90 6 6
Mexico 37 8 18
Moldova 44 - 20
Mongolia 93 -4 4
Montenegro 68 - 13
Morocco 29 25 16
Mozambique 42 18 25
Myanmar 26 - 6
Namibia 81 - 17
Nepal 45 8 12
Netherlands 100 - -
New Zealand 99 - -
Nicaragua 31 13 18
Niger 16 9 8
Nigeria 40 24 25
Norway 100 - -
Pakistan 21 28 12
Panama 46 9 23
Paraguay 49 5 17
Peru 43 17 26
Philippines 34 -9 27
Poland 87 - 4
Portugal 92 - 8
Romania 58 9 33
Russian Federation 76 - 9
Rwanda 50 11 19
Saudi Arabia 72 22 12
Senegal 42 8 13
Serbia 71 - 12
Sierra Leone 20 9 11
Singapore 98 - -
Slovak Republic 84 - 10
Slovenia 98 - -
South Africa 69 - 11
South Sudan 9 8 8
Spain 94 4 -
Sri Lanka 74 - 5
Sweden 100 - -
Switzerland 98 - -
Taiwan, China 94 - 5
Tajikistan 47 10 14
Tanzania 47 9 16
Thailand 82 4 7
Togo 45 15 18
Trinidad and Tobago 81 15 6
Tunisia 37 17 26
Turkey 69 29 20
Turkmenistan 41 10 -
Uganda 59 13 20
Ukraine 63 - 16
United Arab Emirates 88 16 9
United Kingdom 96 - -
United States 93 - 13
Uruguay 64 7 25
Uzbekistan 37 - 12
Venezuela, RB 73 7 22
Vietnam 31 - 18
West Bank and Gaza 25 19 22
Zambia 46 11 24
Zimbabwe 55 8 19