Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@
*.zip
*.dat
*.dta
kate_notebook.R
first_clean_pisa2000r.dta
filtered_pisa2000r.dta
55 changes: 55 additions & 0 deletions ko_first_clean_data_no_eth.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
library(haven) # Importing Stata datasets
library(dplyr)
library(labelled)

# Load in the reading scores dataset
datapath <- "DATA/PISA2000"
pisa <- read_dta(file.path(datapath, "pisa2000r.dta")) |> as_factor()

school_pisa <- read_dta("/Users/kateohara/Library/CloudStorage/OneDrive-UniversityofStirling/0_courses_seminars/lss_hackathon_2026/PISA2000/PISA2000_school_questionnaire.dta")

school_pisa_usa <- school_pisa |>
filter(cnt == "USA") |>
distinct(schoolid, .keep_all = TRUE)

uspisa <- pisa |>
filter(cnt == "USA") |> # Filter country early for performance
left_join(
school_pisa_usa |> select(schoolid, sc03q01, wnrschbw),
by = "schoolid"
) |>
rename(
grade = st02q01,
female = st03q01,
english = st17q01,
schooltype = sc03q01,
studentweight = w_fstuwt,
schoolweight = wnrschbw
) |>
filter(grade %in% c(9, 10)) |>
group_by(schoolid) |>
mutate(school_hisei = mean(hisei, na.rm = TRUE)) |>
ungroup()

# Keep only selected variables
uspisa_short <- uspisa |> select(
pv1read, pv2read, pv3read, pv4read, pv5read,
effper, belong,
grade, female, hisei, school_hisei,english, schooltype,
studentweight, schoolweight)


# Drop if missing on reading score, effper, and emote:
uspisa_short_nona <- uspisa_short |>
filter(
if_all(
c(pv1read, pv2read, pv3read, pv4read, pv5read),
\(x) x != "N/A" & !is.na(x)
),
belong != "N/A" & !is.na(belong),
effper != "N/A" & !is.na(effper)
)

final <- uspisa_short_nona
head(final)
write_dta(final, "first_clean_pisa2000r.dta")