Author
library(here)
here() starts at /Users/kevinreuning/Library/CloudStorage/Dropbox/personal_website
source(here("blog/data/trust/GSS.r"))
GSS_metadata <- read.dct(here("blog/data/trust/GSS.dct"))
GSS_ascii <- read.dat(here("blog/data/trust/GSS.dat"), GSS_metadata)
attr(GSS_ascii, "col.label") <- GSS_metadata[["ColLabel"]]
GSS <- GSS_ascii

library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.0.4     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(srvyr)

Attaching package: 'srvyr'

The following object is masked from 'package:stats':

    filter
GSS |>
  mutate(
    Party = case_match(
      PARTYID,
      0:2 ~ "Democratic",
      c(3, 7) ~ "Indep/Other",
      4:7 ~ "Republican"
    ),
    Trust = case_match(
      TRUST,
      1 ~ "Most can be trusted",
      2 ~ "Can't be too carefull",
      3 ~ "It depends"
    )
  ) |>
  drop_na(Trust, Party) |>
  as_survey(weights = WTSSALL) |>
  group_by(YEAR, Party, Trust) |>
  summarize(survey_mean()) |>
  ggplot(aes(x = YEAR, y = coef, color = Trust)) +
  facet_wrap(~Party) +
  geom_smooth() +
  theme_minimal() +
  geom_pointrange(
    aes(ymin = coef - 1.96 * `_se`, ymax = coef + 1.96 * `_se`),
    alpha = 0.5
  ) +
  theme(legend.position = "bottom") +
  labs(x = "Year") +
  scale_y_continuous("", labels = scales::label_percent())
`geom_smooth()` using method = 'loess' and formula = 'y ~ x'