suppressPackageStartupMessages(library(tidyverse))
democracy <- read_csv("data/democracy.csv", show_col_types=FALSE) |>
  rename_with(tolower) |> mutate(ln_gdpw=log(gdpw))
maxT <- max(table(democracy$country))
cat("max T:", maxT, " total countries:", n_distinct(democracy$country), "\n")
keep <- democracy |> group_by(country) |>
  summarise(n_obs = n(), n_complete = sum(!is.na(ln_gdpw)), .groups="drop") |>
  filter(n_obs == maxT, n_complete == maxT)
cat("balanced+complete countries:", nrow(keep), "\n")
print(head(keep))
