---
title: "Lab 1 - Intro to R and Survey Data"
author: "Your name"
date: "August 31, 2026"
format:
  html:
    theme: cosmo
editor_options:
  chunk_output_type: console
---

```{r setup, include=FALSE}
# DO NOT ALTER CODE IN THIS CHUNK
library(tidyverse)
library(haven)
library(labelled)
library(here)
```

* * *

# Guided Work

## Exercise 1: Import and inspect the Latino National Survey

```{r}
lns_raw <- read_dta(
  here("Labs", "case_study", "data", "lns_full.dta")
)

dim(lns_raw)
names(lns_raw)[1:20]
glimpse(lns_raw)
```

[How many respondents and variables are in the file? Enter your response here.]

## Exercise 2: Inspect labels and responses

```{r}
var_label(lns_raw$natprob)
val_labels(lns_raw$natprob)

lns_raw |>
  count(as_factor(natprob), sort = TRUE)
```

[Enter your response here.]

## Exercise 3: Create a small analysis file

```{r}
lns_clean <- lns_raw |>
  transmute(
    main_problem = as_factor(natprob),
    latino_problem = as_factor(latprob),
    generation = as_factor(newgen),
    age = as.numeric(age),
    female = as_factor(female),
    income = as_factor(income),
    poor_work = as_factor(poordisc),
    latino_work = as_factor(latdisc),
    discrimination_index = as.numeric(discindx)
  )

glimpse(lns_clean)
```

## Exercise 4: Handle missing responses

```{r}
lns_clean |>
  count(main_problem, sort = TRUE)

# Complete the recode after checking the exact value label

```

[Why should we preserve the original variable? Enter your response here.]

## Exercise 5: Filter and summarize

```{r}
young_adults <- lns_clean |>
  filter(age >= 18, age <= 29)

# Enter the remaining code here
```

[Interpret one result here.]

## Save the analysis file

```{r}
dir.create(
  here("Labs", "fall2026", "lab1", "output"),
  recursive = TRUE,
  showWarnings = FALSE
)

write_rds(
  lns_clean,
  here("Labs", "fall2026", "lab1", "output", "lns_clean.rds")
)
```

* * *

# On Your Own

Use `latino_problem`, which records the most important problem facing Latinos.

## 1. Inspect the variable

```{r}
# Enter your code here
```

[Enter your interpretation here.]

## 2. Create `latino_problem_analysis`

```{r}
# Enter your code here
```

[Explain your missing-data decision here.]

## 3. Select one generation group

```{r}
# Enter your code here
```

[Enter your interpretation here.]

## 4. Produce a substantive table

```{r}
# Enter your code here
```

[Enter your interpretation here.]

## 5. Document one analytical decision

[Enter your response here.]
