fdid_prepare: Prepare Data for Factorial Difference-in-Differences Analysis

View source: R/fdid_prepare.R

fdid_prepareR Documentation

Prepare Data for Factorial Difference-in-Differences Analysis

Description

Prepares a dataset for factorial difference-in-differences (FDID) analysis by reshaping the data into a wide format, averaging time-varying covariates, and renaming columns for consistency in subsequent analysis.

Usage

fdid_prepare(
  data,
  Y_label,
  X_labels = NULL,
  G_label,
  unit_label,
  time_label,
  cluster_label = NULL
)

Arguments

data

A data frame containing the dataset to be processed.

Y_label

A string specifying the column name of the outcome variable.

X_labels

A character vector specifying the column names of the time-varying covariates.

G_label

A string specifying the column name of the group variable (e.g., treatment vs. control).

unit_label

A string specifying the column name of the unit identifier (e.g., individual or entity).

time_label

A string specifying the column name of the time variable.

cluster_label

An optional string specifying the column name of the clustering variable. Default is 'NULL'.

Value

A data frame in wide format with the following: - Outcome variable pivoted to wide format with time columns. - Time-varying covariates averaged across time. - Columns renamed: - Unit identifier -> 'unit' - Covariates -> 'x1', 'x2', ... - Group variable -> 'G' - Clustering variable (if provided) -> 'c'

Author(s)

Rivka Lipkovitz

Examples

data <- data.frame(
  id = rep(1:3, each = 4),
  time = rep(1:4, times = 3),
  outcome = rnorm(12),
  covar1 = runif(12),
  covar2 = runif(12),
  group = c(0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1)
)
fdid_data <- fdid_prepare(
  data = data,
  Y_label = "outcome",
  X_labels = c("covar1", "covar2"),
  G_label = "group",
  unit_label = "id",
  time_label = "time"
)
head(fdid_data)


fdid documentation built on March 23, 2026, 5:07 p.m.