| Title: | Unit-level Difference-in-Difference Estimator |
|---|---|
| Description: | The package provides a function to estimate the unit-level difference-in-difference estimator proposed by Arkhangelsky, Yanagimoto, and Zohar (2024). |
| Authors: | Kazuharu Yanagimoto [aut, cre] (ORCID: <https://orcid.org/0009-0007-1967-8304>) |
| Maintainer: | Kazuharu Yanagimoto <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.6.2 |
| Built: | 2026-06-07 08:03:19 UTC |
| Source: | https://github.com/kazuyanagimoto/unitdid |
Aggregate the mean and variance of the estimated unit-level DiD effects
aggregate_unitdid( object, agg = "full", na.rm = TRUE, by = NULL, normalized = NULL, allow_negative_var = FALSE, only_full_horizon = FALSE )aggregate_unitdid( object, agg = "full", na.rm = TRUE, by = NULL, normalized = NULL, allow_negative_var = FALSE, only_full_horizon = FALSE )
object |
|
agg |
Aggregation method.
One of |
na.rm |
Logical. If |
by |
A character vector of variables to aggregate separately by.
Default is inherited from the |
normalized |
Logical. If |
allow_negative_var |
Logical. If |
only_full_horizon |
Logical. If TRUE, when you aggregate
the unit-level treatment effect, only the event year ( |
A tibble with the aggregated mean and variance of
the estimated unit-level DiD effects
Simulated Individual Child Panalty Data
base_heterocpbase_heterocp
base_heterocpA dataframe with 1000 individuals for each birth year from 1965 to 1984:
idIndividual identifier
yearYear of observation
byearBirth year
cageAge at first birth
rel_timeRelative time to first birth
yOutcome variable
Generated by gen_heterocp() with seed 1234
Generate Sample Heterogenous Child Penalty Data
gen_heterocp(size_cohort = 300)gen_heterocp(size_cohort = 300)
size_cohort |
n_obsumber of individuals per birth year |
A sample dataframe with heterogenous child penalty over the age at first birth
set.seed(1234) base_heterocp <- gen_heterocp()set.seed(1234) base_heterocp <- gen_heterocp()
Get unit-level Difference-in-Differences estimates
get_unitdid( object, normalized = NULL, export = TRUE, only_full_horizon = FALSE )get_unitdid( object, normalized = NULL, export = TRUE, only_full_horizon = FALSE )
object |
|
normalized |
Logical. If |
export |
Logical. If |
only_full_horizon |
Logical. If TRUE, only the event year ( |
A dataframe with a new column of the unit-level DiD estimates
Aggregate the mean and variance of the estimated unit-level DiD effects
## S3 method for class 'unitdid' summary(object, ...)## S3 method for class 'unitdid' summary(object, ...)
object |
|
... |
|
A tibble with the summary statistics
library(unitdid) mdl_base <- base_heterocp |> unitdid(yname = "y", iname = "id", tname = "year", ename = "cyear", bname = "byear") summary(mdl_base, agg = "event_age")library(unitdid) mdl_base <- base_heterocp |> unitdid(yname = "y", iname = "id", tname = "year", ename = "cyear", bname = "byear") summary(mdl_base, agg = "event_age")
A function estimates unit-level difference-in-differences
unitdid( data, yname, iname, tname, ename, first_stage = NULL, wname = NULL, k_min = 0, k_max = 5, compute_varcov = "none", by = NULL, bname = NULL, normalized = FALSE, newnames = NULL )unitdid( data, yname, iname, tname, ename, first_stage = NULL, wname = NULL, k_min = 0, k_max = 5, compute_varcov = "none", by = NULL, bname = NULL, normalized = FALSE, newnames = NULL )
data |
The dataframe containing all the variables |
yname |
Outcome variable |
iname |
Unit identifier |
tname |
Time variable |
ename |
Event timing variable |
first_stage |
Formula for Y(0).
Formula follows |
wname |
Optional. The name of the weight variable. |
k_min |
Relative time to treatment at which treatment starts. Default is 0. |
k_max |
Relative time to treatment at which treatment ends. Default is 5. |
compute_varcov |
One of c("none", "var", "cov") and Default is "none".
If "var", the function will estimate the unit-level variance of the outcome
variable. If "cov", the function will estimate the unit-level covariance of
the outcome variable for each pair within |
by |
A character vector of variables to estimate separately by. Default is NULL. |
bname |
Birth year variable. Default is NULL. Necessary to aggregate the estimates by age at event. |
normalized |
Logical. If TRUE, the function will normalize the outcome variable scale. Default is FALSE. |
newnames |
Optional. A list of new names for the output variables.
|
A unitdid class object.