Minimum set of libraries
remove(list=ls())
library(readxl)
library(tidyverse)
library(labelled)
library(ggcorrplot)
library(gridExtra)
library(GGally)
library(knitr)
library(kableExtra)
require(psych)
library(GPArotation)
library(Hmisc)
require(lavaan)
require(lavaanPlot)
require(ResourceSelection)
require(semPlot)
require(tidySEM)
require(performance)
require(car)
library(semPlot)
Correlation, printing, and citing
corplot <- function(d, m = "pearson", sz = 2.5, title = NULL) {
d_num <- d %>% dplyr::select(where(is.numeric))
if (ncol(d_num) < 2) return(NULL)
mycorr <- cor(d_num, use = "pairwise.complete.obs", method = m)
p.mat <- ggcorrplot::cor_pmat(d_num)
ggcorrplot(mycorr,
hc.order = TRUE,
type = "lower",
colors = c("red","white","green"),
tl.cex = 8,
tl.col = "black",
lab = TRUE,
lab_size = sz,
p.mat = p.mat,
sig.level = 0.01,
insig = "pch",
pch = 4) +
ggplot2::ggtitle(title %||% "")
}
myprint=function(x){x%>%kbl()%>%kable_classic(html_font = "Cambria")}
# Import Data
raw_data <- read_excel("../data/raw/economic-freedom-of-the-world-2024-master-index-data-for-researchers-iso.xlsx",
sheet = "EFW Data 2024 Report",
range = "B5:CH4790"
)
## New names:
## • `data` -> `data...9`
## • `data` -> `data...11`
## • `data` -> `data...13`
## • `data` -> `data...15`
## • `data` -> `data...17`
## • `data` -> `data...35`
## • `data` -> `data...37`
## • `data` -> `data...39`
## • `data` -> `data...44`
## • `data` -> `data...46`
## • `data` -> `data...48`
df <- raw_data
#names(df)
#str(df)
1A: Government consumption
1B: Transfers and subsidies
1C: Government investment
1D: Top marginal tax rate
i. 1Di: Top marginal income tax rate
ii. 1Dii: Top marginal income and payroll tax rates
1E: State ownership of assets
# --- Rename only Area 1 columns ---
df <- df %>%
rename(
`1A` = `Government consumption`, # score
`1A_data` = `data...9`, # underlying data
`1B` = `Transfers and subsidies`, # score
`1B_data` = `data...11`, # underlying data
`1C` = `Government investment`, # score
`1C_data` = `data...13`, # underlying data
`1D_i` = `Top marginal income tax rate`, # score
`1D_i_data` = `data...15`, # underlying data
`1D_ii` = `Top marginal income and payroll tax rate`, # score
`1D_ii_data` = `data...17`, # underlying data
`1D` = `Top marginal tax rate`, # combined top rate
`1E` = `State ownership of Assets`, # score
`Area1` = `Size of Government`, # Area 1 summary score
`Area1_rank` = `Area 1 Rank` # Area 1 rank
)
# --- Attach labels so you keep the readable names ---
var_label(df$`1A`) <- "Government consumption"
var_label(df$`1A_data`) <- "Government consumption – data"
var_label(df$`1B`) <- "Transfers and subsidies"
var_label(df$`1B_data`) <- "Transfers and subsidies – data"
var_label(df$`1C`) <- "Government investment"
var_label(df$`1C_data`) <- "Government investment – data"
var_label(df$`1D_i`) <- "Top marginal income tax rate"
var_label(df$`1D_i_data`) <- "Top marginal income tax rate – data"
var_label(df$`1D_ii`) <- "Top marginal income and payroll tax rate"
var_label(df$`1D_ii_data`) <- "Top marginal income and payroll tax rate – data"
var_label(df$`1D`) <- "Top marginal tax rate (aggregate score)"
var_label(df$`1E`) <- "State ownership of Assets"
var_label(df$Area1) <- "Area 1: Size of Government (summary score)"
var_label(df$Area1_rank) <- "Area 1 Rank"
#dplyr::glimpse(df) # see new names
#sapply(df[c("1A","1B","1C","1D","1E","Area1")], var_label) # see labels
2A–2H cover the eight sub-indicators.
2_adj, 2_wo_gen, 2_with_gen capture the gender adjustment and the two alternate summary indices.
Area2 = the official “with gender adjustment” score.
df <- df %>%
rename(
`2A` = `Judicial independence`,
`2B` = `Impartial courts`,
`2C` = `Protection of property rights`,
`2D` = `Military interference in rule of law and politics`,
`2E` = `Integrity of the legal system`,
`2F` = `Legal enforcement of contracts`,
`2G` = `Regulatory restrictions on the sale of real property`,
`2H` = `Reliability of police`,
`2_adj` = `Gender Legal Rights Adjustment`,
`2_wo_gen` = `Legal System & Property Rights -- Without Gender Adjustment`,
`2_with_gen` = `Legal System & Property Rights -- With Gender Adjustment`,
Area2_rank = `Area 2 Rank`
) %>%
mutate(
Area2 = `2_with_gen`
) %>%
relocate(Area2, .after = `2_with_gen`)
# Labels
var_label(df$`2A`) <- "Judicial independence"
var_label(df$`2B`) <- "Impartial courts"
var_label(df$`2C`) <- "Protection of property rights"
var_label(df$`2D`) <- "Military interference in rule of law and politics"
var_label(df$`2E`) <- "Integrity of the legal system"
var_label(df$`2F`) <- "Legal enforcement of contracts"
var_label(df$`2G`) <- "Regulatory restrictions on the sale of real property"
var_label(df$`2H`) <- "Reliability of police"
var_label(df$`2_adj`) <- "Gender Legal Rights Adjustment"
var_label(df$`2_wo_gen`) <- "Legal System & Property Rights (without Gender Adjustment)"
var_label(df$`2_with_gen`) <- "Legal System & Property Rights (with Gender Adjustment)"
var_label(df$Area2) <- "Area 2: Legal System & Property Rights (summary score)"
var_label(df$Area2_rank) <- "Area 2: Rank"
df <- df %>%
rename(
`3A` = `Money growth`,
`3A_data` = `data...35`,
`3B` = `Standard deviation of inflation`,
`3B_data` = `data...37`,
`3C` = `Inflation: Most recent year`,
`3C_data` = `data...39`,
`3D` = `Freedom to own foreign currency bank accounts`,
Area3 = `Sound Money`,
Area3_rank = `Area 3 Rank`
)
var_label(df$`3A`) <- "Money growth"
var_label(df$`3A_data`) <- "Money growth – data"
var_label(df$`3B`) <- "Standard deviation of inflation"
var_label(df$`3B_data`) <- "Standard deviation of inflation – data"
var_label(df$`3C`) <- "Inflation: Most recent year"
var_label(df$`3C_data`) <- "Inflation: Most recent year – data"
var_label(df$`3D`) <- "Freedom to own foreign currency bank accounts"
var_label(df$Area3) <- "Area 3: Sound Money (summary score)"
var_label(df$Area3_rank) <- "Area 3: Rank"
df <- df %>%
rename(
`4A_i` = `Revenue from trade taxes (% of trade sector)`,
`4A_i_data` = `data...44`,
`4A_ii` = `Mean tariff rate`,
`4A_ii_data`= `data...46`,
`4A_iii` = `Standard deviation of tariff rates`,
`4A_iii_data`= `data...48`,
`4A` = `Tariffs`,
`4B_i` = `Non-tariff trade barriers`,
`4B_ii` = `Compliance costs of importing and exporting`,
`4B` = `Regulatory trade barriers`,
`4C` = `Black market exchange rates`,
`4D_i` = `Financial openness`,
`4D_ii` = `Capital controls`,
`4D_iii` = `Freedom of foreigners to visit`,
`4D_iv` = `Protection of foreign assets`,
`4D` = `Controls of the movement of capital and people`,
Area4 = `Freedom to trade internationally`,
Area4_rank = `Area 4 Rank`
)
var_label(df$`4A_i`) <- "Revenue from trade taxes (% of trade sector)"
var_label(df$`4A_i_data`) <- "Revenue from trade taxes – data"
var_label(df$`4A_ii`) <- "Mean tariff rate"
var_label(df$`4A_ii_data`)<- "Mean tariff rate – data"
var_label(df$`4A_iii`) <- "Standard deviation of tariff rates"
var_label(df$`4A_iii_data`)<- "Standard deviation of tariff rates – data"
var_label(df$`4A`) <- "Tariffs (aggregate score)"
var_label(df$`4B_i`) <- "Non-tariff trade barriers"
var_label(df$`4B_ii`) <- "Compliance costs of importing and exporting"
var_label(df$`4B`) <- "Regulatory trade barriers (aggregate score)"
var_label(df$`4C`) <- "Black market exchange rates"
var_label(df$`4D_i`) <- "Financial openness"
var_label(df$`4D_ii`) <- "Capital controls"
var_label(df$`4D_iii`) <- "Freedom of foreigners to visit"
var_label(df$`4D_iv`) <- "Protection of foreign assets"
var_label(df$`4D`) <- "Controls of the movement of capital and people (aggregate score)"
var_label(df$Area4) <- "Area 4: Freedom to trade internationally (summary score)"
var_label(df$Area4_rank) <- "Area 4: Rank"
df <- df %>%
rename(
`5A_i` = `Ownership of banks`,
`5A_ii` = `Private sector credit`,
`5A_iii` = `Interest rate controls/negative real interest rates)`,
`5A` = `Credit market regulations`,
`5B_i` = `Hiring regulations and minimum wage`,
`5B_ii` = `Hiring and firing regulations`,
`5B_iii` = `Centralized collective bargaining`,
`5B_iv` = `Hours Regulations`,
`5B_v` = `Mandated cost of worker dismissal`,
`5B_vi` = `Conscription`,
`5B_vii` = `Foreign Labor`,
`5B` = `Labor market regulations`,
`5C_i` = `Regulatory Burden`,
`5C_ii` = `Bureacracy costs`,
`5C_iii` = `Impartial Public Administration`,
`5C_iv` = `Tax compliance`,
`5C` = `Business regulations`,
`5D_i` = `Market openness`,
`5D_ii` = `Business Permits`,
`5D_iii` = `Distorton of the business environment`,
`5D` = `Freedom to enter markets and compete`,
Area5 = `Regulation`,
Area5_rank = `Area 5 Rank`
)
var_label(df$`5A_i`) <- "Ownership of banks"
var_label(df$`5A_ii`) <- "Private sector credit"
var_label(df$`5A_iii`) <- "Interest rate controls / negative real interest rates"
var_label(df$`5A`) <- "Credit market regulations (aggregate score)"
var_label(df$`5B_i`) <- "Hiring regulations and minimum wage"
var_label(df$`5B_ii`) <- "Hiring and firing regulations"
var_label(df$`5B_iii`) <- "Centralized collective bargaining"
var_label(df$`5B_iv`) <- "Hours Regulations"
var_label(df$`5B_v`) <- "Mandated cost of worker dismissal"
var_label(df$`5B_vi`) <- "Conscription"
var_label(df$`5B_vii`) <- "Foreign Labor"
var_label(df$`5B`) <- "Labor market regulations (aggregate score)"
var_label(df$`5C_i`) <- "Regulatory Burden"
var_label(df$`5C_ii`) <- "Bureaucracy costs"
var_label(df$`5C_iii`) <- "Impartial Public Administration"
var_label(df$`5C_iv`) <- "Tax compliance"
var_label(df$`5C`) <- "Business regulations (aggregate score)"
var_label(df$`5D_i`) <- "Market openness"
var_label(df$`5D_ii`) <- "Business Permits"
var_label(df$`5D_iii`) <- "Distortion of the business environment"
var_label(df$`5D`) <- "Freedom to enter markets and compete (aggregate score)"
var_label(df$Area5) <- "Area 5: Regulation (summary score)"
var_label(df$Area5_rank) <- "Area 5: Rank"
library(writexl)
# export
write_xlsx(x = df, path = "economic_freedom_cleaned.xlsx")
str(df)
## tibble [4,785 × 86] (S3: tbl_df/tbl/data.frame)
## $ Year : num [1:4785] 2022 2022 2022 2022 2022 ...
## $ ISO Code 2 : chr [1:4785] "AL" "DZ" "AO" "AR" ...
## $ ISO Code 3 : chr [1:4785] "ALB" "DZA" "AGO" "ARG" ...
## $ Countries : chr [1:4785] "Albania" "Algeria" "Angola" "Argentina" ...
## $ Economic Freedom Summary Index : num [1:4785] 7.48 4.46 4.79 4.55 7.49 7.98 7.62 5.8 6.65 7.51 ...
## $ Rank : num [1:4785] 38 161 155 159 36 9 23 128 81 34 ...
## $ Quartile : num [1:4785] 1 4 4 4 1 1 1 4 2 1 ...
## $ 1A : num [1:4785] 8.28 3.49 7.94 6.17 7.06 ...
## ..- attr(*, "label")= chr "Government consumption"
## $ 1A_data : num [1:4785] 11.8 28.1 13 19 16 ...
## ..- attr(*, "label")= chr "Government consumption – data"
## $ 1B : num [1:4785] 7.13 7.82 9.7 5.54 7.88 ...
## ..- attr(*, "label")= chr "Transfers and subsidies"
## $ 1B_data : num [1:4785] 11.02 8.51 1.59 16.88 8.27 ...
## ..- attr(*, "label")= chr "Transfers and subsidies – data"
## $ 1C : num [1:4785] 7.55 4 7.74 8.7 8.98 ...
## ..- attr(*, "label")= chr "Government investment"
## $ 1C_data : num [1:4785] 23.6 36 22.9 19.5 18.6 ...
## ..- attr(*, "label")= chr "Government investment – data"
## $ 1D_i : num [1:4785] 9 7 9 7 9 5 4 9 10 10 ...
## ..- attr(*, "label")= chr "Top marginal income tax rate"
## $ 1D_i_data : chr [1:4785] "23" "35" "25" "35" ...
## ..- attr(*, "label")= chr "Top marginal income tax rate – data"
## $ 1D_ii : num [1:4785] 7 2 7 1 7 4 3 4 10 10 ...
## ..- attr(*, "label")= chr "Top marginal income and payroll tax rate"
## $ 1D_ii_data : chr [1:4785] "34" "53" "33" "57" ...
## ..- attr(*, "label")= chr "Top marginal income and payroll tax rate – data"
## $ 1D : num [1:4785] 8 4.5 8 4 8 4.5 3.5 6.5 10 10 ...
## ..- attr(*, "label")= chr "Top marginal tax rate (aggregate score)"
## $ 1E : num [1:4785] 8.08 2.44 4.13 6.69 8.11 ...
## ..- attr(*, "label")= chr "State ownership of Assets"
## $ Area1 : num [1:4785] 7.81 4.45 7.5 6.22 8.01 ...
## ..- attr(*, "label")= chr "Area 1: Size of Government (summary score)"
## $ Area1_rank : num [1:4785] 24 162 36 111 20 117 147 159 3 41 ...
## ..- attr(*, "label")= chr "Area 1 Rank"
## $ 2A : num [1:4785] 4.61 4.01 3.81 4.84 4.56 ...
## ..- attr(*, "label")= chr "Judicial independence"
## $ 2B : num [1:4785] 4.68 3.02 2.93 4.26 4.68 ...
## ..- attr(*, "label")= chr "Impartial courts"
## $ 2C : num [1:4785] 4.42 5.06 3.39 4.79 5.45 ...
## ..- attr(*, "label")= chr "Protection of property rights"
## $ 2D : num [1:4785] 8.33 3.33 4.17 7.5 5 ...
## ..- attr(*, "label")= chr "Military interference in rule of law and politics"
## $ 2E : num [1:4785] 5.75 4.76 3.69 4.52 5.64 ...
## ..- attr(*, "label")= chr "Integrity of the legal system"
## $ 2F : num [1:4785] 3.65 2.84 1.15 3.38 4.29 ...
## ..- attr(*, "label")= chr "Legal enforcement of contracts"
## $ 2G : num [1:4785] 6.72 6.63 5.52 6.86 9.82 ...
## ..- attr(*, "label")= chr "Regulatory restrictions on the sale of real property"
## $ 2H : num [1:4785] 5.3 6.13 2.3 5.96 7.08 ...
## ..- attr(*, "label")= chr "Reliability of police"
## $ 2_adj : num [1:4785] 1 0.706 0.882 0.882 1 ...
## ..- attr(*, "label")= chr "Gender Legal Rights Adjustment"
## $ 2_wo_gen : num [1:4785] 5.43 4.47 3.37 5.26 5.81 ...
## ..- attr(*, "label")= chr "Legal System & Property Rights (without Gender Adjustment)"
## $ 2_with_gen : num [1:4785] 5.43 3.82 3.17 4.95 5.81 ...
## ..- attr(*, "label")= chr "Legal System & Property Rights (with Gender Adjustment)"
## $ Area2 : num [1:4785] 5.43 3.82 3.17 4.95 5.81 ...
## ..- attr(*, "label")= chr "Area 2: Legal System & Property Rights (summary score)"
## $ Area2_rank : num [1:4785] 66 127 145 85 56 9 10 91 68 75 ...
## ..- attr(*, "label")= chr "Area 2: Rank"
## $ 3A : num [1:4785] 9.48 8.68 7.52 0 8.54 ...
## ..- attr(*, "label")= chr "Money growth"
## $ 3A_data : num [1:4785] 2.58 6.59 12.41 53.37 7.3 ...
## ..- attr(*, "label")= chr "Money growth – data"
## $ 3B : num [1:4785] 8.23 5.51 6.01 5.18 8.79 ...
## ..- attr(*, "label")= chr "Standard deviation of inflation"
## $ 3B_data : num [1:4785] 4.42 11.23 9.97 12.05 3.01 ...
## ..- attr(*, "label")= chr "Standard deviation of inflation – data"
## $ 3C : num [1:4785] 7.31 6.29 1.46 0 6.54 ...
## ..- attr(*, "label")= chr "Inflation: Most recent year"
## $ 3C_data : num [1:4785] 6.73 9.27 21.36 71.43 8.64 ...
## ..- attr(*, "label")= chr "Inflation: Most recent year – data"
## $ 3D : num [1:4785] 10 5 5 5 10 10 10 10 0 10 ...
## ..- attr(*, "label")= chr "Freedom to own foreign currency bank accounts"
## $ Area3 : num [1:4785] 8.76 6.37 5 2.55 8.47 ...
## ..- attr(*, "label")= chr "Area 3: Sound Money (summary score)"
## $ Area3_rank : num [1:4785] 28 123 147 162 46 23 49 127 131 12 ...
## ..- attr(*, "label")= chr "Area 3: Rank"
## $ 4A_i : num [1:4785] 9.65 8.48 9.39 4.21 9.56 ...
## ..- attr(*, "label")= chr "Revenue from trade taxes (% of trade sector)"
## $ 4A_i_data : num [1:4785] 0.53 2.28 0.91 8.68 0.66 ...
## ..- attr(*, "label")= chr "Revenue from trade taxes – data"
## $ 4A_ii : num [1:4785] 9.28 6.22 7.8 7.34 8.74 9.52 8.98 8.36 3.5 9.1 ...
## ..- attr(*, "label")= chr "Mean tariff rate"
## $ 4A_ii_data : num [1:4785] 3.6 18.9 11 13.3 6.3 2.4 5.1 8.2 32.5 4.5 ...
## ..- attr(*, "label")= chr "Mean tariff rate – data"
## $ 4A_iii : num [1:4785] 8.08 5.84 3.71 5.85 8.21 ...
## ..- attr(*, "label")= chr "Standard deviation of tariff rates"
## $ 4A_iii_data : num [1:4785] 4.79 10.39 15.73 10.37 4.47 ...
## ..- attr(*, "label")= chr "Standard deviation of tariff rates – data"
## $ 4A : num [1:4785] 9 6.85 6.97 5.8 8.84 ...
## ..- attr(*, "label")= chr "Tariffs (aggregate score)"
## $ 4B_i : num [1:4785] 8.4 2.92 3.6 4.23 4.09 ...
## ..- attr(*, "label")= chr "Non-tariff trade barriers"
## $ 4B_ii : num [1:4785] 9.405 0.479 2.515 5.65 9.315 ...
## ..- attr(*, "label")= chr "Compliance costs of importing and exporting"
## $ 4B : num [1:4785] 8.9 1.7 3.06 4.94 6.71 ...
## ..- attr(*, "label")= chr "Regulatory trade barriers (aggregate score)"
## $ 4C : num [1:4785] 10 2.17 0 2.17 10 ...
## ..- attr(*, "label")= chr "Black market exchange rates"
## $ 4D_i : num [1:4785] 4.02 1.46 2.5 2.66 7.94 ...
## ..- attr(*, "label")= chr "Financial openness"
## $ 4D_ii : num [1:4785] 4.615 0.769 1.538 0 5.385 ...
## ..- attr(*, "label")= chr "Capital controls"
## $ 4D_iii : num [1:4785] 9.27 0.75 0 8.83 8.73 0.11 9.16 2.59 10 7.11 ...
## ..- attr(*, "label")= chr "Freedom of foreigners to visit"
## $ 4D_iv : num [1:4785] 6.9 4.33 3.38 4.37 5.05 ...
## ..- attr(*, "label")= chr "Protection of foreign assets"
## $ 4D : num [1:4785] 6.2 1.83 1.85 3.97 6.78 ...
## ..- attr(*, "label")= chr "Controls of the movement of capital and people (aggregate score)"
## $ Area4 : num [1:4785] 8.53 3.14 2.97 4.22 8.08 ...
## ..- attr(*, "label")= chr "Area 4: Freedom to trade internationally (summary score)"
## $ Area4_rank : num [1:4785] 34 161 164 155 56 52 26 85 145 45 ...
## ..- attr(*, "label")= chr "Area 4: Rank"
## $ 5A_i : num [1:4785] 10 0 5 5 10 10 8 5 10 10 ...
## ..- attr(*, "label")= chr "Ownership of banks"
## $ 5A_ii : num [1:4785] 7.59 6 10 6.07 9.06 ...
## ..- attr(*, "label")= chr "Private sector credit"
## $ 5A_iii : num [1:4785] 9 5 9 0 10 10 10 5 10 10 ...
## ..- attr(*, "label")= chr "Interest rate controls / negative real interest rates"
## $ 5A : num [1:4785] 8.86 3.67 8 3.69 9.69 ...
## ..- attr(*, "label")= chr "Credit market regulations (aggregate score)"
## $ 5B_i : num [1:4785] 6.53 4.03 6.25 3.88 5.83 ...
## ..- attr(*, "label")= chr "Hiring regulations and minimum wage"
## $ 5B_ii : num [1:4785] 5.65 5.82 4.57 1.66 7.13 ...
## ..- attr(*, "label")= chr "Hiring and firing regulations"
## $ 5B_iii : num [1:4785] 5.58 6.52 6.97 3.19 7.25 ...
## ..- attr(*, "label")= chr "Centralized collective bargaining"
## $ 5B_iv : num [1:4785] 8 6 4 10 10 10 6 6 8 8 ...
## ..- attr(*, "label")= chr "Hours Regulations"
## $ 5B_v : num [1:4785] 6.3 7.76 6.63 2.52 9.25 ...
## ..- attr(*, "label")= chr "Mandated cost of worker dismissal"
## $ 5B_vi : num [1:4785] 10 3 0 10 0 10 3 1 10 10 ...
## ..- attr(*, "label")= chr "Conscription"
## $ 5B_vii : num [1:4785] 7.76 3.23 3.56 7.09 6.02 ...
## ..- attr(*, "label")= chr "Foreign Labor"
## $ 5B : num [1:4785] 7.12 5.19 4.57 5.48 6.5 ...
## ..- attr(*, "label")= chr "Labor market regulations (aggregate score)"
## $ 5C_i : num [1:4785] 5.65 4.22 2.94 2.71 5.17 ...
## ..- attr(*, "label")= chr "Regulatory Burden"
## $ 5C_ii : num [1:4785] 6.22 3.78 5.33 5.11 4.67 ...
## ..- attr(*, "label")= chr "Bureaucracy costs"
## $ 5C_iii : num [1:4785] 6.06 2.61 4.86 7.55 6.41 ...
## ..- attr(*, "label")= chr "Impartial Public Administration"
## $ 5C_iv : num [1:4785] 3.59 4.76 4.64 4.5 6.02 ...
## ..- attr(*, "label")= chr "Tax compliance"
## $ 5C : num [1:4785] 5.38 3.84 4.44 4.97 5.57 ...
## ..- attr(*, "label")= chr "Business regulations (aggregate score)"
## $ 5D_i : num [1:4785] 6.81 4.64 3.43 6.14 5.59 ...
## ..- attr(*, "label")= chr "Market openness"
## $ 5D_ii : num [1:4785] 5.62 8.77 7.92 5.73 9.3 ...
## ..- attr(*, "label")= chr "Business Permits"
## $ 5D_iii : num [1:4785] 6.25 2.58 1.25 3.38 5 ...
## ..- attr(*, "label")= chr "Distortion of the business environment"
## $ 5D : num [1:4785] 6.23 5.33 4.2 5.08 6.63 ...
## ..- attr(*, "label")= chr "Freedom to enter markets and compete (aggregate score)"
## $ Area5 : num [1:4785] 6.9 4.51 5.3 4.8 7.1 ...
## ..- attr(*, "label")= chr "Area 5: Regulation (summary score)"
## $ Area5_rank : num [1:4785] 55 156 140 148 45 6 40 107 30 21 ...
## ..- attr(*, "label")= chr "Area 5: Rank"
## $ World Bank Region : chr [1:4785] "Europe & Central Asia" "Middle East & North Africa" "Sub-Saharan Africa" "Latin America & the Caribbean" ...
## $ World Bank Current Income Classification, 1990-Present: chr [1:4785] "UM" "LM" "LM" "UM" ...
# Compute scaling factor
scaling_factor <- (1 + df$`2_adj`) / 2
# Create new scaled variables and assign descriptive names
df$`2A_scaled` <- df$`2A` / scaling_factor
label(df$`2A_scaled`) <- "Judicial independence*"
df$`2B_scaled` <- df$`2B` / scaling_factor
label(df$`2B_scaled`) <- "Impartial courts*"
df$`2C_scaled` <- df$`2C` / scaling_factor
label(df$`2C_scaled`) <- "Protection of property rights*"
df$`2D_scaled` <- df$`2D` / scaling_factor
label(df$`2D_scaled`) <- "Military interference in rule of law and politics*"
df$`2E_scaled` <- df$`2E` / scaling_factor
label(df$`2E_scaled`) <- "Integrity of the legal system *"
df$`2F_scaled` <- df$`2F` / scaling_factor
label(df$`2F_scaled`) <- "Legal enforcement of contracts*"
df$`2G_scaled` <- df$`2G` / scaling_factor
label(df$`2G_scaled`) <- "Regulatory restrictions on property*"
df$`2H_scaled` <- df$`2H` / scaling_factor
label(df$`2H_scaled`) <- "Reliability of police*"
df_2022 <- df %>%
filter(Year == 2022) %>%
select(
Year, Countries, `Economic Freedom Summary Index`, Rank,
# Area 1
`1A`, `1B`, `1C`, `1D_i`, `1D_ii`, `1D`, `1E`, Area1, Area1_rank,
# Area 2
`2A`, `2B`, `2C`, `2D`, `2E`, `2F`, `2G`, `2H`, `2_adj`, `2_wo_gen`, `2_with_gen`, Area2, Area2_rank,
# Scaled variables from Area 2
`2A_scaled`, `2B_scaled`, `2C_scaled`, `2D_scaled`, `2E_scaled`, `2F_scaled`, `2G_scaled`, `2H_scaled`,
# Area 3
`3A`, `3B`, `3C`, `3D`, Area3, Area3_rank,
# Area 4
`4A_i`, `4A_ii`, `4A_iii`, `4A`, `4B_i`, `4B_ii`, `4B`, `4C`,
`4D_i`, `4D_ii`, `4D_iii`, `4D_iv`, `4D`, Area4, Area4_rank,
# Area 5
`5A_i`, `5A_ii`, `5A_iii`, `5A`,
`5B_i`, `5B_ii`, `5B_iii`, `5B_iv`, `5B_v`, `5B_vi`, `5B_vii`, `5B`,
`5C_i`, `5C_ii`, `5C_iii`, `5C_iv`, `5C`,
`5D_i`, `5D_ii`, `5D_iii`, `5D`,
Area5, Area5_rank
)
# myprint(describe(mydata))
str(df_2022 )
## tibble [165 × 78] (S3: tbl_df/tbl/data.frame)
## $ Year : num [1:165] 2022 2022 2022 2022 2022 ...
## $ Countries : chr [1:165] "Albania" "Algeria" "Angola" "Argentina" ...
## $ Economic Freedom Summary Index: num [1:165] 7.48 4.46 4.79 4.55 7.49 7.98 7.62 5.8 6.65 7.51 ...
## $ Rank : num [1:165] 38 161 155 159 36 9 23 128 81 34 ...
## $ 1A : num [1:165] 8.28 3.49 7.94 6.17 7.06 ...
## ..- attr(*, "label")= chr "Government consumption"
## $ 1B : num [1:165] 7.13 7.82 9.7 5.54 7.88 ...
## ..- attr(*, "label")= chr "Transfers and subsidies"
## $ 1C : num [1:165] 7.55 4 7.74 8.7 8.98 ...
## ..- attr(*, "label")= chr "Government investment"
## $ 1D_i : num [1:165] 9 7 9 7 9 5 4 9 10 10 ...
## ..- attr(*, "label")= chr "Top marginal income tax rate"
## $ 1D_ii : num [1:165] 7 2 7 1 7 4 3 4 10 10 ...
## ..- attr(*, "label")= chr "Top marginal income and payroll tax rate"
## $ 1D : num [1:165] 8 4.5 8 4 8 4.5 3.5 6.5 10 10 ...
## ..- attr(*, "label")= chr "Top marginal tax rate (aggregate score)"
## $ 1E : num [1:165] 8.08 2.44 4.13 6.69 8.11 ...
## ..- attr(*, "label")= chr "State ownership of Assets"
## $ Area1 : num [1:165] 7.81 4.45 7.5 6.22 8.01 ...
## ..- attr(*, "label")= chr "Area 1: Size of Government (summary score)"
## $ Area1_rank : num [1:165] 24 162 36 111 20 117 147 159 3 41 ...
## ..- attr(*, "label")= chr "Area 1 Rank"
## $ 2A : num [1:165] 4.61 4.01 3.81 4.84 4.56 ...
## ..- attr(*, "label")= chr "Judicial independence"
## $ 2B : num [1:165] 4.68 3.02 2.93 4.26 4.68 ...
## ..- attr(*, "label")= chr "Impartial courts"
## $ 2C : num [1:165] 4.42 5.06 3.39 4.79 5.45 ...
## ..- attr(*, "label")= chr "Protection of property rights"
## $ 2D : num [1:165] 8.33 3.33 4.17 7.5 5 ...
## ..- attr(*, "label")= chr "Military interference in rule of law and politics"
## $ 2E : num [1:165] 5.75 4.76 3.69 4.52 5.64 ...
## ..- attr(*, "label")= chr "Integrity of the legal system"
## $ 2F : num [1:165] 3.65 2.84 1.15 3.38 4.29 ...
## ..- attr(*, "label")= chr "Legal enforcement of contracts"
## $ 2G : num [1:165] 6.72 6.63 5.52 6.86 9.82 ...
## ..- attr(*, "label")= chr "Regulatory restrictions on the sale of real property"
## $ 2H : num [1:165] 5.3 6.13 2.3 5.96 7.08 ...
## ..- attr(*, "label")= chr "Reliability of police"
## $ 2_adj : num [1:165] 1 0.706 0.882 0.882 1 ...
## ..- attr(*, "label")= chr "Gender Legal Rights Adjustment"
## $ 2_wo_gen : num [1:165] 5.43 4.47 3.37 5.26 5.81 ...
## ..- attr(*, "label")= chr "Legal System & Property Rights (without Gender Adjustment)"
## $ 2_with_gen : num [1:165] 5.43 3.82 3.17 4.95 5.81 ...
## ..- attr(*, "label")= chr "Legal System & Property Rights (with Gender Adjustment)"
## $ Area2 : num [1:165] 5.43 3.82 3.17 4.95 5.81 ...
## ..- attr(*, "label")= chr "Area 2: Legal System & Property Rights (summary score)"
## $ Area2_rank : num [1:165] 66 127 145 85 56 9 10 91 68 75 ...
## ..- attr(*, "label")= chr "Area 2: Rank"
## $ 2A_scaled : 'labelled' num [1:165] 4.61 4.71 4.04 5.15 4.56 ...
## ..- attr(*, "label")= chr "Judicial independence*"
## $ 2B_scaled : 'labelled' num [1:165] 4.68 3.54 3.11 4.52 4.68 ...
## ..- attr(*, "label")= chr "Impartial courts*"
## $ 2C_scaled : 'labelled' num [1:165] 4.42 5.94 3.6 5.09 5.45 ...
## ..- attr(*, "label")= chr "Protection of property rights*"
## $ 2D_scaled : 'labelled' num [1:165] 8.33 3.91 4.43 7.97 5 ...
## ..- attr(*, "label")= chr "Military interference in rule of law and politics*"
## $ 2E_scaled : 'labelled' num [1:165] 5.75 5.58 3.93 4.81 5.64 ...
## ..- attr(*, "label")= chr "Integrity of the legal system *"
## $ 2F_scaled : 'labelled' num [1:165] 3.65 3.33 1.22 3.59 4.29 ...
## ..- attr(*, "label")= chr "Legal enforcement of contracts*"
## $ 2G_scaled : 'labelled' num [1:165] 6.72 7.77 5.87 7.29 9.82 ...
## ..- attr(*, "label")= chr "Regulatory restrictions on property*"
## $ 2H_scaled : 'labelled' num [1:165] 5.3 7.19 2.45 6.33 7.08 ...
## ..- attr(*, "label")= chr "Reliability of police*"
## $ 3A : num [1:165] 9.48 8.68 7.52 0 8.54 ...
## ..- attr(*, "label")= chr "Money growth"
## $ 3B : num [1:165] 8.23 5.51 6.01 5.18 8.79 ...
## ..- attr(*, "label")= chr "Standard deviation of inflation"
## $ 3C : num [1:165] 7.31 6.29 1.46 0 6.54 ...
## ..- attr(*, "label")= chr "Inflation: Most recent year"
## $ 3D : num [1:165] 10 5 5 5 10 10 10 10 0 10 ...
## ..- attr(*, "label")= chr "Freedom to own foreign currency bank accounts"
## $ Area3 : num [1:165] 8.76 6.37 5 2.55 8.47 ...
## ..- attr(*, "label")= chr "Area 3: Sound Money (summary score)"
## $ Area3_rank : num [1:165] 28 123 147 162 46 23 49 127 131 12 ...
## ..- attr(*, "label")= chr "Area 3: Rank"
## $ 4A_i : num [1:165] 9.65 8.48 9.39 4.21 9.56 ...
## ..- attr(*, "label")= chr "Revenue from trade taxes (% of trade sector)"
## $ 4A_ii : num [1:165] 9.28 6.22 7.8 7.34 8.74 9.52 8.98 8.36 3.5 9.1 ...
## ..- attr(*, "label")= chr "Mean tariff rate"
## $ 4A_iii : num [1:165] 8.08 5.84 3.71 5.85 8.21 ...
## ..- attr(*, "label")= chr "Standard deviation of tariff rates"
## $ 4A : num [1:165] 9 6.85 6.97 5.8 8.84 ...
## ..- attr(*, "label")= chr "Tariffs (aggregate score)"
## $ 4B_i : num [1:165] 8.4 2.92 3.6 4.23 4.09 ...
## ..- attr(*, "label")= chr "Non-tariff trade barriers"
## $ 4B_ii : num [1:165] 9.405 0.479 2.515 5.65 9.315 ...
## ..- attr(*, "label")= chr "Compliance costs of importing and exporting"
## $ 4B : num [1:165] 8.9 1.7 3.06 4.94 6.71 ...
## ..- attr(*, "label")= chr "Regulatory trade barriers (aggregate score)"
## $ 4C : num [1:165] 10 2.17 0 2.17 10 ...
## ..- attr(*, "label")= chr "Black market exchange rates"
## $ 4D_i : num [1:165] 4.02 1.46 2.5 2.66 7.94 ...
## ..- attr(*, "label")= chr "Financial openness"
## $ 4D_ii : num [1:165] 4.615 0.769 1.538 0 5.385 ...
## ..- attr(*, "label")= chr "Capital controls"
## $ 4D_iii : num [1:165] 9.27 0.75 0 8.83 8.73 0.11 9.16 2.59 10 7.11 ...
## ..- attr(*, "label")= chr "Freedom of foreigners to visit"
## $ 4D_iv : num [1:165] 6.9 4.33 3.38 4.37 5.05 ...
## ..- attr(*, "label")= chr "Protection of foreign assets"
## $ 4D : num [1:165] 6.2 1.83 1.85 3.97 6.78 ...
## ..- attr(*, "label")= chr "Controls of the movement of capital and people (aggregate score)"
## $ Area4 : num [1:165] 8.53 3.14 2.97 4.22 8.08 ...
## ..- attr(*, "label")= chr "Area 4: Freedom to trade internationally (summary score)"
## $ Area4_rank : num [1:165] 34 161 164 155 56 52 26 85 145 45 ...
## ..- attr(*, "label")= chr "Area 4: Rank"
## $ 5A_i : num [1:165] 10 0 5 5 10 10 8 5 10 10 ...
## ..- attr(*, "label")= chr "Ownership of banks"
## $ 5A_ii : num [1:165] 7.59 6 10 6.07 9.06 ...
## ..- attr(*, "label")= chr "Private sector credit"
## $ 5A_iii : num [1:165] 9 5 9 0 10 10 10 5 10 10 ...
## ..- attr(*, "label")= chr "Interest rate controls / negative real interest rates"
## $ 5A : num [1:165] 8.86 3.67 8 3.69 9.69 ...
## ..- attr(*, "label")= chr "Credit market regulations (aggregate score)"
## $ 5B_i : num [1:165] 6.53 4.03 6.25 3.88 5.83 ...
## ..- attr(*, "label")= chr "Hiring regulations and minimum wage"
## $ 5B_ii : num [1:165] 5.65 5.82 4.57 1.66 7.13 ...
## ..- attr(*, "label")= chr "Hiring and firing regulations"
## $ 5B_iii : num [1:165] 5.58 6.52 6.97 3.19 7.25 ...
## ..- attr(*, "label")= chr "Centralized collective bargaining"
## $ 5B_iv : num [1:165] 8 6 4 10 10 10 6 6 8 8 ...
## ..- attr(*, "label")= chr "Hours Regulations"
## $ 5B_v : num [1:165] 6.3 7.76 6.63 2.52 9.25 ...
## ..- attr(*, "label")= chr "Mandated cost of worker dismissal"
## $ 5B_vi : num [1:165] 10 3 0 10 0 10 3 1 10 10 ...
## ..- attr(*, "label")= chr "Conscription"
## $ 5B_vii : num [1:165] 7.76 3.23 3.56 7.09 6.02 ...
## ..- attr(*, "label")= chr "Foreign Labor"
## $ 5B : num [1:165] 7.12 5.19 4.57 5.48 6.5 ...
## ..- attr(*, "label")= chr "Labor market regulations (aggregate score)"
## $ 5C_i : num [1:165] 5.65 4.22 2.94 2.71 5.17 ...
## ..- attr(*, "label")= chr "Regulatory Burden"
## $ 5C_ii : num [1:165] 6.22 3.78 5.33 5.11 4.67 ...
## ..- attr(*, "label")= chr "Bureaucracy costs"
## $ 5C_iii : num [1:165] 6.06 2.61 4.86 7.55 6.41 ...
## ..- attr(*, "label")= chr "Impartial Public Administration"
## $ 5C_iv : num [1:165] 3.59 4.76 4.64 4.5 6.02 ...
## ..- attr(*, "label")= chr "Tax compliance"
## $ 5C : num [1:165] 5.38 3.84 4.44 4.97 5.57 ...
## ..- attr(*, "label")= chr "Business regulations (aggregate score)"
## $ 5D_i : num [1:165] 6.81 4.64 3.43 6.14 5.59 ...
## ..- attr(*, "label")= chr "Market openness"
## $ 5D_ii : num [1:165] 5.62 8.77 7.92 5.73 9.3 ...
## ..- attr(*, "label")= chr "Business Permits"
## $ 5D_iii : num [1:165] 6.25 2.58 1.25 3.38 5 ...
## ..- attr(*, "label")= chr "Distortion of the business environment"
## $ 5D : num [1:165] 6.23 5.33 4.2 5.08 6.63 ...
## ..- attr(*, "label")= chr "Freedom to enter markets and compete (aggregate score)"
## $ Area5 : num [1:165] 6.9 4.51 5.3 4.8 7.1 ...
## ..- attr(*, "label")= chr "Area 5: Regulation (summary score)"
## $ Area5_rank : num [1:165] 55 156 140 148 45 6 40 107 30 21 ...
## ..- attr(*, "label")= chr "Area 5: Rank"
# Step 1: Extract variable labels (fallback to variable name if missing)
# --- Create clean variable labels for df_2022 ---
lab_vec <- vapply(
names(df_2022),
function(n) {
lb <- attr(df_2022[[n]], "label", exact = TRUE)
if (is.null(lb) || is.na(lb) || lb == "") {
return(n)
}
# Remove redundant repetition of variable name inside the label
lb_clean <- sub(paste0("^", n, "\\s*[:\\-]?\\s*", collapse = ""), "", lb)
# Output as "varname: cleaned label"
paste0(n, ": ", lb_clean)
},
character(1)
)
# Step 2: Run describe() only on numeric columns
desc <- psych::describe(select(df_2022, where(is.numeric)), fast = FALSE)
# Step 3: Apply labels as rownames
rownames(desc) <- lab_vec[rownames(desc)]
# Step 4: Create final summary data.frame
desc_df <- desc %>%
as.data.frame() %>%
tibble::rownames_to_column("Variable") %>%
select(Variable, n, mean, sd, min, max) %>%
rename(
N = n,
Mean = mean,
SD = sd,
Min = min,
Max = max
)
# Step 5: Render as nicely formatted table
kable(
desc_df,
digits = 2,
col.names = c("Variable", "N", "Mean", "SD", "Min", "Max"),
align = "lccccc",
caption = "Summary Statistics with Labels (Including Scaled Variables)"
) %>%
kable_styling(full_width = FALSE, position = "center", font_size = 12)
Variable | N | Mean | SD | Min | Max |
---|---|---|---|---|---|
Year | 165 | 2022.00 | 0.00 | 2022.00 | 2022.00 |
Economic Freedom Summary Index | 165 | 6.53 | 1.05 | 3.02 | 8.58 |
Rank | 165 | 82.78 | 47.80 | 1.00 | 165.00 |
1A: Government consumption | 165 | 5.47 | 2.46 | 0.00 | 10.00 |
1B: Transfers and subsidies | 156 | 7.53 | 2.05 | 1.82 | 10.00 |
1C: Government investment | 161 | 7.12 | 3.28 | 0.00 | 10.00 |
1D_i: Top marginal income tax rate | 165 | 7.47 | 2.19 | 2.00 | 10.00 |
1D_ii: Top marginal income and payroll tax rate | 162 | 5.48 | 2.63 | 0.00 | 10.00 |
1D: Top marginal tax rate (aggregate score) | 165 | 6.50 | 2.23 | 1.00 | 10.00 |
1E: State ownership of Assets | 162 | 6.66 | 1.58 | 2.44 | 9.52 |
Area1: Area 1: Size of Government (summary score) | 165 | 6.64 | 1.12 | 3.62 | 9.06 |
Area1_rank: Area 1 Rank | 165 | 83.00 | 47.78 | 1.00 | 165.00 |
2A: Judicial independence | 165 | 5.51 | 1.45 | 2.45 | 8.64 |
2B: Impartial courts | 165 | 4.66 | 1.89 | 0.83 | 8.84 |
2C: Protection of property rights | 165 | 5.44 | 2.16 | 0.00 | 9.67 |
2D: Military interference in rule of law and politics | 138 | 6.29 | 2.66 | 0.00 | 10.00 |
2E: Integrity of the legal system | 164 | 5.83 | 1.85 | 1.70 | 9.80 |
2F: Legal enforcement of contracts | 165 | 3.97 | 1.98 | 0.00 | 8.73 |
2G: Regulatory restrictions on the sale of real property | 163 | 7.59 | 1.52 | 2.67 | 9.98 |
2H: Reliability of police | 165 | 5.21 | 2.42 | 0.00 | 9.77 |
2_adj: Gender Legal Rights Adjustment | 165 | 0.87 | 0.17 | 0.29 | 1.00 |
2_wo_gen: Legal System & Property Rights (without Gender Adjustment) | 165 | 5.53 | 1.66 | 1.98 | 9.10 |
2_with_gen: Legal System & Property Rights (with Gender Adjustment) | 165 | 5.23 | 1.79 | 1.63 | 9.10 |
Area2: Area 2: Legal System & Property Rights (summary score) | 165 | 5.23 | 1.79 | 1.63 | 9.10 |
Area2_rank: Area 2: Rank | 165 | 83.00 | 47.78 | 1.00 | 165.00 |
2A_scaled: Judicial independence* | 165 | 5.89 | 1.42 | 2.45 | 8.64 |
2B_scaled: Impartial courts* | 165 | 4.95 | 1.88 | 1.00 | 8.84 |
2C_scaled: Protection of property rights* | 165 | 5.78 | 2.15 | 0.00 | 9.93 |
2D_scaled: Military interference in rule of law and politics* | 138 | 6.66 | 2.65 | 0.00 | 11.33 |
2E_scaled: Integrity of the legal system * | 164 | 6.21 | 1.81 | 1.70 | 9.80 |
2F_scaled: Legal enforcement of contracts* | 165 | 4.22 | 2.00 | 0.00 | 8.73 |
2G_scaled: Regulatory restrictions on property* | 163 | 8.16 | 1.75 | 3.02 | 13.81 |
2H_scaled: Reliability of police* | 165 | 5.55 | 2.59 | 0.00 | 12.13 |
3A: Money growth | 163 | 8.24 | 1.61 | 0.00 | 9.98 |
3B: Standard deviation of inflation | 165 | 7.65 | 2.52 | 0.00 | 9.74 |
3C: Inflation: Most recent year | 165 | 5.88 | 2.61 | 0.00 | 9.46 |
3D: Freedom to own foreign currency bank accounts | 165 | 7.15 | 3.95 | 0.00 | 10.00 |
Area3: Area 3: Sound Money (summary score) | 165 | 7.23 | 1.71 | 0.74 | 9.55 |
Area3_rank: Area 3: Rank | 165 | 82.99 | 47.77 | 1.00 | 165.00 |
4A_i: Revenue from trade taxes (% of trade sector) | 156 | 8.63 | 1.47 | 3.33 | 10.00 |
4A_ii: Mean tariff rate | 164 | 8.26 | 1.02 | 3.50 | 10.00 |
4A_iii: Standard deviation of tariff rates | 165 | 6.06 | 2.13 | 0.00 | 10.00 |
4A: Tariffs (aggregate score) | 165 | 7.62 | 1.18 | 3.92 | 10.00 |
4B_i: Non-tariff trade barriers | 165 | 5.75 | 1.80 | 0.00 | 9.18 |
4B_ii: Compliance costs of importing and exporting | 165 | 6.46 | 3.01 | 0.00 | 9.98 |
4B: Regulatory trade barriers (aggregate score) | 165 | 6.11 | 2.11 | 1.69 | 9.41 |
4C: Black market exchange rates | 165 | 9.22 | 2.47 | 0.00 | 10.00 |
4D_i: Financial openness | 165 | 5.84 | 3.02 | 0.00 | 10.00 |
4D_ii: Capital controls | 164 | 3.52 | 2.76 | 0.00 | 10.00 |
4D_iii: Freedom of foreigners to visit | 165 | 7.10 | 3.38 | 0.00 | 10.00 |
4D_iv: Protection of foreign assets | 165 | 5.73 | 2.10 | 0.00 | 9.27 |
4D: Controls of the movement of capital and people (aggregate score) | 165 | 5.55 | 2.15 | 0.69 | 9.40 |
Area4: Area 4: Freedom to trade internationally (summary score) | 165 | 7.12 | 1.49 | 2.48 | 9.66 |
Area4_rank: Area 4: Rank | 165 | 83.00 | 47.78 | 1.00 | 165.00 |
5A_i: Ownership of banks | 151 | 7.59 | 2.78 | 0.00 | 10.00 |
5A_ii: Private sector credit | 162 | 7.39 | 2.53 | 0.00 | 10.00 |
5A_iii: Interest rate controls / negative real interest rates | 163 | 8.35 | 2.27 | 0.00 | 10.00 |
5A: Credit market regulations (aggregate score) | 164 | 7.74 | 1.63 | 0.00 | 10.00 |
5B_i: Hiring regulations and minimum wage | 165 | 5.81 | 1.80 | 1.25 | 9.45 |
5B_ii: Hiring and firing regulations | 165 | 5.64 | 1.97 | 0.00 | 10.00 |
5B_iii: Centralized collective bargaining | 141 | 6.48 | 1.22 | 1.61 | 8.67 |
5B_iv: Hours Regulations | 165 | 7.84 | 1.94 | 2.00 | 10.00 |
5B_v: Mandated cost of worker dismissal | 162 | 6.49 | 2.83 | 0.00 | 10.00 |
5B_vi: Conscription | 165 | 6.61 | 4.20 | 0.00 | 10.00 |
5B_vii: Foreign Labor | 165 | 5.02 | 1.49 | 0.00 | 8.14 |
5B: Labor market regulations (aggregate score) | 165 | 6.25 | 1.22 | 2.67 | 9.14 |
5C_i: Regulatory Burden | 158 | 4.15 | 1.22 | 1.14 | 7.44 |
5C_ii: Bureaucracy costs | 165 | 5.04 | 2.22 | 0.00 | 9.56 |
5C_iii: Impartial Public Administration | 162 | 5.62 | 2.48 | 0.34 | 9.91 |
5C_iv: Tax compliance | 165 | 5.90 | 1.92 | 0.00 | 9.87 |
5C: Business regulations (aggregate score) | 165 | 5.17 | 1.55 | 0.60 | 9.05 |
5D_i: Market openness | 165 | 6.07 | 1.80 | 1.24 | 10.00 |
5D_ii: Business Permits | 161 | 8.39 | 1.14 | 4.98 | 10.00 |
5D_iii: Distortion of the business environment | 165 | 5.20 | 2.29 | 0.00 | 10.00 |
5D: Freedom to enter markets and compete (aggregate score) | 165 | 6.52 | 1.44 | 2.59 | 9.86 |
Area5: Area 5: Regulation (summary score) | 165 | 6.41 | 1.13 | 2.54 | 8.86 |
Area5_rank: Area 5: Rank | 165 | 83.00 | 47.78 | 1.00 | 165.00 |
# ---- Helper that ignores missing vars gracefully ----
sel_vars <- function(df_2022, vars) dplyr::select(df, dplyr::any_of(vars))
# ============
# GROUPS by Area (matches your current columns)
# ============
groups <- list(
A1 = c("1A","1B","1C","1D_i","1D_ii","1D","1E","Area1"),
A2 = c("2A","2B","2C","2D","2E","2F","2G","2H","2_adj","2_wo_gen","2_with_gen","Area2"),
A2_scaled = c("2A_scaled","2B_scaled","2C_scaled","2D_scaled", "2E_scaled","2F_scaled","2G_scaled","2H_scaled", "Area2"),
A3 = c("3A","3B","3C","3D","Area3"),
A4 = c("4A_i","4A_ii","4A_iii","4A","4B_i","4B_ii","4B","4C","4D_i","4D_ii","4D_iii","4D_iv","4D","Area4"),
A5 = c("5A_i","5A_ii","5A_iii","5A",
"5B_i","5B_ii","5B_iii","5B_iv","5B_v","5B_vi","5B_vii","5B",
"5C_i","5C_ii","5C_iii","5C_iv","5C",
"5D_i","5D_ii","5D_iii","5D","Area5")
)
# Optional: keep rank columns for reference or plotting separately
ranks <- c("Area1_rank","Area2_rank","Area3_rank","Area4_rank","Area5_rank")
# ============
# EXAMPLE: build a 2x3 grid of correlation plots by Area
# (skips a plot if not enough numeric columns)
# ============
plots <- list(
corplot(sel_vars(df_2002, groups$A1), title = "Area 1 (1A–1E + Area1)"),
corplot(sel_vars(df_2002, groups$A2), title = "Area 2 (2A–2H + adj & summaries)"),
corplot(sel_vars(df_2002, groups$A2_scaled), title = "Area 2 (scaled variables)"),
corplot(sel_vars(df_2002, groups$A3), title = "Area 3 (3A–3D + Area3)"),
corplot(sel_vars(df_2002, groups$A4), title = "Area 4 (4A–4D + Area4)"),
corplot(sel_vars(df_2002, groups$A5), title = "Area 5 (5A–5D + Area5)")
)
# Drop NULLs (in case a group had <2 numeric vars)
plots <- Filter(Negate(is.null), plots)
# Arrange (2 columns looks small)
# if (length(plots) > 0) gridExtra::grid.arrange(grobs = plots, ncol = 1)
# Print each correlation plot separately
for (i in seq_along(plots)) {
print(plots[[i]])
}
all_vars <- unique(unlist(groups))
plot_all <- corplot(sel_vars(df_2002, all_vars), sz = 2, title = "All Areas: indicators + Area summaries")
if (!is.null(plot_all)) print(plot_all)
KDE Pairs of data - not evaluted for speeding computations