| fdid_prepare | R Documentation |
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.
fdid_prepare(
data,
Y_label,
X_labels = NULL,
G_label,
unit_label,
time_label,
cluster_label = NULL
)
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'. |
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'
Rivka Lipkovitz
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.