Temporalities: Time series, panel and longitudinal data analysis
Aims
By the end of the session you will learn how to:
fit random-intercepts and random coefficients models to hierarchical data that contains a temporal dimension
use several R packages for modelling time-series data
Setup
Create a worksheet document
In Week 1 you set up R and RStudio, and an RProject folder (we called it “HSS8005_labs”) with an .R script and a .qmd or .Rmd document in it (we called these “Lab_1”). Ideally, you saved this on a cloud drive so you can access it from any computer (e.g. OneDrive). You will be working in this folder. If it’s missing, complete Exercise 3 from the Week 1 Worksheet.
Create a new Quarto markdown file (.qmd) for this session (e.g. “Lab_7.qmd”) and work in it to complete the exercises and report on your final analysis.
R packages
Code
# Just in case we get errors asking that the package repositories be explicitly set when installing new packages:options(repos =list(CRAN ="http://cran.rstudio.com/"))# Install and load required packages# We can use the {pacman} package to easily install and load several packages:# ({pacman} itself may need installing if not yet installed)pacman::p_load(tidyverse, sjlabelled, easystats, ggformula, ggeffects, marginaleffects, modelsummary, gtsummary,survey, sandwich, lmtest, lme4, # for general hierarchical modellingpanelr, plm, pglm)# for time-series hierarchical data structures
Exercise 1
For this exercise, work through the modelling of the Mitchell (2021) dataset carried out in Example 2 in the Notes.
Spend some time looking over the article and the dataset to understand the variables included.
The example in the Notes only focuses on specifying the different multilevel model specifications, but using the steps from the previous week and from Example 1 in the Notes, first create some summary descriptions of the data.
Exercise 2
No return to the models based on the Österman (2021) from the Week 6 worksheet and expand those models to also include the survey “round” variable (essround) as an additional level accounting for variation across rounds/time.
For this exercise, you cna combine the code from Exercise 1 above with that developed in Week 6.
Include these new models in a summary table to contract the results from the previous models and reflect on the differences.
Exercise 3
Using the hierarchical modelling functions from Exercise 1 above, develop an analysis using the simple toy dataset on student test scores from Example 1 in the Notes. You are free to construct your own model.
Österman, Marcus. 2021. “Can We Trust Education for Fostering Trust? Quasi-experimental Evidence on the Effect of Education and Tracking on Social Trust.”Social Indicators Research 154(1):211–33. doi: 10.1007/s11205-020-02529-y.