suppressPackageStartupMessages(library(tidyverse))
d <- read_csv("data/democracy.csv", show_col_types=FALSE) |> rename_with(tolower)
maxT <- max(table(d$country))
cands <- d |> group_by(country, ctyname) |>
  summarise(always_aut = all(reg == 0, na.rm = TRUE),
            n_obs = n(),
            comp_y_reg = sum(!is.na(gdpw) & !is.na(reg)),
            comp_full  = sum(!is.na(gdpw) & !is.na(reg) & !is.na(edt)),
            last_obs = max(year), .groups="drop") |>
  filter(always_aut, n_obs == maxT, comp_y_reg == maxT)
print(cands)
