Project 1 — The Pew Data Brief

Replace with a title that states your finding

Author

Your Names (2–3 of you)

Published

August 18, 2026

About this file

This .qmd is the analysis. It imports the raw ATP file, does the wrangling, builds the analytic dataset, produces Table 1 and your figures, and computes the numbers your prose reports. There is no separate script hiding somewhere else.

Two habits make that possible:

  • Raw data stays raw. The .sav you download from Pew goes in data/raw/ and is never edited by hand. Anything derived from it is written by code into data/derived/.
  • Numbers come from R. Report values with inline R rather than typing them, so the prose cannot quietly drift away from the analysis. You used this in the labs: open with a backtick followed by the letter r, write your code, then close with a backtick — so a sentence can end with the live row count instead of a number you typed once and forgot to update.

Delete this section before you submit.

Setup

library(tidyverse)
library(here)
library(haven)      # read_sav() for the Pew .sav file
library(labelled)   # variable labels, zap_labels(), look_for()
library(gtsummary)  # Table 1
library(gt)         # table rendering
library(scales)     # axis and percent formatting

── Are you inside an RStudio project? ──────────────────────────────────────

here() resolves paths from the project root, and it only knows where that is

if an .Rproj file exists. The starter zip deliberately does not include one,

because RStudio names it after whatever your team calls the folder. If you

have not created it yet, this stops with a useful message instead of failing

later with a confusing “file not found”.

if (!any(grepl(“\.Rproj$”, list.files(here::here())))) { stop(“No .Rproj found at the project root. Create one first:”, “File > New Project > Existing Directory, pointing at this folder.”, “See the Project setup and reproducibility guide.”) }

Import the raw data

Read the ATP .sav from data/raw/. Do not modify the file on disk.

Paths are built with here(), just as in the labs: it starts from the folder containing the .Rproj and works the same on every teammate’s laptop. The main thing to change below is the filename.

# TODO: Import the raw ATP file. Uncomment this and replace the placeholder
# filename with your real one.
# raw_path <- here("data", "raw", "ATP_WXX.sav")
#
# This guard is worth keeping: it turns "file not found" into a useful
# instruction.
# stopifnot("raw file not found — see documentation/data-provenance.md" =
#             file.exists(raw_path))
#
# pew_raw <- read_sav(raw_path)

# TODO: Confirm that the row count matches what Pew's documentation reports
# for this wave, and note any difference in documentation/data-provenance.md.

Build the analytic dataset

Every recode, filter, and derived variable belongs here — and each one should also be documented in documentation/codebook.csv. Pew codes missing responses as values like 99; decide what each one means before you convert anything.

# TODO: Build the analytic dataset from pew_raw.
# analytic <-
#   pew_raw |>
#   select(...) |>        # keep only what your question needs
#   mutate(...)           # missing-value codes to NA, recodes, derived variables
#
# Decide what each Pew missing code means BEFORE converting it, and record
# that decision in documentation/codebook.csv.

# TODO: Check the result before trusting it. A quick assertion here is often
# the difference between catching a problem early and discovering it after a
# table or figure looks strange.
# stopifnot(
#   "analytic sample is empty" = nrow(analytic) > 0
#   # add the checks that matter for YOUR data: expected row count after
#   # exclusions, factor levels spelled as you expect, no leftover 99s
# )
# TODO: Save the analytic dataset. The rest of this document — and your
# teammates — work from this one file. It is rebuilt every time the document
# renders, so it is never edited by hand and never committed.
# write_rds(analytic, here("data", "derived", "analytic.rds"))

The question

State the descriptive question in one or two sentences, and say who would benefit from knowing the answer. Keep this section grounded in the question you set out to answer, not the result you eventually found.

Measurement

Trace your focal construct from the survey item to the analytic variable: what respondents were actually asked, how you recoded it, and one real limitation of measuring the construct this way.

Data and analytic sample

Name the wave and field dates, how many people it surveyed, how many are in your analytic sample, and what happened to everyone else. Every percentage later in this document should have a denominator that a reader can find here.

# TODO: report the starting N, the N after each exclusion, and the final N

Table 1

Describe the analytic sample — the people you actually analyzed.

# TODO: build Table 1 with gtsummary, labelled variables, and a stated denominator

What we found

Finding 1

# TODO: the headline figure — readable on its own, title states the finding

Finding 2

# TODO: the figure that qualifies, compares, or complicates Finding 1

What the findings mean

Explain what the evidence supports, and what it does not. Be specific to this sample and this measure — the goal here is not to list generic caveats, but to name the real limits that matter for your analysis.

Reproducibility information

Session information
sessionInfo()
R version 4.5.2 (2025-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Tahoe 26.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.1

locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8

time zone: America/Denver
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] scales_1.4.0    gt_1.1.0        gtsummary_2.4.0 labelled_2.15.0
 [5] haven_2.5.5     here_1.0.2      lubridate_1.9.4 forcats_1.0.1  
 [9] stringr_1.6.0   dplyr_1.1.4     purrr_1.2.1     readr_2.2.0    
[13] tidyr_1.3.2     tibble_3.3.1    ggplot2_4.0.3   tidyverse_2.0.0

loaded via a namespace (and not attached):
 [1] gtable_0.3.6       jsonlite_2.0.0     compiler_4.5.2     tidyselect_1.2.1  
 [5] xml2_1.5.2         yaml_2.3.12        fastmap_1.2.0      R6_2.6.1          
 [9] generics_0.1.4     knitr_1.51         htmlwidgets_1.6.4  rprojroot_2.1.1   
[13] pillar_1.11.1      RColorBrewer_1.1-3 tzdb_0.5.0         rlang_1.3.0       
[17] stringi_1.8.7      xfun_0.56          fs_1.6.6           S7_0.2.1          
[21] otel_0.2.0         timechange_0.3.0   cli_3.6.6          withr_3.0.3       
[25] magrittr_2.0.5     digest_0.6.39      grid_4.5.2         hms_1.1.4         
[29] lifecycle_1.0.5    vctrs_0.7.3        evaluate_1.0.5     glue_1.8.1        
[33] farver_2.1.2       rmarkdown_2.30     tools_4.5.2        pkgconfig_2.0.3   
[37] htmltools_0.5.9