From 6c1c8f03a7276453b75a55efed7a2f0378c47854 Mon Sep 17 00:00:00 2001 From: Brantly Callaway Date: Fri, 31 Jan 2025 17:08:14 -0500 Subject: [PATCH] pte2 renamed pte and default, removed old version of pte, updated documentation and testing, and now passing check --- NAMESPACE | 4 +- R/attgt_functions.R | 6 +- R/classes.R | 24 +- R/empirical_bootstrap.R | 2 +- R/ggpte.R | 9 +- R/process_dose_gt.R | 18 +- R/pte.R | 371 ++--------------- R/pte_aggte.R | 31 +- R/pte_params.R | 28 +- README.md | 98 ++--- _pkgdown.yml | 3 +- docs/bootstrap-toc.css | 60 --- docs/bootstrap-toc.js | 159 -------- docs/docsearch.css | 148 ------- docs/docsearch.js | 85 ---- docs/index.html | 98 ++--- docs/pkgdown.css | 384 ------------------ docs/pkgdown.yml | 2 +- docs/reference/aggte_obj.html | 4 +- docs/reference/attgt_if.html | 4 +- docs/reference/attgt_noif.html | 4 +- docs/reference/compute.pte.html | 15 +- docs/reference/compute.pte2.html | 128 ------ docs/reference/crit_val_checks.html | 4 +- docs/reference/did_attgt.html | 4 +- docs/reference/dose_obj.html | 4 +- .../figures/README-unnamed-chunk-3-1.png | Bin 22840 -> 23448 bytes .../figures/README-unnamed-chunk-6-1.png | Bin 20650 -> 20188 bytes .../figures/README-unnamed-chunk-8-1.png | Bin 24276 -> 24517 bytes docs/reference/ggpte.html | 12 +- docs/reference/ggpte_cont.html | 4 +- docs/reference/group_time_att.html | 4 +- docs/reference/gt_data_frame.html | 4 +- docs/reference/index.html | 58 ++- docs/reference/orig2t.html | 98 ----- docs/reference/overall_weights.html | 4 +- docs/reference/pte.html | 69 +++- docs/reference/pte2.html | 261 ------------ docs/reference/pte_aggte.html | 4 +- docs/reference/pte_attgt.html | 4 +- docs/reference/pte_default.html | 4 +- docs/reference/pte_dose_results.html | 4 +- docs/reference/pte_emp_boot.html | 9 +- docs/reference/pte_params.html | 6 +- docs/reference/pte_results.html | 4 +- docs/reference/setup_pte.html | 10 +- docs/reference/setup_pte_basic.html | 10 +- docs/reference/summary.pte_results.html | 4 +- docs/reference/t2orig.html | 101 ----- docs/sitemap.xml | 5 +- man/aggte_obj.Rd | 16 +- man/attgt_if.Rd | 3 +- man/attgt_noif.Rd | 3 +- man/compute.pte.Rd | 7 +- man/compute.pte2.Rd | 62 --- man/crit_val_checks.Rd | 3 +- man/did_attgt.Rd | 3 +- man/dose_obj.Rd | 2 +- man/figures/README-unnamed-chunk-3-1.png | Bin 22840 -> 23448 bytes man/figures/README-unnamed-chunk-6-1.png | Bin 20650 -> 20188 bytes man/figures/README-unnamed-chunk-8-1.png | Bin 24276 -> 24517 bytes man/ggpte.Rd | 7 +- man/ggpte_cont.Rd | 2 +- man/group_time_att.Rd | 3 +- man/gt_data_frame.Rd | 3 +- man/overall_weights.Rd | 16 +- man/process_dose_gt.Rd | 23 ++ man/pte.Rd | 54 ++- man/pte2.Rd | 167 -------- man/pte_aggte.Rd | 21 +- man/pte_attgt.Rd | 3 +- man/pte_default.Rd | 3 +- man/pte_dose_results.Rd | 4 +- man/pte_emp_boot.Rd | 6 +- man/pte_params.Rd | 9 +- man/pte_results.Rd | 3 +- man/setup_pte.Rd | 7 +- man/setup_pte_basic.Rd | 8 +- man/summary.pte_results.Rd | 2 +- tests/testthat/test-did-inference.R | 4 +- tests/testthat/test-did.R | 16 +- 81 files changed, 539 insertions(+), 2297 deletions(-) delete mode 100644 docs/bootstrap-toc.css delete mode 100644 docs/bootstrap-toc.js delete mode 100644 docs/docsearch.css delete mode 100644 docs/docsearch.js delete mode 100644 docs/pkgdown.css delete mode 100644 docs/reference/compute.pte2.html delete mode 100644 docs/reference/orig2t.html delete mode 100644 docs/reference/pte2.html delete mode 100644 docs/reference/t2orig.html delete mode 100644 man/compute.pte2.Rd create mode 100644 man/process_dose_gt.Rd delete mode 100644 man/pte2.Rd 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 `

    `). - getTopLevel: function($scope) { - for (var i = 1; i <= 6; i++) { - var $headings = this.findOrFilter($scope, 'h' + i); - if ($headings.length > 1) { - return i; - } - } - - return 1; - }, - - // returns the elements for the top level, and the next below it - getHeadings: function($scope, topLevel) { - var topSelector = 'h' + topLevel; - - var secondaryLevel = topLevel + 1; - var secondarySelector = 'h' + secondaryLevel; - - return this.findOrFilter($scope, topSelector + ',' + secondarySelector); - }, - - getNavLevel: function(el) { - return parseInt(el.tagName.charAt(1), 10); - }, - - populateNav: function($topContext, topLevel, $headings) { - var $context = $topContext; - var $prevNav; - - var helpers = this; - $headings.each(function(i, el) { - var $newNav = helpers.generateNavItem(el); - var navLevel = helpers.getNavLevel(el); - - // determine the proper $context - if (navLevel === topLevel) { - // use top level - $context = $topContext; - } else if ($prevNav && $context === $topContext) { - // create a new level of the tree and switch to it - $context = helpers.createChildNavList($prevNav); - } // else use the current $context - - $context.append($newNav); - - $prevNav = $newNav; - }); - }, - - parseOps: function(arg) { - var opts; - if (arg.jquery) { - opts = { - $nav: arg - }; - } else { - opts = arg; - } - opts.$scope = opts.$scope || $(document.body); - return opts; - } - }, - - // accepts a jQuery object, or an options object - init: function(opts) { - opts = this.helpers.parseOps(opts); - - // ensure that the data attribute is in place for styling - opts.$nav.attr('data-toggle', 'toc'); - - var $topContext = this.helpers.createChildNavList(opts.$nav); - var topLevel = this.helpers.getTopLevel(opts.$scope); - var $headings = this.helpers.getHeadings(opts.$scope, topLevel); - this.helpers.populateNav($topContext, topLevel, $headings); - } - }; - - $(function() { - $('nav[data-toggle="toc"]').each(function(i, el) { - var $nav = $(el); - Toc.init($nav); - }); - }); -})(); diff --git a/docs/docsearch.css b/docs/docsearch.css deleted file mode 100644 index e5f1fe1..0000000 --- a/docs/docsearch.css +++ /dev/null @@ -1,148 +0,0 @@ -/* Docsearch -------------------------------------------------------------- */ -/* - Source: https://github.com/algolia/docsearch/ - License: MIT -*/ - -.algolia-autocomplete { - display: block; - -webkit-box-flex: 1; - -ms-flex: 1; - flex: 1 -} - -.algolia-autocomplete .ds-dropdown-menu { - width: 100%; - min-width: none; - max-width: none; - padding: .75rem 0; - background-color: #fff; - background-clip: padding-box; - border: 1px solid rgba(0, 0, 0, .1); - box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); -} - -@media (min-width:768px) { - .algolia-autocomplete .ds-dropdown-menu { - width: 175% - } -} - -.algolia-autocomplete .ds-dropdown-menu::before { - display: none -} - -.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { - padding: 0; - background-color: rgb(255,255,255); - border: 0; - max-height: 80vh; -} - -.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { - margin-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion { - padding: 0; - overflow: visible -} - -.algolia-autocomplete .algolia-docsearch-suggestion--category-header { - padding: .125rem 1rem; - margin-top: 0; - font-size: 1.3em; - font-weight: 500; - color: #00008B; - border-bottom: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { - float: none; - padding-top: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { - float: none; - width: auto; - padding: 0; - text-align: left -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content { - float: none; - width: auto; - padding: 0 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--content::before { - display: none -} - -.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { - padding-top: .75rem; - margin-top: .75rem; - border-top: 1px solid rgba(0, 0, 0, .1) -} - -.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { - display: block; - padding: .1rem 1rem; - margin-bottom: 0.1; - font-size: 1.0em; - font-weight: 400 - /* display: none */ -} - -.algolia-autocomplete .algolia-docsearch-suggestion--title { - display: block; - padding: .25rem 1rem; - margin-bottom: 0; - font-size: 0.9em; - font-weight: 400 -} - -.algolia-autocomplete .algolia-docsearch-suggestion--text { - padding: 0 1rem .5rem; - margin-top: -.25rem; - font-size: 0.8em; - font-weight: 400; - line-height: 1.25 -} - -.algolia-autocomplete .algolia-docsearch-footer { - width: 110px; - height: 20px; - z-index: 3; - margin-top: 10.66667px; - float: right; - font-size: 0; - line-height: 0; -} - -.algolia-autocomplete .algolia-docsearch-footer--logo { - background-image: url("data:image/svg+xml;utf8,"); - background-repeat: no-repeat; - background-position: 50%; - background-size: 100%; - overflow: hidden; - text-indent: -9000px; - width: 100%; - height: 100%; - display: block; - transform: translate(-8px); -} - -.algolia-autocomplete .algolia-docsearch-suggestion--highlight { - color: #FF8C00; - background: rgba(232, 189, 54, 0.1) -} - - -.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { - box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) -} - -.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { - background-color: rgba(192, 192, 192, .15) -} diff --git a/docs/docsearch.js b/docs/docsearch.js deleted file mode 100644 index b35504c..0000000 --- a/docs/docsearch.js +++ /dev/null @@ -1,85 +0,0 @@ -$(function() { - - // register a handler to move the focus to the search bar - // upon pressing shift + "/" (i.e. "?") - $(document).on('keydown', function(e) { - if (e.shiftKey && e.keyCode == 191) { - e.preventDefault(); - $("#search-input").focus(); - } - }); - - $(document).ready(function() { - // do keyword highlighting - /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ - var mark = function() { - - var referrer = document.URL ; - var paramKey = "q" ; - - if (referrer.indexOf("?") !== -1) { - var qs = referrer.substr(referrer.indexOf('?') + 1); - var qs_noanchor = qs.split('#')[0]; - var qsa = qs_noanchor.split('&'); - var keyword = ""; - - for (var i = 0; i < qsa.length; i++) { - var currentParam = qsa[i].split('='); - - if (currentParam.length !== 2) { - continue; - } - - if (currentParam[0] == paramKey) { - keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); - } - } - - if (keyword !== "") { - $(".contents").unmark({ - done: function() { - $(".contents").mark(keyword); - } - }); - } - } - }; - - mark(); - }); -}); - -/* Search term highlighting ------------------------------*/ - -function matchedWords(hit) { - var words = []; - - var hierarchy = hit._highlightResult.hierarchy; - // loop to fetch from lvl0, lvl1, etc. - for (var idx in hierarchy) { - words = words.concat(hierarchy[idx].matchedWords); - } - - var content = hit._highlightResult.content; - if (content) { - words = words.concat(content.matchedWords); - } - - // return unique words - var words_uniq = [...new Set(words)]; - return words_uniq; -} - -function updateHitURL(hit) { - - var words = matchedWords(hit); - var url = ""; - - if (hit.anchor) { - url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; - } else { - url = hit.url + '?q=' + escape(words.join(" ")); - } - - return url; -} diff --git a/docs/index.html b/docs/index.html index 8fc7d4d..800f24e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -86,18 +86,18 @@

    Example 1: Difference in difference #> #> 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) @@ -132,43 +132,43 @@

    Example 2: Policy Evaluat #> #> 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)) @@ -210,18 +210,18 @@

    Example 3: Empirical Bootstrap#> #> 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/docs/pkgdown.css b/docs/pkgdown.css deleted file mode 100644 index 80ea5b8..0000000 --- a/docs/pkgdown.css +++ /dev/null @@ -1,384 +0,0 @@ -/* Sticky footer */ - -/** - * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ - * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css - * - * .Site -> body > .container - * .Site-content -> body > .container .row - * .footer -> footer - * - * Key idea seems to be to ensure that .container and __all its parents__ - * have height set to 100% - * - */ - -html, body { - height: 100%; -} - -body { - position: relative; -} - -body > .container { - display: flex; - height: 100%; - flex-direction: column; -} - -body > .container .row { - flex: 1 0 auto; -} - -footer { - margin-top: 45px; - padding: 35px 0 36px; - border-top: 1px solid #e5e5e5; - color: #666; - display: flex; - flex-shrink: 0; -} -footer p { - margin-bottom: 0; -} -footer div { - flex: 1; -} -footer .pkgdown { - text-align: right; -} -footer p { - margin-bottom: 0; -} - -img.icon { - float: right; -} - -/* Ensure in-page images don't run outside their container */ -.contents img { - max-width: 100%; - height: auto; -} - -/* Fix bug in bootstrap (only seen in firefox) */ -summary { - display: list-item; -} - -/* Typographic tweaking ---------------------------------*/ - -.contents .page-header { - margin-top: calc(-60px + 1em); -} - -dd { - margin-left: 3em; -} - -/* Section anchors ---------------------------------*/ - -a.anchor { - display: none; - margin-left: 5px; - width: 20px; - height: 20px; - - background-image: url(./link.svg); - background-repeat: no-repeat; - background-size: 20px 20px; - background-position: center center; -} - -h1:hover .anchor, -h2:hover .anchor, -h3:hover .anchor, -h4:hover .anchor, -h5:hover .anchor, -h6:hover .anchor { - display: inline-block; -} - -/* Fixes for fixed navbar --------------------------*/ - -.contents h1, .contents h2, .contents h3, .contents h4 { - padding-top: 60px; - margin-top: -40px; -} - -/* Navbar submenu --------------------------*/ - -.dropdown-submenu { - position: relative; -} - -.dropdown-submenu>.dropdown-menu { - top: 0; - left: 100%; - margin-top: -6px; - margin-left: -1px; - border-radius: 0 6px 6px 6px; -} - -.dropdown-submenu:hover>.dropdown-menu { - display: block; -} - -.dropdown-submenu>a:after { - display: block; - content: " "; - float: right; - width: 0; - height: 0; - border-color: transparent; - border-style: solid; - border-width: 5px 0 5px 5px; - border-left-color: #cccccc; - margin-top: 5px; - margin-right: -10px; -} - -.dropdown-submenu:hover>a:after { - border-left-color: #ffffff; -} - -.dropdown-submenu.pull-left { - float: none; -} - -.dropdown-submenu.pull-left>.dropdown-menu { - left: -100%; - margin-left: 10px; - border-radius: 6px 0 6px 6px; -} - -/* Sidebar --------------------------*/ - -#pkgdown-sidebar { - margin-top: 30px; - position: -webkit-sticky; - position: sticky; - top: 70px; -} - -#pkgdown-sidebar h2 { - font-size: 1.5em; - margin-top: 1em; -} - -#pkgdown-sidebar h2:first-child { - margin-top: 0; -} - -#pkgdown-sidebar .list-unstyled li { - margin-bottom: 0.5em; -} - -/* bootstrap-toc tweaks ------------------------------------------------------*/ - -/* All levels of nav */ - -nav[data-toggle='toc'] .nav > li > a { - padding: 4px 20px 4px 6px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; -} - -nav[data-toggle='toc'] .nav > li > a:hover, -nav[data-toggle='toc'] .nav > li > a:focus { - padding-left: 5px; - color: inherit; - border-left: 1px solid #878787; -} - -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: 5px; - font-size: 1.5rem; - font-weight: 400; - color: inherit; - border-left: 2px solid #878787; -} - -/* 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-left: 16px; - font-size: 1.35rem; -} - -nav[data-toggle='toc'] .nav .nav > li > a:hover, -nav[data-toggle='toc'] .nav .nav > li > a:focus { - padding-left: 15px; -} - -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: 15px; - font-weight: 500; - font-size: 1.35rem; -} - -/* orcid ------------------------------------------------------------------- */ - -.orcid { - font-size: 16px; - color: #A6CE39; - /* margins are required by official ORCID trademark and display guidelines */ - margin-left:4px; - margin-right:4px; - vertical-align: middle; -} - -/* Reference index & topics ----------------------------------------------- */ - -.ref-index th {font-weight: normal;} - -.ref-index td {vertical-align: top; min-width: 100px} -.ref-index .icon {width: 40px;} -.ref-index .alias {width: 40%;} -.ref-index-icons .alias {width: calc(40% - 40px);} -.ref-index .title {width: 60%;} - -.ref-arguments th {text-align: right; padding-right: 10px;} -.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} -.ref-arguments .name {width: 20%;} -.ref-arguments .desc {width: 80%;} - -/* Nice scrolling for wide elements --------------------------------------- */ - -table { - display: block; - overflow: auto; -} - -/* Syntax highlighting ---------------------------------------------------- */ - -pre, code, pre code { - background-color: #f8f8f8; - color: #333; -} -pre, pre code { - white-space: pre-wrap; - word-break: break-all; - overflow-wrap: break-word; -} - -pre { - border: 1px solid #eee; -} - -pre .img, pre .r-plt { - margin: 5px 0; -} - -pre .img img, pre .r-plt img { - background-color: #fff; -} - -code a, pre a { - color: #375f84; -} - -a.sourceLine:hover { - text-decoration: none; -} - -.fl {color: #1514b5;} -.fu {color: #000000;} /* function */ -.ch,.st {color: #036a07;} /* string */ -.kw {color: #264D66;} /* keyword */ -.co {color: #888888;} /* comment */ - -.error {font-weight: bolder;} -.warning {font-weight: bolder;} - -/* Clipboard --------------------------*/ - -.hasCopyButton { - position: relative; -} - -.btn-copy-ex { - position: absolute; - right: 0; - top: 0; - visibility: hidden; -} - -.hasCopyButton:hover button.btn-copy-ex { - visibility: visible; -} - -/* headroom.js ------------------------ */ - -.headroom { - will-change: transform; - transition: transform 200ms linear; -} -.headroom--pinned { - transform: translateY(0%); -} -.headroom--unpinned { - transform: translateY(-100%); -} - -/* mark.js ----------------------------*/ - -mark { - background-color: rgba(255, 255, 51, 0.5); - border-bottom: 2px solid rgba(255, 153, 51, 0.3); - padding: 1px; -} - -/* vertical spacing after htmlwidgets */ -.html-widget { - margin-bottom: 10px; -} - -/* fontawesome ------------------------ */ - -.fab { - font-family: "Font Awesome 5 Brands" !important; -} - -/* don't display links in code chunks when printing */ -/* source: https://stackoverflow.com/a/10781533 */ -@media print { - code a:link:after, code a:visited:after { - content: ""; - } -} - -/* Section anchors --------------------------------- - Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 -*/ - -div.csl-bib-body { } -div.csl-entry { - clear: both; -} -.hanging-indent div.csl-entry { - margin-left:2em; - text-indent:-2em; -} -div.csl-left-margin { - min-width:2em; - float:left; -} -div.csl-right-inline { - margin-left:2em; - padding-left:1em; -} -div.csl-indent { - margin-left: 2em; -} diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 2b36278..a95c359 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -2,7 +2,7 @@ pandoc: 3.1.3 pkgdown: 2.1.0 pkgdown_sha: ~ articles: {} -last_built: 2025-01-31T19:39Z +last_built: 2025-01-31T21:23Z urls: reference: https://github.com/bcallaway11/ptetools/reference article: https://github.com/bcallaway11/ptetools/articles diff --git a/docs/reference/aggte_obj.html b/docs/reference/aggte_obj.html index d8f12cb..8b54244 100644 --- a/docs/reference/aggte_obj.html +++ b/docs/reference/aggte_obj.html @@ -1,5 +1,5 @@ -aggte_obj — aggte_obj • ptetoolsObject to hold aggregated treatment effect results — aggte_obj • ptetools
    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 • ptetools Skip to contents @@ -26,7 +26,7 @@
    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 • ptetools Skip to contents @@ -26,7 +26,7 @@
    diff --git a/docs/reference/compute.pte.html b/docs/reference/compute.pte.html index 4a748fd..dc3896a 100644 --- a/docs/reference/compute.pte.html +++ b/docs/reference/compute.pte.html @@ -1,5 +1,11 @@ -compute.pte — compute.pte • ptetools +compute.pte — compute.pte • ptetools Skip to contents @@ -30,7 +36,10 @@
    -

    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.

    @@ -94,7 +103,7 @@

    Arguments

    Value

    -

    list of attgt results and, sometimes, and influence function

    +

    list of attgt results and, sometimes, an influence function