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]
|
Maintainer: | Kazuharu Yanagimoto <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.6.2 |
Built: | 2025-02-23 06:18:27 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_heterocp
base_heterocp
base_heterocp
A dataframe with 1000 individuals for each birth year from 1965 to 1984:
id
Individual identifier
year
Year of observation
byear
Birth year
cage
Age at first birth
rel_time
Relative time to first birth
y
Outcome 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.