Skip to content

Better compatibility with other event study estimators #9

@kylebutts

Description

@kylebutts

From making did2s::event_study I noticed most functions use g = 0 as the never-treated group, but you all default to g = Inf. An easy fix is to allow for both by changing line 874 to:

df[, "g"] <-  df[,g] 
df[df$g == 0, "g"] <- Inf

processDF <- function(df, i, g, t, y){
#This function processes the df inputted to staggered (or staggered_cs/sa)
# It checks that the columns in the user-inputted values of i,g,t,y are actually in the data
# It also renames these columns to "i", "g", "t", "y"
# Let's make sure we have columns with name i, t, y and g
colnames_df <- colnames(df)
if(!i %in% colnames_df){
stop(paste0("There is no column ", i, " in the data. Thus, we are not able to find the unit identifier variable."))
}
if(!t %in% colnames_df){
stop(paste0("There is no column ", t, " in the data. Thus, we are not able to find the time identifier variable."))
}
if(!g %in% colnames_df){
stop(paste0("There is no column ", g, " in the data. Thus, we are not able to find the group identifier variable."))
}
if(!y %in% colnames_df){
stop(paste0("There is no column ", y, " in the data. Thus, we are not able to find the outcome variable."))
}
# Sanity checks
if(i %in% c("g", "t", "y" )){
stop(paste0("Unit identifier cannot be labeled g, t, or y"))
}
if(t %in% c("i","y", "g" )){
stop(paste0("Time identifier cannot be labeled i, g, or y"))
}
if(g %in% c("i", "t" ,"y" )){
stop(paste0("Group identifier cannot be labeled i, t, or y"))
}
# Re-label i, t, g, y
if(i != "i"){
df[,"i"] <- df[,i]
}
if(t != "t"){
df[, "t"] <- df[,t]
}
if(g != "g"){
df[, "g"] <- df[,g]
}
if(y != "y"){
df[, "y"] <- df[,y]
}
return(df)
}

If you want to be safe, in case y actually has year 0 for whatever reason

if(!any(0 %in% unique(df[, y])) {
    df[df$g == 0, "g"] <- Inf
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions