Converts a data set in panel form to matrix format required by synthdid estimators. A typical long panel date set looks like [unit, time, outcome, treatment]. Synthdid requires a balanced panel with simultaneous adoption of treatment: each unit must be observed at all times, and all treated units must begin treatment simultaneosly. This function creates num.units x num.time.periods matrices Y and W of outcomes and treatment indicators. In these matrices, columns are sorted by time, and by default (when treated.last=TRUE), rows for control units appear before those of treated units.

panel.matrices(
  panel,
  unit = 1,
  time = 2,
  outcome = 3,
  treatment = 4,
  treated.last = TRUE
)

Arguments

panel

A data.frame with columns consisting of units, time, outcome, and treatment indicator.

unit

The column number/name corresponding to the unit identifier. Default is 1.

time

The column number/name corresponding to the time identifier. Default is 2.

outcome

The column number/name corresponding to the outcome identifier. Default is 3.

treatment

The column number/name corresponding to the treatment status. Default is 4.

treated.last

Should we sort the rows of Y and W so treated units are last. If FALSE, sort by unit number/name. Default is TRUE.

Value

A list with entries Y: the data matrix, N0: the number of control units, T0: the number of time periods before treatment, W: the matrix of treatment indicators.

Examples

# \donttest{ # Load tobacco sales in long panel format. data("california_prop99") # Transform to N*T matrix format required for synthdid, # where N is the number of units and T the time periods. setup <- panel.matrices(california_prop99, unit = 1, time = 2, outcome = 3, treatment = 4) # Compute synthdid estimate synthdid_estimate(setup$Y, setup$N0, setup$T0)
#> synthdid: -15.604 +- NA. Effective N0/N0 = 16.4/38~0.4. Effective T0/T0 = 2.8/19~0.1. N1,T1 = 1,12.
# }