Skip to content

Commit

Permalink
quick fix for var name change
Browse files Browse the repository at this point in the history
  • Loading branch information
TsaiLintung committed Aug 2, 2024
1 parent 30fe214 commit 9de9a95
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions R/fastdid.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ fastdid <- function(data,
validate_argument(dt, p)

# validate and throw away not legal data

setnames(dt, c(timevar, cohortvar, unitvar), c("time", "G", "unit"))
dt <- validate_dt(dt, p)


# preprocess -----------------------------------------------------------

#make dt conform to the WLOG assumptions of fastdid
Expand Down
1 change: 1 addition & 0 deletions R/validate.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ validate_argument <- function(dt, p){
validate_dt <- function(dt, p){

varnames <- unlist(p[str_ends(names(p), "var")], recursive = TRUE) #get all the argument that ends with "var"
varnames <- varnames[!varnames %in% c(p$timevar, p$unitvar, p$cohortvar)]

raw_unit_size <- dt[, uniqueN(unit)]
raw_time_size <- dt[, uniqueN(time)]
Expand Down
9 changes: 8 additions & 1 deletion development/did.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
library(did)
library(fastdid)

rm(list = ls());gc()

data(mpdta)
mpdta$x <- rnorm(nrow(mpdta))

#the unbalanced panel OR influence function calculation (DRDID::drdid_rc.R, 230, should be post - pre - or), since control function is subtracted
#simultaneous valid band, should subset t>g before getting the new critical value? (compute.aggte 376-383)

# did ---------

# repeated cross section with
out <- att_gt(yname="lemp",
Expand Down Expand Up @@ -46,3 +47,9 @@ for(est in c("dr", "ipw", "reg")){
rm(out, agg)
}
}

# fastdid ------------
mpdta <- as.data.table(mpdta)
setnames(mpdta, "first.treat", "firsttreat")
result <- fastdid(mpdta, timevar = "year", cohortvar = "firsttreat", unitvar = "countyreal",outcomevar = "lemp", result_type = "simple",
allow_unbalance_panel = FALSE, covariatesvar = "x")
5 changes: 5 additions & 0 deletions inst/tinytest/test_1_fastdid.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ expect_silent(fastdid(dt[G != 3], timevar = "time", cohortvar = "G", unitvar = "
expect_silent(fastdid(dt, timevar = "time", cohortvar = "G", unitvar = "unit",outcomevar = "y", result_type = "group_time", alpha = 0.01),
info = "alternative alpha")

dt2 <- copy(dt)
setnames(dt2, c("time", "G", "unit"), c("t", "g", "u"))
expect_silent(fastdid(dt2, timevar = "t", cohortvar = "g", unitvar = "u",outcomevar = "y", result_type = "group_time", alpha = 0.01),
info = "other column names")

# bootstrap part ------------------------

expect_silent(fastdid(dt, timevar = "time", cohortvar = "G", unitvar = "unit",outcomevar = "y", result_type = "group_time",
Expand Down

0 comments on commit 9de9a95

Please sign in to comment.