ptetools 1.1.0
New
check_overlap()reports overlap diagnostics for each group-time cell (#28). It uses the same cells and covariates aspte_default(). For each cell it gives the share of treated units outside the comparison group’s covariate range (including the lagged outcome withlagged_outcome_cov = TRUE) and, where it can be estimated, the share with a propensity score above 0.9 and 0.999. Shares are reported weighted too whenweightsnameis given.-
pte_attgt()(used bypte_default()) warns more usefully:- When it switches from AIPW to regression adjustment, the warning now says why: too few treated units for the number of covariates, or propensity scores near 1 for a given share of treated units (it used to say “small group size” either way).
- It now warns when it drops a covariate that does not vary among comparison units but does among treated units, such as a dummy for a region with treated units only. The estimates then extrapolate for those treated units. Dropping covariates that are redundant for treated units too (duplicates, empty factor levels) stays silent.
- Each kind of warning is given once per call, listing the group-time cells (in the original group and period codes) instead of once per cell, and not again for every empirical bootstrap draw.
New
unsupported_covariates()flags, for each predicted unit, the covariates that were dropped for collinearity in the fitting sample but matter for that unit’s prediction (#34). It is the check behindpte_attgt()’s dropped-covariate warning, exported so that otherattgt_funs can apply the same rule.New
pte_cell_warning()lets anyattgt_funreport problems this way:pte()collects the warnings across group-time cells and reports each kind once, listing the cells.pte()(e.g.pte_default()) withboot_type = "empirical"no longer warns “aggte_fun not specified” for ATT results, where the default aggregation is the only built-in one. The warning remains for QTT and QOTT results.Bug fix: uniform confidence bands for QTT curves (and QTT minus ATT) could be absurdly wide when the outcome has a mass point, such as zero earnings (#33). The critical value standardized the bootstrap draws by an IQR-based scale, but the band multiplied it by the bootstrap SD. At quantiles inside the mass point the IQR scale is nearly, but not exactly, 0, so the critical value exploded. Both now use the SD, and quantiles whose draws never vary are left out of the critical value. Standard errors are unchanged.
Bug fix: with time periods coded 2, …, T (for example 2:3 or 2:5), results were not mapped back from the internal coding 1, …, T. Group-time results were labeled with the wrong groups and periods, and the overall ATT and event study were
NaN. Whether to map back was guessed from whether the internal periods were all valid original periods; it now checks whether the setup function recoded them. Periods coded 1, …, T, calendar years and other codings were unaffected.Bug fix: standard errors and uniform bands for
ATT(d)fromprocess_dose_gt()(used by contdid) were wrong with a not-yet-treated comparison group, the default. The comparison-group part of the influence function had the wrong sign. That cancels within a single group-time cell, but not across cells where the same unit is first a comparison unit and later treated. In simulations, 95% intervals covered about 92%; they now cover 95%. Results with never-treated comparisons, and those forACRT(d)and the overall parameters, are unaffected.Bug fix: with repeated cross sections (
panel = FALSE), standard errors of the event study and the overall ATT left out the term for estimating the group shares used to weightATT(g,t)(#32). They now matchdid::aggte()exactly, with and without sampling weights. The difference was small in practice (about 0.01% onmpdta); group-time standard errors were unaffected.Bug fix: the empirical bootstrap ignored sampling weights. Each draw was set up again without
weightsname, so every draw was unweighted and weighted standard errors and bands were those of the unweighted estimator (#21). This affected every estimator usingboot_type = "empirical"with weights, including QTT runs and qte’s estimators. Point estimates were correct. The QOTT bootstrap also rebuilt its draws withoutret_quantile, so its standard errors were for the median whatever quantile was estimated.Sampling weights audit (#21):
did_attgt()andcovid_attgt()now use sampling weights (they did not pass them to DRDID), andsetup_pte_basic()gainsweightsname(it set every weight to 1). Weighted estimates and standard errors frompte_default()matchdid::att_gt()for panel data (ATT(g,t), event study and overall, both estimation methods, with covariates, both base periods and comparison groups, and with clustering) and for repeated cross sections (ATT(g,t)), and are unchanged when the weights are rescaled.Bug fix: aggregated QTTs and QOTTs mixed the wrong cells’ distributions.
attgt_pte_aggregations()returned its weight vectors in the order of an internal table thatmerge()sorts by group, while the cells’F0/F1are in the order the cells were computed. With more than one group, the overall, event-time and group QTTs could put weight on pre-treatment cells and none on some post-treatment cells. Cells dropped asNAalso shifted later weights. The weights now follow the order of the cells. ATT results were not affected. Found while adding the ATT to QTT runs (#27).QTT runs (
gt_type = "qtt"withqtt_pte_aggregations()) now also return the ATT, from the same cells, weights and bootstrap draws (#27):$attholds the overall, event-time and group ATTs with standard errors and confidence intervals, and$qtt_minus_attholds the curves QTT(tau) - ATT with pointwise and uniform bands and the p-value of a sup-t test that QTT(tau) = ATT at every quantile (no distributional effect beyond a location shift). Overlaying a separately estimated ATT on a QTT band is not a valid test of this, since it ignores the estimation error in the ATT and its correlation with the QTT.summary()reports the ATTs and the tests,autoplot()draws the overall ATT on the QTT curve, andautoplot(type = "qtt_minus_att")plots the difference with its band.Aggregated QTTs (
qtt_pte_aggregations()) are now exact (#25). The cells’ distribution functions used to be mixed on a 1,000-point grid of the pooled outcome, so each quantile was rounded up to a grid point, andquantile()on the mixture then rounded its jumps again. Weighted data and the equivalent row-replicated data gave different QTTs. The mixture now uses every support point of the cells’ CDFs (one sort), at about the same cost, throughBMisc::combine_ecdfs(), which computes mixtures exactly in BMisc 1.4.11 (now required). Reported QTTs change slightly (onmpdta, by up to about 0.01). The cells’F0/F1must be step-function CDFs, as those fromBMisc::weighted_ecdf()are. Bootstrap draws no longer keep their own overall CDFs, so memory does not grow with sample size timesbiters. The quantile of the treatment effect (qott_pte_aggregations()) is now exact in the same way. Its grid, 1,000 points on [-max(y), max(y)], also missed effects below -max(y), and ran backwards when every outcome was negative. Each cell’s QOTT is now its exact quantile too.The doubly robust estimator is now
est_method = "aipw"(augmented inverse probability weighting), the new default inpte_default(),pte_attgt()anddid_rcs_attgt()(#30)."dr"still works as a deprecated alias, with a warning; it was ambiguous next to qte’scond_dist = "dr"(distribution regression). An unsupportedest_methodnow gives a clear error up front.New
control_group = "eventuallytreated"(#29): the comparison units are units that are treated at some point but not yet treated (net of anticipation) in either period of a group-time comparison, i.e. the not-yet-treated units other than the never treated. The latest-treated cohort then serves only as a comparison group, and periods from its treatment date on are dropped, as without a never-treated group. Units first treated after the last period count as eventually treated.-
QTT results (
pte_qtt), e.g. from qte’s estimators (#26):-
summary()now returns asummary.pte_qttobject instead of printing, so the table no longer appears twice at the console; - the summary shows the dynamic (event-study) and group QTTs at selected quantiles (
probs, default the median), not only the overall curve; - it labels the band (simultaneous over quantiles, or pointwise) and marks estimates whose band excludes 0 with
*, like the ATT summary; -
autoplot(type = "group")now plots each cohort’s QTT at the selected quantile(s); it used to error.
-
setup_pte()gainsrequire_comparison(defaultTRUE). WithFALSE, setup does not require comparison units and estimates every group; this is for estimators that use only variation within each group and build their own cells, such as contdid’s ACRT when no unit is untreated (contdid #5).process_dose_gt()then reports only ACRT results; ATT(d) and the overall ATT areNA.control_groupis now checked: it must be"notyettreated","nevertreated"or"eventuallytreated". Any other value, including a typo, used to be treated as"nevertreated"without a warning.Fixed designs without a never-treated group.
setup_pte()(andsetup_pte_basic()) removed the smallest group value assuming it was 0, so without never-treated units the earliest cohort was silently dropped and estimation could then fail. Now, as indid::att_gt(), the latest cohort serves as the comparison group (as never treated withcontrol_group = "nevertreated", with a warning) and periods from its treatment date on are dropped. If every unit is treated in the same period, there is now a clear error that no comparison units exist.Fixed the empirical-bootstrap aggregation with
weightsname: cohorts were combined by unweighted unit counts instead of weighted shares, so overall and event-study results were wrong whenever average weights differed across cohorts (#23). This affected estimators that use the empirical bootstrap, including qte’s. They now matchpte_aggte().Sampling weights are now checked (#24): they must be non-missing, finite and non-negative with a positive sum, and, with panel data, constant over time within each unit (as in
did). Previously, invalid weights gaveNaNestimates or inconsistent results without an error.Empirical bootstrap: group effects and event times of a small cohort that is missing from some bootstrap draws now keep their estimates and get standard errors from the draws that contain the cohort; if it is missing from more than 10% of the draws, the standard errors are
NA(#22). Before, such estimates were dropped from the results, estimate and all, if any single draw missed the cohort. The same applies to the QTT estimators. Also fixed: group-time standard errors from the empirical bootstrap were attached to the wrong (g,t) cells; they are now matched by group and time period.New
clustervarsargument forpte_default(),pte()(viasetup_pte()) to cluster standard errors at a level above the unit, as indid::att_gt()(#6): one variable, constant within each unit. It applies to analytical standard errors (cluster-robust variance, including the pre-test), the multiplier bootstrap (one multiplier per cluster, applied to influence functions summed within clusters) and the empirical bootstrap (whole clusters are resampled), for group-time effects and all aggregations.mboot2()andgetSE()gain aclusterargument. Unclustered results are unchanged.setup_pte()now storescontrol_groupin thepte_paramsobject, so later steps (the overall ATT for continuous treatments) use the requested comparison group instead of always the default. Continuous-treatment results (process_dose_gt()) now work withbase_period = "universal".Covariate formulas can now transform variables, e.g.
xformula = ~ factor(state) + I(x^2) + log(z), inpte_default()/pte_attgt(),did_attgt()andcovid_attgt()(#5). Such terms failed with “object not found”. Results for untransformed covariates are unchanged.An error while estimating one group-time cell now says which group and time period it is (in units of
tname) (#17). With a continuous treatment, a cohort with no more treated units than parameters in the dose regression now gives a clear error instead of “something off with overall influence function”.The empirical bootstrap no longer errors when a bootstrap draw contains no treated units, which happened often with small cohorts (#10). Such draws are dropped, with a warning that says how many, and standard errors use the remaining draws. This also applies to the QTT estimators in qte.
pte_default()withest_method = "dr"no longer warns “non-integer #successes in a binomial glm!” on every call (#20). The overlap check now fits its logit propensity score withquasibinomial()and weights normalized to mean 1; fitted values, and so results, are unchanged.No more flood of warnings from the multiplier bootstrap with
base_period = "universal"(#3). The sup-t critical value for uniform confidence bands is computed only when it is used (cband = TRUE), and only over parameters with a positive standard error, which leaves out the universal reference period (0 by construction). This removes one warning per bootstrap draw (“no non-missing arguments to max”) and spurious “critical value … somehow smaller” warnings. Results are unchanged.mboot2()gains acbandargument.clnow parallelizes the empirical bootstrap on Windows too (#11). A numericclonly worked by forking, which Windows does not support, so there the bootstrap silently ran serially. On Windows, ptetools now creates a cluster withclworkers (reproducible withset.seed()) and stops it afterwards.clcan also be a cluster object fromparallel::makeCluster(), on any platform. The documentation ofclnow says what it does.The pre-test of parallel trends is now reported with
base_period = "universal"(#18). The reference cells, which are 0 by construction, made the covariance matrix singular. Cells with zero variance are now left out, as indid::att_gt(), and the pre-test matchesdidfor both base periods.Fixed standard errors of aggregated parameters (overall ATT, event study, group effects) from
pte_aggte(), which were slightly off (about 0.3-0.8% onmpdta) (#19). The term for estimating the group shares used shares normalized to sum to 1 across treated groups instead of P(G = g). They now matchdid::aggte()exactly. Point estimates are unchanged.overall_weights()(used for continuous treatments) no longer stops with “something’s going wrong calculating overall weights” when the weights sum to 1 only up to floating-point rounding, which happened with many timing groups (#1).The
bstrapdocumentation no longer refers todev/NOTES.md, which is not part of the package; it now says what happens with a continuous treatment (#4).-
anticipationnow followsdid::att_gt(): it is measured in units of the time variable (e.g., years), not in number of periods, which matters when periods are not one unit apart. Specifically:- the base period is the last period at least
anticipationbefore treatment, and cells witht >= g - anticipationare post-treatment; - not-yet-treated comparison units must not be anticipating treatment in either period of the cell (first treated more than
anticipationafter both periods), so units about to anticipate are no longer used as controls; - the pre-test leaves out anticipation periods;
- units first treated more than
anticipationafter the last period are treated as never treated (previously an error); - a clear error is given when no group has a period early enough to serve as its base period.
Results with
anticipation = 0are unchanged. Withanticipation > 0, results can change even with consecutive periods, because of the comparison-group rule. - the base period is the last period at least
New exported helpers for custom subset functions:
pte_base_period()gives the base period of a group-time cell as indid::att_gt(), andpte_calendar_time()maps internal period indices back to the time variable.two_by_two_subset()uses them.Fixed pre-treatment
ATT(g,t)withbase_period = "universal"and not-yet-treated controls (the default) (#16). The comparison group could include units already treated in the base period, which comes after the current period in pre-treatment cells. Not-yet-treated controls are now units first treated after both periods of the cell, as indid::att_gt(). Post-treatment estimates and the overall ATT are unchanged; pre-trends in event studies can change.pte_default()now matchesdid::att_gt()for both base periods and both control groups, including with unequally spaced time periods.biters = 0now skips the bootstrap (#14). It crashed the multiplier bootstrap, and earlier versions silently ran 2 bootstrap draws. Whereattgt_funreturns an influence function,biters = 0is the same asbstrap = FALSE(analytical, pointwise standard errors). Where standard errors are only available from the bootstrap (the empirical bootstrap, including the QTT estimators, andATT(d)/ACRT(d)with a continuous treatment), the point estimates are returned withNAstandard errors.bitersmust now be a non-negative whole number.Fixed estimates when a column named in
gname,tname,idnameorynameis calledG,period,idorY(#13). Withgname = "G"ortname = "period"and groups coded as calendar years, the overall ATT and event study were silentlyNaN.setup_pte()andsetup_pte_basic()now store their internal columns as.G,.id,.periodand.Y, and never modify the user’s columns.Breaking change for custom setup and subset functions. The full data from a setup function now has the internal columns
.G,.id,.period,.Y,.wand.rowid, notG,id,periodandY. Subset functions should select rows using the dot columns and finish withgt_data_frame(), which gives each group-time cell the columnsG,id,periodandY(attgt_funs are unchanged).gt_data_frame()now errors if the dot columns are missing.keep_all_untreated_subset()andkeep_all_pretreatment_subset()now also returngt_data_framecells.Fixed the standard errors of
ATT(d)andACRT(d)fromprocess_dose_gt()(used bycontdid) whendvalsdoes not span exactly the range of the positive doses: the influence functions were built with a different B-spline basis than the one the dose regression was fitted with.process_dose_gt()now uses the boundary knots inptep$boundary_knotswhen present, and otherwise keeps the previous behavior (#7; thanks to @AsadGudzevic94).Fixed
pte_attgt(),did_attgt()andcovid_attgt()(and sopte_default()) giving wrong estimates with covariates or sampling weights when the data were not sorted by id within each period: covariates and weights were paired with other units’ outcomes (#9).setup_pte()now sorts panel data by id and period, and the 2x2 cells are matched by id. Results for data already sorted this way are unchanged.-
pte()andpte_default()are faster, with the same results; the empirical bootstrap (used by theqteestimators) is often more than 10x faster. Speedups:- The bootstrap resamples units by index.
- Each (g,t) cell is built from row indices computed once.
-
pte_default()keeps only the columns it uses. - The multiplier bootstrap is vectorized and uses the same random draws as before.
-
data.tableis no longer a dependency.
The multiplier-bootstrap standard errors for ATT(g,t) now use
bitersdraws. Previously they always used 1000 draws, whateverbiterswas set to. Aggregated parameters already usedbiters.setup_pte()now gives a clear error when a value ofgnameis neither 0 nor one of the time periods.Fixed standard errors for aggregated parameters (overall ATT, event study) when
weightsnameis used: they depended on the scale of the weights and were far too large for weights not near 1, such as population counts (#8). Weights are now normalized to mean 1 before aggregation, as indid. Point estimates are unchanged.Added
bstrapargument topte(),pte_default(),setup_pte(), andsetup_pte_basic()to request purely analytical (non-bootstrap) standard errors (bstrap = FALSE) instead of the multiplier bootstrap, whereverattgt_funreturns an influence function. This skips the (often expensive) multiplier bootstrap entirely and is much faster for large panels.bstrap = FALSEonly supports pointwise confidence intervals (falls back fromcband = TRUEwith a warning), overridesboot_type = "empirical", and is not currently supported for continuous treatment (gt_type = "dose").Fixed a bug in
crit_val_checks()that threwobject 'dp' not foundwhen a simultaneous critical value could not be computed (e.g. designs with no pre-treatment periods, where standard errors come backNA). The fallback to pointwise critical values now works correctly, andpte()/process_dose_gt()correctly downgrade theircbandflag sosummary()reports “Pointwise” rather than “Simult.” whenever this fallback occurs.Fixed a bug where
autoplot.dose_obj()(used bycontdid::ggcont_did()) crashed witharguments imply differing number of rowsbecause the critical value stored ondose_objcarried a stray"cband"attribute left over fromcrit_val_checks(), which brokedata.frame()recycling.
ptetools 1.0.1
CRAN release: 2026-07-20
Force time periods to be positive integers in
ptetools::setup_pte()Fix bug related to accounting for variance of untreated group with continuous treatment
Added
covid_datadataset (previously inppe); updated GitHub Actions workflows; fixed several documentation issues; droppedtidyrdependency in favour ofdata.tableAdded
pte_default(), a convenience wrapper combiningsetup_pte(),two_by_two_subset(), andpte_attgt()for standard DID/unconfoundedness-style estimationAdded support for repeated cross-sectional data via
panel = FALSE, with a newtwo_by_two_rcs_subset()subset functionAdded
print(),summary(),autoplot(), andplot()methods forpte_emp_boot(empirical bootstrap results)Added
aggte_funargument topte(),panel_empirical_bootstrap(), andqtt_empirical_bootstrap()for supplying a custom group-time aggregation function on the empirical bootstrap pathBumped minimum required
BMiscversion to 1.4.8 —ptetoolscalls severalBMiscfunctions (add_cov_to_formula,rhs_vars,combine_ecdfs,get_list_element,weighted_combine_list) that were not available until that version
