Skip to content

Commit 9de9a95

Browse files
committed
quick fix for var name change
1 parent 30fe214 commit 9de9a95

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

R/fastdid.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ fastdid <- function(data,
8585
validate_argument(dt, p)
8686

8787
# validate and throw away not legal data
88+
8889
setnames(dt, c(timevar, cohortvar, unitvar), c("time", "G", "unit"))
8990
dt <- validate_dt(dt, p)
9091

92+
9193
# preprocess -----------------------------------------------------------
9294

9395
#make dt conform to the WLOG assumptions of fastdid

R/validate.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ validate_argument <- function(dt, p){
5353
validate_dt <- function(dt, p){
5454

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

5758
raw_unit_size <- dt[, uniqueN(unit)]
5859
raw_time_size <- dt[, uniqueN(time)]

development/did.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
library(did)
2+
library(fastdid)
23

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

56
data(mpdta)
67
mpdta$x <- rnorm(nrow(mpdta))
78

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

11+
# did ---------
1112

1213
# repeated cross section with
1314
out <- att_gt(yname="lemp",
@@ -46,3 +47,9 @@ for(est in c("dr", "ipw", "reg")){
4647
rm(out, agg)
4748
}
4849
}
50+
51+
# fastdid ------------
52+
mpdta <- as.data.table(mpdta)
53+
setnames(mpdta, "first.treat", "firsttreat")
54+
result <- fastdid(mpdta, timevar = "year", cohortvar = "firsttreat", unitvar = "countyreal",outcomevar = "lemp", result_type = "simple",
55+
allow_unbalance_panel = FALSE, covariatesvar = "x")

inst/tinytest/test_1_fastdid.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ expect_silent(fastdid(dt[G != 3], timevar = "time", cohortvar = "G", unitvar = "
4545
expect_silent(fastdid(dt, timevar = "time", cohortvar = "G", unitvar = "unit",outcomevar = "y", result_type = "group_time", alpha = 0.01),
4646
info = "alternative alpha")
4747

48+
dt2 <- copy(dt)
49+
setnames(dt2, c("time", "G", "unit"), c("t", "g", "u"))
50+
expect_silent(fastdid(dt2, timevar = "t", cohortvar = "g", unitvar = "u",outcomevar = "y", result_type = "group_time", alpha = 0.01),
51+
info = "other column names")
52+
4853
# bootstrap part ------------------------
4954

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

0 commit comments

Comments
 (0)