Skip to content

Instantly share code, notes, and snippets.

@soodoku
Created March 29, 2024 00:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soodoku/9df5b06a3865c4dfa7880cfeae38c0fb to your computer and use it in GitHub Desktop.
Save soodoku/9df5b06a3865c4dfa7880cfeae38c0fb to your computer and use it in GitHub Desktop.
Skew in Village Pop. in India With Implications for Optimal Strategy to Reach Out
library(readr)
shrug <- read_csv("/Users/soodoku/Downloads/shrug-vd11-csv/pc11_vd_clean_shrid.csv")
# Take out missing from village pop (just 1) and sort
t_pop <- shrug$pc11_vd_t_p[!is.na(shrug$pc11_vd_t_p)]
sorted_values <- sort(t_pop, decreasing = TRUE)
# We have like 570k villages. 50k villages have ...
sum(sorted_values[1:50000])/sum(sorted_values)
# [1] 0.3720554
# Let's do it more systematically
percentiles <- seq(10, 100, by = 10)
proportions <- length(percentiles)
for (i in seq_along(percentiles)) {
index <- round(length(sorted_values) * (percentiles[i]/100))
percentile_sum <- sum(sorted_values[1:index])
proportions[i] <- percentile_sum / sum(t_pop)
}
# Combine percentiles and proportions into a data frame for easier interpretation
result <- data.frame(Percentile = percentiles, Proportion = proportions)
# Print the result
print(result)
@soodoku
Copy link
Author

soodoku commented Mar 29, 2024

Screenshot 2024-03-28 at 5 26 21 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment