diff --git a/NAMESPACE b/NAMESPACE
index fd33f63..436b40a 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -14,7 +14,6 @@ export(attgt_if)
export(attgt_noif)
export(attgt_pte_aggregations)
export(compute.pte)
-export(compute.pte2)
export(crit_val_checks)
export(did_attgt)
export(dose_obj)
@@ -28,8 +27,9 @@ export(mboot2)
export(overall_weights)
export(panel_empirical_bootstrap)
export(process_att_gt)
+export(process_dose_gt)
export(pte)
-export(pte2)
+export(pte_aggte)
export(pte_attgt)
export(pte_default)
export(pte_dose_results)
diff --git a/R/attgt_functions.R b/R/attgt_functions.R
index 93dae60..f0064c1 100644
--- a/R/attgt_functions.R
+++ b/R/attgt_functions.R
@@ -1,4 +1,5 @@
-#' @title did_attgt
+#' @title Difference-in-differences estimates of ATT(g,t), given a group g and
+#' time period t.
#'
#' @description Takes a "local" data.frame and computes
#' an estimate of a group time average treatment effect
@@ -65,7 +66,8 @@ did_attgt <- function(gt_data, xformula = ~1, ...) {
}
-#' @title pte_attgt
+#' @title A flexible way to estimate ATT(g,t) using difference-in-differences or
+#' lagged outcome unconfoundedness, for a particular group and time period
#'
#' @description `pte_attgt` takes a "local" data.frame and computes
#' an estimate of a group time average treatment effect
diff --git a/R/classes.R b/R/classes.R
index 7718e76..fbf1171 100644
--- a/R/classes.R
+++ b/R/classes.R
@@ -1,4 +1,5 @@
-#' @title group_time_att
+#' @title Class that holds causal effect parameter estimates across
+#' timing groups and time periods
#'
#' @description group_time_att class
#'
@@ -131,7 +132,8 @@ print.group_time_att <- function(x, ...) {
}
-#' @title pte_results
+#' @title Class for holding overall results with a staggered treatment,
+#' including an overall ATT and an event study
#'
#' @description class for holding pte results
#'
@@ -160,7 +162,7 @@ pte_results <- function(att_gt,
#' @title summary.pte_results
#'
-#' @description A function to summarize \code{pte} results.
+#' @description A function to summarize `ptetools` results.
#'
#' @param object an \code{pte_results} object
#' @param ... other arguments
@@ -289,7 +291,8 @@ print.summary.pte_results <- function(x, ...) {
cat("\n\n")
}
-#' @title attgt_if
+#' @title Class for holding returns from group-time specific estimates
+#' in settings when an influence function is returned
#'
#' @description Class for holding group-time average treatment effects
#' along with their influence function
@@ -312,7 +315,8 @@ attgt_if <- function(attgt, inf_func, extra_gt_returns = NULL) {
out
}
-#' @title attgt_noif
+#' @title Class for holding returns from group-time specific estimates
+#' in settings when an influence function is not returned
#'
#' @description Class for holding group-time average treatment effects
#' which don't include influence functions
@@ -329,7 +333,8 @@ attgt_noif <- function(attgt, extra_gt_returns = NULL) {
}
-#' @title gt_data_frame
+#' @title Checks if data satisfies criteria to be used in internal
+#' `ptetools` functions
#'
#' @description function to take in a data.frame, check if it has the right
#' columns to be used to calculate a group-time average treatment effect,
@@ -354,9 +359,9 @@ gt_data_frame <- function(data) {
data
}
-#' @title pte_emp_boot
+#' @title Class to hold empirical bootstrap results
#'
-#' @title Class for holding \code{pte} empirical bootstrap results
+#' @description Class for holding `ptetools` empirical bootstrap results
#'
#' @param attgt_results \code{data.frame} holding attgt results
#' @param overall_results \code{data.frame} holding overall results
@@ -471,7 +476,7 @@ summary.pte_emp_boot <- function(object, ...) {
}
-#' @title pte_dose_results
+#' @title Class for holding results with a continuous treatment
#'
#' @description class for holding pte results
#'
@@ -479,6 +484,7 @@ summary.pte_emp_boot <- function(object, ...) {
#' @param dose vector of doses
#' @param att_d ATT(d) for each value of `dose`
#' @param acrt_d ACRT(d) for each value of `dose`
+#' @param ptep a `pte_params` object
#'
#' @export
pte_dose_results <- function(att_gt,
diff --git a/R/empirical_bootstrap.R b/R/empirical_bootstrap.R
index 66091ba..37bbf6c 100644
--- a/R/empirical_bootstrap.R
+++ b/R/empirical_bootstrap.R
@@ -3,7 +3,7 @@
#' @description Computes empirical bootstrap pointwise standard errors
#'
#' @inheritParams compute.pte
-#' @inheritParams pte2
+#' @inheritParams pte
#' @inheritParams attgt_if
#' @param attgt.list list of attgt results from \code{compute.pte}
#'
diff --git a/R/ggpte.R b/R/ggpte.R
index efca0ac..edcc20a 100644
--- a/R/ggpte.R
+++ b/R/ggpte.R
@@ -1,6 +1,9 @@
-#' @title ggpte
+#' @title The main plotting function in the `ptetools` package. It plots
+#' event studies.
#'
-#' @description Simple event study plots for panel treatment effects
+#' @description Simple event study plots for panel treatment effects. This
+#' function is generic enough that most packages that otherwise use
+#' the `ptetools` package can call it directly to plot an event study.
#'
#' @param pte_results A \code{pte_results} object
#'
@@ -19,7 +22,7 @@ ggpte <- function(pte_results) {
}
-#' @title ggpte_cont
+#' @title Plots dose-specific results in applications with a continuous treatment
#'
#' @description a function for plotting results in applications with a continuous treatment
#'
diff --git a/R/process_dose_gt.R b/R/process_dose_gt.R
index 861f531..2b4c0a2 100644
--- a/R/process_dose_gt.R
+++ b/R/process_dose_gt.R
@@ -1,3 +1,19 @@
+#' @title Processes results from each group and time period in settings
+#' with a continuous treatment.
+#'
+#' @description After computing results for each group and time period,
+#' `process_dose_gt` combines/averages them into overall effects and/or
+#' dose specific effects. This is generic code that can be used
+#' from different ways of estimating causal effects across different
+#' timing groups and periods in a previous step.
+#'
+#' @inheritParams process_att_gt
+#' @inheritParams pte_results
+#'
+#' @param gt_results list of group-time specific results
+#' @param ... extra arguments
+#'
+#' @export
process_dose_gt <- function(gt_results, ptep, ...) {
# make the call to att, to get same format of results
att_gt <- process_att_gt(gt_results, ptep)
@@ -108,7 +124,7 @@ process_dose_gt <- function(gt_results, ptep, ...) {
)
}
-#' @title dose_obj
+#' @title An object that holds results when there is a continuous treatment
#'
#' @description Holds results from computing dose-specific treatment effects
#' with a continuous treatment
diff --git a/R/pte.R b/R/pte.R
index dc3f5c2..e0ed17a 100644
--- a/R/pte.R
+++ b/R/pte.R
@@ -1,145 +1,20 @@
#' @title compute.pte
#'
-#' @description Function that actually computes panel treatment effects
-#'
-#' @inheritParams pte
-#' @param ptep \code{pte_params} object
-#'
-#' @return list of attgt results and, sometimes, and influence function
-#'
-#' @export
-compute.pte <- function(ptep,
- subset_fun,
- attgt_fun,
- ...) {
- #-----------------------------------------------------------------------------
- # unpack ptep
- #-----------------------------------------------------------------------------
- data <- ptep$data
- yname <- ptep$yname
- gname <- ptep$gname
- idname <- ptep$idname
- tname <- ptep$tname
- base_period <- ptep$base_period
- anticipation <- ptep$anticipation
-
- data <- as.data.frame(data)
-
- # setup data
- G <- data[, gname]
- id <- data[, idname]
- period <- data[, tname]
- n <- length(unique(data$id))
-
- # pick up all time periods
- time.periods <- ptep$tlist
-
- # sort the groups and drop the untreated group
- groups <- ptep$glist
-
- # list to store all group-time average treatment effects
- # that we calculate
- attgt.list <- list()
- counter <- 1
- nG <- length(groups)
- nT <- length(time.periods)
- inffunc <- matrix(data = NA, nrow = n, ncol = nG * (nT))
-
- # list to hold extra results from gt-specific calculations
- extra_gt_returns <- list()
-
- # loop over all groups
- for (g in groups) {
- # loop over all time periods
- for (tp in time.periods) {
- if (isTRUE(base_period == "universal")) {
- if (tp == (g - 1 - anticipation)) {
- attgt.list[[counter]] <- list(
- att = 0,
- group = g,
- time.period = tp
- )
-
- extra_gt_returns[[counter]] <- list(
- extra_gt_returns = NULL,
- group = g,
- time.period = tp
- )
- counter <- counter + 1
- next
- }
- }
- #-----------------------------------------------------------------------------
- # code to get the right subset of the data
- #-----------------------------------------------------------------------------
- gt_subset <- subset_fun(data, g, tp, ...)
- gt_data <- gt_subset$gt_data
- n1 <- gt_subset$n1
- disidx <- gt_subset$disidx
-
- #-----------------------------------------------------------------------------
- # code to estimate attgt using correct relevant data
- #-----------------------------------------------------------------------------
- attgt <- attgt_fun(gt_data = gt_data, ...)
-
-
- #-----------------------------------------------------------------------------
- # process attgt results
- # - branch based on whether or not attgt_fun returned an influence
- # function
- #-----------------------------------------------------------------------------
-
- # save results
- attgt.list[[counter]] <- list(
- att = attgt$attgt,
- group = g,
- time.period = tp
- )
-
- extra_gt_returns[[counter]] <- list(
- extra_gt_returns = attgt$extra_gt_returns,
- group = g,
- time.period = tp
- )
-
-
- # code if influence function is available
- if (!is.null(attgt$inf_func)) {
- # adjust for relative sizes of overall data
- # and groups used for this attgt
- attgt$inf_func <- (n / n1) * attgt$inf_func
-
- this.inf_func <- rep(0, n)
- this.inf_func[disidx] <- attgt$inf_func
- inffunc[, counter] <- this.inf_func
- }
-
- # cat("counter: ", counter, "\n")
- counter <- counter + 1
- #----------------------------------------------------
- }
- }
-
- return(list(attgt.list = attgt.list, inffunc = inffunc, extra_gt_returns = extra_gt_returns))
-}
-
-#' @title compute.pte2
-#'
#' @description Function that actually computes panel treatment effects.
#' The difference relative to \code{compute.pte} is that this function
#' loops over time periods first (instead of groups) and tries to
#' estimate model for untreated potential outcomes jointly for all groups.
#'
-#' @inheritParams pte2
+#' @inheritParams pte
#' @param ptep \code{pte_params} object
#'
#' @return list of attgt results and, sometimes, an influence function
#'
#' @export
-compute.pte2 <- function(ptep,
- subset_fun,
- attgt_fun,
- ...) {
+compute.pte <- function(ptep,
+ subset_fun,
+ attgt_fun,
+ ...) {
#-----------------------------------------------------------------------------
# unpack ptep
#-----------------------------------------------------------------------------
@@ -258,7 +133,6 @@ compute.pte2 <- function(ptep,
return(list(attgt.list = attgt.list, inffunc = inffunc, extra_gt_returns = extra_gt_returns))
}
-
#' @title pte
#'
#' @description Main function for computing panel treatment effects
@@ -331,13 +205,19 @@ compute.pte2 <- function(ptep,
#' to figure out). If no influence function is provided, then the \code{pte}
#' package will use the empirical bootstrap no matter what the value of this
#' parameter.
-#' @param gt_type is the type of result that is computed for each group and
-#' time period. The default choice is "att" is this is (by far) the most
-#' common choice. The other option is "dtt", which stands for distribution
-#' treatment effect on the treated. In this case, the attgt_fun should
-#' return a vector of counterfactual outcomes for each unit in the data, from
-#' which a counterfactual distribution can be computed. Additional arguments
-#' will often need to be provided in this case.
+#'
+#' @param process_dtt_gt_fun An optional function to customize results when
+#' the gt-specific function returns the distribution of treated and untreated
+#' potential outcomes. The default is `process_dtt_gt`, which is a function
+#' provided by the package. See that function for an example of what this function
+#' should return. This is unused is unused except in cases where
+#' the results involve distributions.
+#'
+#' @param process_dose_gt_fun An optional function to customize results when the gt-specific
+#' function returns treatment effects that depend on dose (i.e., amount of the
+#' treatment). The default is `process_dose_gt`, which is a function provided
+#' by the package. See that function for an example of what this function should
+#' return. This is unused except in cases where the results involve doses.
#'
#' @param ... extra arguments that can be passed to create the correct subsets
#' of the data (depending on \code{subset_fun}), to estimate group time
@@ -360,206 +240,17 @@ pte <- function(yname,
alp = 0.05,
boot_type = "multiplier",
weightsname = NULL,
- biters = 100,
- cl = 1,
gt_type = "att",
ret_quantile = NULL,
+ global_fun = FALSE,
+ time_period_fun = FALSE,
+ group_fun = FALSE,
+ process_dtt_gt_fun = process_dtt_gt,
+ process_dose_gt_fun = process_dose_gt,
+ biters = 100,
+ cl = 1,
+ call = NULL,
...) {
- .Deprecated("pte2")
-
- ptep <- setup_pte_fun(
- yname = yname,
- gname = gname,
- tname = tname,
- idname = idname,
- data = data,
- cband = cband,
- alp = alp,
- boot_type = boot_type,
- weightsname = weightsname,
- gt_type = gt_type,
- ret_quantile = ret_quantile,
- biters = biters,
- cl = cl,
- ...
- )
-
- res <- compute.pte(
- ptep = ptep,
- subset_fun = subset_fun,
- attgt_fun = attgt_fun,
- ...
- )
-
- # check if no influence function provided,
- # if yes, go to alternate code for empirical
- # bootstrap
- if (all(is.na(res$inffunc)) | ptep$boot_type == "empirical") {
- return(panel_empirical_bootstrap(res$attgt.list,
- ptep,
- setup_pte_fun,
- subset_fun,
- attgt_fun,
- extra_gt_returns = res$extra_gt_returns,
- ...
- ))
- }
-
- att_gt <- process_att_gt(res, ptep)
-
- #-----------------------------------------------------------------------------
- # aggregate ATT(g,t)'s
- #-----------------------------------------------------------------------------
-
- # overall
- overall_att <- pte_aggte(att_gt, type = "group", bstrap = TRUE, cband = cband, alp = ptep$alp)
-
- # event study
- # ... for max_e and min_e
- dots <- list(...)
- min_e <- ifelse(is.null(dots$min_e), -Inf, dots$min_e)
- max_e <- ifelse(is.null(dots$max_e), Inf, dots$max_e)
- balance_e <- dots$balance_e
-
- event_study <- pte_aggte(att_gt,
- type = "dynamic",
- bstrap = TRUE,
- cband = cband,
- alp = ptep$alp,
- min_e = min_e,
- max_e = max_e,
- balance_e = balance_e
- )
-
- # output
- out <- pte_results(
- att_gt = att_gt,
- overall_att = overall_att,
- event_study = event_study,
- ptep = ptep
- )
-
- out
-}
-
-
-#' @title pte2
-#'
-#' @description Main function for computing panel treatment effects
-#'
-#' @inheritParams pte_params
-#' @param setup_pte_fun This is a function that should take in \code{data},
-#' \code{yname} (the name of the outcome variable in \code{data}),
-#' \code{gname} (the name of the group variable),
-#' \code{idname} (the name of the id variable),
-#' and possibly other arguments such as the significance level \code{alp},
-#' the number of bootstrap iterations \code{biters}, and how many clusters
-#' for parallel computing in the bootstrap \code{cl}. The key thing that
-#' needs to be figured out in this function is which groups and time periods
-#' ATT(g,t) should be computed in. The function should
-#' return a \code{pte_params} object which contains all of the parameters
-#' passed into the function as well as \code{glist} and \code{tlist} which
-#' should be ordered lists of groups and time periods for ATT(g,t) to be computed.
-#'
-#' This function provides also provides a good place for error handling related
-#' to the types of data that can be handled.
-#'
-#' The \code{pte} package contains the function \code{setup_pte} that is
-#' a lightweight function that basically just takes the data, omits
-#' the never-treated group from \code{glist} but includes all other groups
-#' and drops the first time period. This works in cases where ATT would
-#' be identified in the 2x2 case (i.e., where there are two time periods,
-#' no units are treated in the first period and the identification strategy
-#' "works" with access to a treated and untreated group and untreated
-#' potential outcomes for both groups in the first period) --- for example,
-#' this approach works if DID is the identification strategy.
-#'
-#' @param subset_fun This is a function that should take in \code{data},
-#' \code{g} (for group), \code{tp} (for time period), and \code{...}
-#' and be able to return the appropriate \code{data.frame} that can be used
-#' by \code{attgt_fun} to produce ATT(g=g,t=tp). The data frame should
-#' be constructed using \code{gt_data_frame} in order to guarantee that
-#' it has the appropriate columns that identify which group an observation
-#' belongs to, etc.
-#' @param attgt_fun This is a function that should work in the case where
-#' there is a single group and the "right" number of time periods to
-#' recover an estimate of the ATT. For example, in the contest of
-#' difference in differences, it would need to work for a single group,
-#' find the appropriate comparison group (untreated units), find the right
-#' time periods (pre- and post-treatment), and then recover an estimate
-#' of ATT for that group. It will be called over and over separately
-#' by groups and by time periods to compute ATT(g,t)'s.
-#'
-#' The function needs to work in a very specific way. It should take in the
-#' arguments: \code{data}, \code{...}. \code{data} should be constructed
-#' using the function \code{gt_data_frame} which checks to make sure
-#' that \code{data} has the correct columns defined.
-#' \code{...} are additional arguments (such as
-#' formulas for covariates) that \code{attgt_fun} needs. From these arguments
-#' \code{attgt_fun} must return a list with element \code{ATT} containing the
-#' group-time average treatment effect for that group and that time period.
-#'
-#' If \code{attgt_fun} returns an influence function (which should be provided
-#' in a list element named \code{inf_func}), then the code will use the
-#' multiplier bootstrap to compute standard errors for group-time average
-#' treatment effects, an overall treatment effect parameter, and a dynamic
-#' treatment effect parameter (i.e., event study parameter). If
-#' \code{attgt_fun} does not return an influence function, then the same
-#' objects will be computed using the empirical bootstrap. This is usually
-#' (perhaps substantially) easier to code, but also will usually be (perhaps
-#' substantially) computationally slower.
-#'
-#' @param boot_type should be one of "multiplier" (the default) or "empirical".
-#' The multiplier bootstrap is generally much faster, but \code{attgt_fun} needs
-#' to provide an expression for the influence function (which could be challenging
-#' to figure out). If no influence function is provided, then the \code{pte}
-#' package will use the empirical bootstrap no matter what the value of this
-#' parameter.
-#'
-#' @param process_dtt_gt_fun An optional function to customize results when
-#' the gt-specific function returns the distribution of treated and untreated
-#' potential outcomes. The default is `process_dtt_gt`, which is a function
-#' provided by the package. See that function for an example of what this function
-#' should return. This is unused is unused except in cases where
-#' the results involve distributions.
-#'
-#' @param process_dose_gt_fun An optional function to customize results when the gt-specific
-#' function returns treatment effects that depend on dose (i.e., amount of the
-#' treatment). The default is `process_dose_gt`, which is a function provided
-#' by the package. See that function for an example of what this function should
-#' return. This is unused except in cases where the results involve doses.
-#'
-#' @param ... extra arguments that can be passed to create the correct subsets
-#' of the data (depending on \code{subset_fun}), to estimate group time
-#' average treatment effects (depending on \code{attgt_fun}), or to
-#' aggregating treatment effects (particularly useful are \code{min_e},
-#' \code{max_e}, and \code{balance_e} arguments to event study aggregations)
-#'
-#' @return \code{pte_results} object
-#'
-#' @export
-pte2 <- function(yname,
- gname,
- tname,
- idname,
- data,
- setup_pte_fun,
- subset_fun,
- attgt_fun,
- cband = TRUE,
- alp = 0.05,
- boot_type = "multiplier",
- weightsname = NULL,
- gt_type = "att",
- ret_quantile = NULL,
- global_fun = FALSE,
- time_period_fun = FALSE,
- group_fun = FALSE,
- process_dtt_gt_fun = process_dtt_gt,
- process_dose_gt_fun = process_dose_gt,
- biters = 100,
- cl = 1,
- ...) {
ptep <- setup_pte_fun(
yname = yname,
gname = gname,
@@ -577,10 +268,11 @@ pte2 <- function(yname,
group_fun = group_fun,
biters = biters,
cl = cl,
+ call = call,
...
)
- res <- compute.pte2(
+ res <- compute.pte(
ptep = ptep,
subset_fun = subset_fun,
attgt_fun = attgt_fun,
@@ -643,7 +335,10 @@ pte2 <- function(yname,
out
}
-#' @title pte_default
+#' @title Default, highly generic function for computing causal effects with
+#' staggered treatment adoption
+#'
+#' @name pte_default
#'
#' @description This is a generic/example wrapper for a call to the `pte` function.
#'
@@ -676,7 +371,7 @@ pte_default <- function(yname,
boot_type = "multiplier",
biters = 100,
cl = 1) {
- res <- pte2(
+ res <- pte(
yname = yname,
gname = gname,
tname = tname,
diff --git a/R/pte_aggte.R b/R/pte_aggte.R
index d8edea1..0ae025b 100644
--- a/R/pte_aggte.R
+++ b/R/pte_aggte.R
@@ -1,4 +1,5 @@
-#' @title pte_aggte
+#' @title Aggregates group-time specific effects into either an overall estimate
+#' or an event study
#'
#' @description This is a slight edit of the aggte function from the `did` package.
#' Currently, it only provides aggregations for "overall" treatment effects
@@ -9,7 +10,19 @@
#' assignment nor from the covariates).
#'
#' @param attgt A group_time_att object to be aggregated
-#' @param type The type of aggregation to be done. Default is "overall"
+#' @param type The type of aggregation to be done. Default is "overall".
+#' @param balance_e Drops groups that do not have at least `balance_e` periods
+#' of post-treatment data. This keeps the composition of groups constant
+#' across different event times in an event study.
+#' Default is NULL, in which case this is ignored.
+#' @param min_e The minimum event time computed in the event study results.
+#' This is useful when there are a huge number of pre-treatment periods.
+#' @param max_e The maximum event time computed in the event study results.
+#' This is useful when there are a huge number of post-treatment periods.
+#' @param ... extra arguments
+#'
+#' @return an `aggte_obj`
+#' @export
pte_aggte <- function(attgt,
type = "overall",
balance_e = NULL,
@@ -155,7 +168,6 @@ pte_aggte <- function(attgt,
selective.inf.func.g = selective.inf.func.g,
selective.inf.func = selective.inf.func
),
- call = call,
DIDparams = attgt
))
} else if (type == "dynamic") {
@@ -255,7 +267,6 @@ pte_aggte <- function(attgt,
dynamic.inf.func.e = dynamic.inf.func.e,
dynamic.inf.func = dynamic.inf.func
),
- call = call,
min_e = min_e,
max_e = max_e,
balance_e = balance_e,
@@ -359,7 +370,8 @@ getSE <- function(thisinffunc, bstrap = TRUE, biters = 100, alp = .05) {
}
-#' @title overall_weights
+#' @title Computes weights across post-treatment groups and time periods to
+#' deliver overall treatment effect parameters
#'
#' @description A function that returns weights on gt's to deliver overall
#' (averaged across groups and time periods) treatment effect parameters
@@ -447,7 +459,8 @@ overall_weights <- function(attgt,
)
}
-#' @title crit_val_checks
+#' @title Performs sanity checks on critical values for forming uniform
+#' confidence bands
#'
#' @description A function to perform sanity checks and possibly adjust a
#' a critical value to form a uniform confidence band
@@ -480,7 +493,7 @@ crit_val_checks <- function(crit_val, alp = 0.05) {
-#' @title aggte_obj
+#' @title Object to hold aggregated treatment effect results
#'
#' @description Objects of this class hold results on aggregated
#' group-time average treatment effects. This is derived from the AGGTEobj
@@ -517,7 +530,6 @@ aggte_obj <- function(overall.att = NULL,
min_e = NULL,
max_e = NULL,
balance_e = NULL,
- call = NULL,
DIDparams = NULL) {
out <- list(
overall.att = overall.att,
@@ -531,7 +543,6 @@ aggte_obj <- function(overall.att = NULL,
min_e = min_e,
max_e = max_e,
balance_e = balance_e,
- call = call,
DIDparams = DIDparams
)
@@ -644,7 +655,7 @@ summary.aggte_obj <- function(object, ...) {
# estimation method text
est_method <- object$DIDparams$est_method
- if (is(est_method, "character")) {
+ if (inherits(est_method, "character")) {
est_method_text <- est_method
if (est_method == "dr") {
est_method_text <- "Doubly Robust"
diff --git a/R/pte_params.R b/R/pte_params.R
index 12d2a22..c5821c6 100644
--- a/R/pte_params.R
+++ b/R/pte_params.R
@@ -1,7 +1,8 @@
-#' @title Example setup panel treatment effects parameters
+#' @title Example function to setup data for using subsequent functions in
+#' the `ptetools` package
#'
#' @description This is a lightweight (example) function for how to setup
-#' the data to be used in the \code{pte} package.
+#' the data to be used in the \code{ptetools} package.
#'
#' \code{setup_pte_basic} takes in information about the structure of \code{data}
#' and returns a \code{pte_params} object. The key piece of information
@@ -37,6 +38,7 @@ setup_pte_basic <- function(yname,
ret_quantile = 0.5,
biters = 100,
cl = 1,
+ call = NULL,
...) {
data <- as.data.frame(data)
@@ -74,17 +76,18 @@ setup_pte_basic <- function(yname,
gt_type = gt_type,
ret_quantile = ret_quantile,
biters = biters,
- cl = cl
+ cl = cl,
+ call = call
)
params
}
-#' @title Setup panel treatment effects parameters
+#' @title A function for setting up data, etc. to use the `ptetools` package
#'
#' @description This is a function for how to setup
-#' the data to be used in the \code{pte} package.
+#' the data to be used in the \code{ptetools} package.
#'
#' The \code{setup_pte} function builds on \code{setup_pte_basic} and
#' attempts to provide a general purpose function (with error handling)
@@ -115,6 +118,7 @@ setup_pte <- function(yname,
ret_quantile = 0.5,
biters = 100,
cl = 1,
+ call = NULL,
...) {
data <- as.data.frame(data)
@@ -207,16 +211,17 @@ setup_pte <- function(yname,
gt_type = gt_type,
ret_quantile = ret_quantile,
biters = biters,
- cl = cl
+ cl = cl,
+ call = call
)
params
}
-#' @title pte_params
+#' @title An object to carry around parameters in the `ptetools` package
#'
-#' @description Objects that contain pte parameters
+#' @description Object that contain pte parameters
#'
#' @param yname Name of outcome in \code{data}
#' @param gname Name of group in \code{data}
@@ -264,6 +269,7 @@ setup_pte <- function(yname,
#' These functions aim at reducing or eliminating running the same code multiple times.
#' @param biters number of bootstrap iterations; default is 100
#' @param cl number of clusters to be used when bootstrapping; default is 1
+#' @param call keeps track of through the `call` from external functions/packages
#'
#' @export
pte_params <- function(yname,
@@ -286,7 +292,8 @@ pte_params <- function(yname,
time_period_fun = FALSE,
group_fun = FALSE,
biters,
- cl) {
+ cl,
+ call = NULL) {
obj <- list(
yname = yname,
gname = gname,
@@ -305,7 +312,8 @@ pte_params <- function(yname,
gt_type = gt_type,
ret_quantile = ret_quantile,
biters = biters,
- cl = cl
+ cl = cl,
+ call = call
)
class(obj) <- "pte_params"
diff --git a/README.md b/README.md
index 3ce9fd4..48d08bb 100644
--- a/README.md
+++ b/README.md
@@ -89,18 +89,18 @@ summary(did_res)
#>
#> Overall ATT:
#> ATT Std. Error [ 95% Conf. Int.]
-#> -0.0323 0.0146 -0.0609 -0.0036 *
+#> -0.0305 0.0123 -0.0546 -0.0063 *
#>
#>
#> Dynamic Effects:
#> Event Time Estimate Std. Error [95% Conf. Band]
-#> -3 0.0269 0.0141 -0.0106 0.0645
-#> -2 -0.0050 0.0148 -0.0444 0.0345
-#> -1 -0.0229 0.0137 -0.0595 0.0138
-#> 0 -0.0201 0.0115 -0.0508 0.0105
-#> 1 -0.0547 0.0187 -0.1046 -0.0048 *
-#> 2 -0.1382 0.0389 -0.2421 -0.0343 *
-#> 3 -0.1069 0.0415 -0.2177 0.0039
+#> -3 0.0298 0.0158 -0.0111 0.0706
+#> -2 -0.0024 0.0127 -0.0351 0.0302
+#> -1 -0.0243 0.0147 -0.0621 0.0136
+#> 0 -0.0189 0.0124 -0.0508 0.0130
+#> 1 -0.0536 0.0181 -0.1001 -0.0070 *
+#> 2 -0.1363 0.0424 -0.2456 -0.0269 *
+#> 3 -0.1008 0.0351 -0.1914 -0.0103 *
#> ---
#> Signif. codes: `*' confidence band does not cover 0
ggpte(did_res)
@@ -154,43 +154,43 @@ summary(covid_res)
#>
#> Overall ATT:
#> ATT Std. Error [ 95% Conf. Int.]
-#> 14.8882 72.9644 -128.1195 157.8958
+#> 14.8882 70.9966 -124.2626 154.0389
#>
#>
#> Dynamic Effects:
#> Event Time Estimate Std. Error [95% Conf. Band]
-#> -10 -3.7266 3.4720 -13.7679 6.3146
-#> -9 2.6607 1.3600 -1.2726 6.5940
-#> -8 0.8290 2.4227 -6.1776 7.8355
-#> -7 5.2843 2.3046 -1.3807 11.9494
-#> -6 2.8555 1.6024 -1.7788 7.4899
-#> -5 1.3589 3.9788 -10.1479 12.8658
-#> -4 0.3294 3.4291 -9.5876 10.2464
-#> -3 -4.2227 4.6652 -17.7146 9.2693
-#> -2 -3.8447 3.0287 -12.6037 4.9143
-#> -1 -0.2234 3.6485 -10.7751 10.3283
-#> 0 -10.8156 9.1745 -37.3486 15.7174
-#> 1 -13.7998 13.8403 -53.8266 26.2270
-#> 2 -7.8432 11.4608 -40.9882 25.3019
-#> 3 -4.5541 7.8721 -27.3206 18.2123
-#> 4 -3.5368 10.4098 -33.6426 26.5689
-#> 5 8.5221 11.6292 -25.1102 42.1544
-#> 6 1.1140 16.7373 -47.2910 49.5190
-#> 7 6.6384 18.6669 -47.3471 60.6240
-#> 8 7.1288 24.3691 -63.3478 77.6054
-#> 9 10.8758 22.1689 -53.2377 74.9893
-#> 10 17.5057 31.9608 -74.9265 109.9379
-#> 11 40.8318 44.0803 -86.6506 168.3141
-#> 12 48.6134 45.2290 -82.1910 179.4178
-#> 13 52.4228 66.3735 -139.5323 244.3779
-#> 14 50.2000 52.6136 -101.9610 202.3610
-#> 15 68.2960 65.5323 -121.2266 257.8186
-#> 16 44.7305 76.4396 -176.3363 265.7973
-#> 17 61.4670 83.4622 -179.9097 302.8436
-#> 18 50.4635 116.1918 -285.5687 386.4957
-#> 19 47.3392 108.3272 -265.9482 360.6266
-#> 20 28.6326 148.0358 -399.4937 456.7589
-#> 21 4.3445 142.9397 -409.0438 417.7328
+#> -10 -3.7266 3.1136 -12.1092 4.6560
+#> -9 2.6607 1.7120 -1.9485 7.2699
+#> -8 0.8290 2.4142 -5.6706 7.3286
+#> -7 5.2843 2.4728 -1.3732 11.9419
+#> -6 2.8555 1.6468 -1.5782 7.2892
+#> -5 1.3589 3.7156 -8.6445 11.3623
+#> -4 0.3294 4.4875 -11.7521 12.4109
+#> -3 -4.2227 3.5722 -13.8400 5.3947
+#> -2 -3.8447 3.0971 -12.1830 4.4935
+#> -1 -0.2234 3.5584 -9.8037 9.3569
+#> 0 -10.8156 8.7835 -34.4632 12.8320
+#> 1 -13.7998 11.9623 -46.0057 18.4061
+#> 2 -7.8432 10.5984 -36.3770 20.6907
+#> 3 -4.5541 10.1508 -31.8830 22.7747
+#> 4 -3.5368 10.8100 -32.6404 25.5668
+#> 5 8.5221 11.9253 -23.5841 40.6283
+#> 6 1.1140 16.3982 -43.0345 45.2625
+#> 7 6.6384 19.3860 -45.5542 58.8311
+#> 8 7.1288 25.5462 -61.6487 75.9063
+#> 9 10.8758 28.1514 -64.9156 86.6673
+#> 10 17.5057 32.5023 -69.9996 105.0110
+#> 11 40.8318 43.1400 -75.3131 156.9767
+#> 12 48.6134 41.9574 -64.3475 161.5743
+#> 13 52.4228 50.3243 -83.0642 187.9098
+#> 14 50.2000 53.9236 -94.9772 195.3773
+#> 15 68.2960 72.5556 -127.0440 263.6360
+#> 16 44.7305 62.2640 -122.9016 212.3626
+#> 17 61.4670 90.7224 -182.7830 305.7169
+#> 18 50.4635 102.9626 -226.7404 327.6674
+#> 19 47.3392 103.1212 -230.2918 324.9701
+#> 20 28.6326 127.6975 -315.1646 372.4298
+#> 21 4.3445 138.8343 -369.4360 378.1250
#> ---
#> Signif. codes: `*' confidence band does not cover 0
ggpte(covid_res) + ylim(c(-1000, 1000))
@@ -255,18 +255,18 @@ summary(did_res_noif)
#>
#> Overall ATT:
#> ATT Std. Error [ 95% Conf. Int.]
-#> -0.0323 0.0112 -0.0542 -0.0103 *
+#> -0.0323 0.0124 -0.0566 -0.008 *
#>
#>
#> Dynamic Effects:
#> Event Time Estimate Std. Error [95% Pointwise Conf. Band]
-#> -3 0.0269 0.0158 -0.0040 0.0578
-#> -2 -0.0050 0.0116 -0.0277 0.0178
-#> -1 -0.0229 0.0131 -0.0485 0.0028
-#> 0 -0.0201 0.0112 -0.0421 0.0018
-#> 1 -0.0547 0.0161 -0.0864 -0.0231 *
-#> 2 -0.1382 0.0364 -0.2095 -0.0669 *
-#> 3 -0.1069 0.0346 -0.1747 -0.0391 *
+#> -3 0.0269 0.0157 -0.0039 0.0577
+#> -2 -0.0050 0.0137 -0.0319 0.0220
+#> -1 -0.0229 0.0136 -0.0495 0.0038
+#> 0 -0.0201 0.0118 -0.0433 0.0030
+#> 1 -0.0547 0.0167 -0.0875 -0.0220 *
+#> 2 -0.1382 0.0367 -0.2102 -0.0662 *
+#> 3 -0.1069 0.0315 -0.1686 -0.0452 *
#> ---
#> Signif. codes: `*' confidence band does not cover 0
ggpte(did_res_noif)
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 234089a..6c759c9 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -21,7 +21,6 @@ reference:
- attgt_noif
- attgt_pte_aggregations
- compute.pte
- - compute.pte2
- dose_obj
- group_time_att
- gt_data_frame
@@ -29,7 +28,6 @@ reference:
- panel_empirical_bootstrap
- process_att_gt
- pte
- - pte2
- pte_aggte
- pte_attgt
- pte_emp_boot
@@ -46,6 +44,7 @@ reference:
- title: Functions for dealing with a continuous treatment
contents:
- pte_dose_results
+ - process_dose_gt
- title: Functions for dealing with distributional treatment effects
contents:
diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css
deleted file mode 100644
index 5a85941..0000000
--- a/docs/bootstrap-toc.css
+++ /dev/null
@@ -1,60 +0,0 @@
-/*!
- * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/)
- * Copyright 2015 Aidan Feldman
- * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
-
-/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */
-
-/* All levels of nav */
-nav[data-toggle='toc'] .nav > li > a {
- display: block;
- padding: 4px 20px;
- font-size: 13px;
- font-weight: 500;
- color: #767676;
-}
-nav[data-toggle='toc'] .nav > li > a:hover,
-nav[data-toggle='toc'] .nav > li > a:focus {
- padding-left: 19px;
- color: #563d7c;
- text-decoration: none;
- background-color: transparent;
- border-left: 1px solid #563d7c;
-}
-nav[data-toggle='toc'] .nav > .active > a,
-nav[data-toggle='toc'] .nav > .active:hover > a,
-nav[data-toggle='toc'] .nav > .active:focus > a {
- padding-left: 18px;
- font-weight: bold;
- color: #563d7c;
- background-color: transparent;
- border-left: 2px solid #563d7c;
-}
-
-/* Nav: second level (shown on .active) */
-nav[data-toggle='toc'] .nav .nav {
- display: none; /* Hide by default, but at >768px, show it */
- padding-bottom: 10px;
-}
-nav[data-toggle='toc'] .nav .nav > li > a {
- padding-top: 1px;
- padding-bottom: 1px;
- padding-left: 30px;
- font-size: 12px;
- font-weight: normal;
-}
-nav[data-toggle='toc'] .nav .nav > li > a:hover,
-nav[data-toggle='toc'] .nav .nav > li > a:focus {
- padding-left: 29px;
-}
-nav[data-toggle='toc'] .nav .nav > .active > a,
-nav[data-toggle='toc'] .nav .nav > .active:hover > a,
-nav[data-toggle='toc'] .nav .nav > .active:focus > a {
- padding-left: 28px;
- font-weight: 500;
-}
-
-/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */
-nav[data-toggle='toc'] .nav > .active > ul {
- display: block;
-}
diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js
deleted file mode 100644
index 1cdd573..0000000
--- a/docs/bootstrap-toc.js
+++ /dev/null
@@ -1,159 +0,0 @@
-/*!
- * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/)
- * Copyright 2015 Aidan Feldman
- * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */
-(function() {
- 'use strict';
-
- window.Toc = {
- helpers: {
- // return all matching elements in the set, or their descendants
- findOrFilter: function($el, selector) {
- // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/
- // http://stackoverflow.com/a/12731439/358804
- var $descendants = $el.find(selector);
- return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])');
- },
-
- generateUniqueIdBase: function(el) {
- var text = $(el).text();
- var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-');
- return anchor || el.tagName.toLowerCase();
- },
-
- generateUniqueId: function(el) {
- var anchorBase = this.generateUniqueIdBase(el);
- for (var i = 0; ; i++) {
- var anchor = anchorBase;
- if (i > 0) {
- // add suffix
- anchor += '-' + i;
- }
- // check if ID already exists
- if (!document.getElementById(anchor)) {
- return anchor;
- }
- }
- },
-
- generateAnchor: function(el) {
- if (el.id) {
- return el.id;
- } else {
- var anchor = this.generateUniqueId(el);
- el.id = anchor;
- return anchor;
- }
- },
-
- createNavList: function() {
- return $('
');
- },
-
- createChildNavList: function($parent) {
- var $childList = this.createNavList();
- $parent.append($childList);
- return $childList;
- },
-
- generateNavEl: function(anchor, text) {
- var $a = $('');
- $a.attr('href', '#' + anchor);
- $a.text(text);
- var $li = $('');
- $li.append($a);
- return $li;
- },
-
- generateNavItem: function(headingEl) {
- var anchor = this.generateAnchor(headingEl);
- var $heading = $(headingEl);
- var text = $heading.data('toc-text') || $heading.text();
- return this.generateNavEl(anchor, text);
- },
-
- // Find the first heading level (`
`, then `
`, etc.) that has more than one element. Defaults to 1 (for `
diff --git a/docs/reference/attgt_if.html b/docs/reference/attgt_if.html
index 031a61b..f063c34 100644
--- a/docs/reference/attgt_if.html
+++ b/docs/reference/attgt_if.html
@@ -1,5 +1,5 @@
-attgt_if — attgt_if • ptetoolsClass for holding returns from group-time specific estimates in settings when an influence function is returned — attgt_if • ptetoolsSkip to contents
@@ -26,7 +26,7 @@
-
attgt_if
+
Class for holding returns from group-time specific estimates in settings when an influence function is returned
diff --git a/docs/reference/attgt_noif.html b/docs/reference/attgt_noif.html
index ce3cda7..bfb140b 100644
--- a/docs/reference/attgt_noif.html
+++ b/docs/reference/attgt_noif.html
@@ -1,5 +1,5 @@
-attgt_noif — attgt_noif • ptetoolsClass for holding returns from group-time specific estimates in settings when an influence function is not returned — attgt_noif • ptetoolsSkip to contents
@@ -26,7 +26,7 @@
-
attgt_noif
+
Class for holding returns from group-time specific estimates in settings when an influence function is not returned
Function that actually computes panel treatment effects
+
Function that actually computes panel treatment effects.
+The difference relative to compute.pte is that this function
+loops over time periods first (instead of groups) and tries to
+estimate model for untreated potential outcomes jointly for all groups.