#install.packages(c("readxl", "tidyverse", "ineq", "reshape2"))
library(readxl)
library(tidyverse)
library(ineq)
library(reshape2)
setwd("C:/Users/user/Downloads")

decile_data <- read_excel("GCIPrawdata.xlsx", skip = 2) 

head(decile_data)  
## # A tibble: 6 × 14
##   Country      Year `Decile 1 Income` `Decile 2 Income` `Decile 3 Income`
##   <chr>       <dbl>             <dbl>             <dbl>             <dbl>
## 1 Afghanistan  1980               206               350               455
## 2 Afghanistan  1981               212               361               469
## 3 Afghanistan  1982               221               377               490
## 4 Afghanistan  1983               238               405               527
## 5 Afghanistan  1984               249               424               551
## 6 Afghanistan  1985               256               435               566
## # ℹ 9 more variables: `Decile 4 Income` <dbl>, `Decile 5 Income` <dbl>,
## #   `Decile 6 Income` <dbl>, `Decile 7 Income` <dbl>, `Decile 8 Income` <dbl>,
## #   `Decile 9 Income` <dbl>, `Decile 10 Income` <dbl>, `Mean Income` <dbl>,
## #   Population <dbl>
sel_Year <- c(1980, 2014)
sel_Country <- c("Belarus", "Germany")

temp <- decile_data %>% filter(Country %in% sel_Country & Year %in% sel_Year)
temp
## # A tibble: 4 × 14
##   Country  Year `Decile 1 Income` `Decile 2 Income` `Decile 3 Income`
##   <chr>   <dbl>             <dbl>             <dbl>             <dbl>
## 1 Belarus  1980               793              1095              1332
## 2 Belarus  2014              2211              3435              4417
## 3 Germany  1980              5077              6461              7689
## 4 Germany  2014              5222              7305              9045
## # ℹ 9 more variables: `Decile 4 Income` <dbl>, `Decile 5 Income` <dbl>,
## #   `Decile 6 Income` <dbl>, `Decile 7 Income` <dbl>, `Decile 8 Income` <dbl>,
## #   `Decile 9 Income` <dbl>, `Decile 10 Income` <dbl>, `Mean Income` <dbl>,
## #   Population <dbl>
total_income <- temp[, "Mean Income"] * temp[, "Population"]  
options(scipen = 999)
total_income  
##     Mean Income
## 1   19141355000
## 2   98213370000
## 3  764805832000
## 4 1239206436000
decs_b80 <- unlist(temp[1, 3:12]) * 2
                               
total_inc <- 20 * unlist(temp[1, "Mean Income"])

cum_inc_share_b80 <- cumsum(decs_b80) / total_inc
cum_inc_share_b80
##  Decile 1 Income  Decile 2 Income  Decile 3 Income  Decile 4 Income 
##       0.03994962       0.09511335       0.16221662       0.23974811 
##  Decile 5 Income  Decile 6 Income  Decile 7 Income  Decile 8 Income 
##       0.32730479       0.42518892       0.53471033       0.65884131 
##  Decile 9 Income Decile 10 Income 
##       0.80468514       0.99984887
decs_b14 <- unlist(temp[2, 3:12]) * 2
                               
total_inc <- 20 * unlist(temp[2, "Mean Income"])

cum_inc_share_b14 <- cumsum(decs_b14) / total_inc
cum_inc_share_b14
##  Decile 1 Income  Decile 2 Income  Decile 3 Income  Decile 4 Income 
##       0.02131906       0.05444027       0.09703018       0.14941664 
##  Decile 5 Income  Decile 6 Income  Decile 7 Income  Decile 8 Income 
##       0.21266030       0.28859319       0.38036833       0.49400251 
##  Decile 9 Income Decile 10 Income 
##       0.64454730       1.00000000
decs_g80 <- unlist(temp[3, 3:12]) * 2
                               
total_inc <- 20 * unlist(temp[3, "Mean Income"])

cum_inc_share_g80 <- cumsum(decs_g80) / total_inc
cum_inc_share_g80
##  Decile 1 Income  Decile 2 Income  Decile 3 Income  Decile 4 Income 
##       0.04093035       0.09301838       0.15500645       0.22644308 
##  Decile 5 Income  Decile 6 Income  Decile 7 Income  Decile 8 Income 
##       0.30750564       0.39905676       0.50299903       0.62334731 
##  Decile 9 Income Decile 10 Income 
##       0.77026766       1.00000000
decs_g14 <- unlist(temp[4, 3:12]) * 2
                               
total_inc <- 20 * unlist(temp[4, "Mean Income"])

