9.5 Long format data

  • Longformat: Observations of same units are stacked on top of each other
    • Row = unit \(\times\) time = observations
    • Columns: unit id, time and variables that are spread out (rarely variables are also stacked)
    • Table 9.2 below is “real” longformat accepted by most stat software
  • Use tidyr package (alternatives reshape package)
    • pivot_longer() to collect variables into one column, separate to generate two columns for variables and time (here separator is a “.”) and pivot_wider() to spread variables across columns keeping time column
    • To my knowledge pivot_longer(), pivot_wider() were introduced after neg. community feedback to replace gather() and spread()
Table 9.2: Long format
unit time trust Victimization
Paul 2006 5 0
Paul 2007 5 1
Pedro 2006 6 1
Pedro 2007 6 0
Peter 2006 1 0
Peter 2007 1 1