In-Class Exercise 1 - Now you see it!

Published

January 13, 2024

Modified

February 2, 2024

Loading R packages

In this hands-on exercise, two R packages will be used. They are:

The code chunk used is as follows:

pacman::p_load(tidyverse, haven, DT)

Importing PISA data

The code chunk below uses ‘read_sas()’ of haven to import PISA data into R environment.

stu_qqq <- read_sas("data/cy08msp_stu_qqq.sas7bdat")

Upon first import, as the student questionaire data file contains data from other countries, we use filter() to filter the data file to only Singapore data.

stu_qqq_SG <- stu_qqq %>%
  filter(CNT == "SGP")

We use write_rds() to save the filtered datafile to a seperate file called stu_qqq_SG

write_rds(stu_qqq_SG,
          "data/stu_qqq_SG.rds")

For our analysis we shall read in data from stu_qqq_SG.rds using read_rds()

stu_qqq_SG <- read_rds("data/stu_qqq_SG.rds")
head(stu_qqq_SG)
# A tibble: 6 × 1,279
  CNT   CNTRYID CNTSCHID CNTSTUID CYC   NatCen STRATUM SUBNATIO REGION  OECD
  <chr>   <dbl>    <dbl>    <dbl> <chr> <chr>  <chr>   <chr>     <dbl> <dbl>
1 SGP       702 70200052 70200001 08MS  070200 SGP01   7020000   70200     0
2 SGP       702 70200134 70200002 08MS  070200 SGP01   7020000   70200     0
3 SGP       702 70200112 70200003 08MS  070200 SGP01   7020000   70200     0
4 SGP       702 70200004 70200004 08MS  070200 SGP01   7020000   70200     0
5 SGP       702 70200152 70200005 08MS  070200 SGP01   7020000   70200     0
6 SGP       702 70200043 70200006 08MS  070200 SGP01   7020000   70200     0
# ℹ 1,269 more variables: ADMINMODE <dbl>, LANGTEST_QQQ <dbl>,
#   LANGTEST_COG <dbl>, LANGTEST_PAQ <dbl>, Option_CT <dbl>, Option_FL <dbl>,
#   Option_ICTQ <dbl>, Option_WBQ <dbl>, Option_PQ <dbl>, Option_TQ <dbl>,
#   Option_UH <dbl>, BOOKID <dbl>, ST001D01T <dbl>, ST003D02T <dbl>,
#   ST003D03T <dbl>, ST004D01T <dbl>, ST250Q01JA <dbl>, ST250Q02JA <dbl>,
#   ST250Q03JA <dbl>, ST250Q04JA <dbl>, ST250Q05JA <dbl>, ST250D06JA <chr>,
#   ST250D07JA <chr>, ST251Q01JA <dbl>, ST251Q02JA <dbl>, ST251Q03JA <dbl>, …
sch_qqq <- read_sas("data/cy08msp_sch_qqq.sas7bdat")
sch_qqq_SG <- sch_qqq %>%
  filter(CNT == "SGP")
write_rds(sch_qqq_SG,
          "data/sch_qqq_SG.rds")
sch_qqq_SG <- read_rds("data/sch_qqq_SG.rds")
DT::datatable(sch_qqq_SG, class= "compact")
write.csv(sch_qqq_SG, "data/sch_qqq_SG.csv", row.names = FALSE)
Back to top