cum_inc_share_g14 <- cumsum(decs_g14) / total_inc
cum_inc_share_g14
##  Decile 1 Income  Decile 2 Income  Decile 3 Income  Decile 4 Income 
##       0.03398412       0.08152414       0.14038787       0.20963165 
##  Decile 5 Income  Decile 6 Income  Decile 7 Income  Decile 8 Income 
##       0.28916439       0.37970194       0.48309254       0.60342965 
##  Decile 9 Income Decile 10 Income 
##       0.75147078       0.99998048
plot(cum_inc_share_b80, type = "l", col = "blue", 
  lwd = 2, xlab = "Deciles", ylab = "Cumulative income share",
   xlim = c(0,10), ylim = c(0,1)
  )  

abline(a = 0, b = 0.1, col = "black", lwd = 2)

title("Lorenz curve, Belarus, 1980") 

highlight_point <- data.frame(prop = 6, y = 0.42)

points(highlight_point, col = "blue", pch = 16)

The Lorenz curve is a graphical representation of the distribution of income or wealth in a society. It shows the cumulative proportion of income or wealth held by the bottom x% of the population.

The point highlighted on the curve represents the situation where 60% of the population holds 42% of the income. The X-coordinate of this point is 60, which indicates that 60% of the population is at (or below) this point on the curve. The Y-coordinate of this point is 0.42, which indicates that this 60% of the population holds 42% of the income.

plot(cum_inc_share_b80, type = "l", col = "blue", 
  lty = 2, lwd = 2, xlab = "Deciles", 
  ylab = "Cumulative income share")  

abline(a = 0, b = 0.1, col = "black", lwd = 2)  

lines(cum_inc_share_b14, col = "green", lty = 1, lwd = 2)

lines(cum_inc_share_g80, col = "magenta", lty = 2, lwd = 2)

lines(cum_inc_share_g14, col = "orange", lty = 1, lwd = 2)  

title("Lorenz curves, Belarus and Germany (1980 and 2014)")  

legend("topleft", lty = 2.5:1, lwd = 2, cex = 1.2, legend = 
  c("Belarus, 1980", "Belarus, 2014",
    "Germany, 1980", "Germany, 2014"),  
  col = c("blue", "green", "magenta", "orange"))

### Gini coefficient

g_b80 <- Gini(decs_b80)
g_b14 <- Gini(decs_b14)
g_g80 <- Gini(decs_g80)
g_g14 <- Gini(decs_g14)
paste("Gini coefficients")
## [1] "Gini coefficients"
paste("Belarus - 1980: ", round(g_b80, 2), ", 2014: ", round(g_b14, 2))
## [1] "Belarus - 1980:  0.24 , 2014:  0.43"
paste("Germany - 1980: ", round(g_g80, 2), ", 2014: ", round(g_g14, 2))
## [1] "Germany - 1980:  0.28 , 2014:  0.31"
plot(cum_inc_share_b80, type = "l", col = "blue", lty = 2, 
  lwd = 2, xlab = "Deciles", 
  ylab = "Cumulative income share")   

abline(a = 0, b = 0.1, col = "black", lwd = 2)

lines(cum_inc_share_b14, col = "green", lty = 1, lwd = 2)

lines(cum_inc_share_g80, col = "magenta", lty = 2, lwd = 2)

lines(cum_inc_share_g14, col = "orange", lty = 1, lwd = 2)

title("Lorenz curves, Belarus and Germany (1980 and 2014)")

legend("topleft", lty = 2.5:1, lwd = 2, cex = 1.2, legend = 
  c("Belarus, 1980", "Belarus, 2014", 
    "Germany, 1980", "Germany, 2014"),
  col = c("blue", "green", "magenta", "orange"))

text(8.4, 0.78, round(g_b80, digits = 3), col = 'blue')
text(9.4, 0.6, round(g_b14, digits = 3), col = 'green')
text(5.2, 0.37, round(g_g80, digits = 3), col = 'magenta')
text(6.4, 0.31, round(g_g14, digits = 3), col = 'orange')

Distribution of income across time, Belarus

Income inequality increased significantly from 1980 to 2014, as the Lorenz curve shifted to the right. The Gini coefficient increased from 0.24 to 0.43, indicating a widening income gap.

Distribution of income across time, Germany

Income inequality also increased slightly from 1980 to 2014, but to a lesser extent than in Belarus. The Lorenz curve shifted slightly to the right, and the Gini coefficient increased from 0.28 to 0.31.

Distribution of income across countries

1980: Belarus had a slightly more equal income distribution than Germany, as its Lorenz curve was closer to the line of perfect equality.

2014: The income distribution in Belarus became more unequal than in Germany, as the gap between the Lorenz curves widened

Similarities

Both countries experienced an increase in income inequality over time, likely due to factors such as globalization, technological change, and changes in government policies.

Differences

Belarus: The more significant increase in income inequality may be attributed to the country’s transition to a market economy and the privatization of state-owned industries. Germany: The relatively smaller increase in income inequality could be due to the country’s strong social safety net, which provides support to low-income individuals.