Skip to content

Commit

Permalink
Add references
Browse files Browse the repository at this point in the history
  • Loading branch information
kazuyanagimoto committed Mar 29, 2024
1 parent 5eb686c commit 4c121a3
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ altdoc/freeze.rds
_quarto/*
!_quarto/_freeze/
*_files/
_quarto/
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<!-- badges: end -->

The `unitdid` package provides a set of functions for the analysis of
the unit-level difference-in-differences (Arkhangelsky, Yanagimoto, and
Zohar, 2024)
the unit-level difference-in-differences ([Arkhangelsky, Yanagimoto, and
Zohar 2024](https://arxiv.org/abs/2403.19563)).

## Installation

Expand Down Expand Up @@ -158,3 +158,10 @@ sum_eage |>
```

<img src="man/figures/README-var_cage-1.svg" style="width:100.0%" />

## References

Arkhangelsky, Dmitry, Kazuharu Yanagimoto, and Tom Zohar. 2024.
“Flexible Analysis of Individual Heterogeneity in Event Studies:
Application to the Child Penalty.” arXiv.
<https://arxiv.org/abs/2403.19563>.
5 changes: 4 additions & 1 deletion README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(
<!-- badges: end -->

The `unitdid` package provides a set of functions for the analysis of
the unit-level difference-in-differences (Arkhangelsky, Yanagimoto, and Zohar, 2024)
the unit-level difference-in-differences ([Arkhangelsky, Yanagimoto, and Zohar 2024](https://arxiv.org/abs/2403.19563)).

## Installation

Expand Down Expand Up @@ -130,3 +130,6 @@ sum_eage |>
panel.grid.minor = element_blank())
```

## References

Arkhangelsky, Dmitry, Kazuharu Yanagimoto, and Tom Zohar. 2024. "Flexible Analysis of Individual Heterogeneity in Event Studies: Application to the Child Penalty." arXiv. [https://arxiv.org/abs/2403.19563](https://arxiv.org/abs/2403.19563).
8 changes: 5 additions & 3 deletions _quarto/_freeze/index/execute-results/html.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"hash": "ca7f64c46b9360786d1547d80d5d3800",
"hash": "ca9eb4cbd691a4666e4e735949aff977",
"result": {
"engine": "knitr",
"markdown": "<!-- README.md is generated from README.Rmd. Please edit that file -->\n\n\n\n\n\n# unitdid\n\n<!-- badges: start -->\n<!-- badges: end -->\n\nThe `unitdid` package provides a set of functions for the analysis of\nthe unit-level difference-in-differences (Arkhangelsky, Yanagimoto, and Zohar, 2024)\n\n## Installation\n\nYou can install the development version of unitdid from [GitHub](https://github.com/kazuyanagimoto/unitdid) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"kazuyanagimoto/unitdid\")\n```\n\n## Example\n\nThis is a basic example with the simulated `base_heterocp` data set:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(unitdid)\nlibrary(dplyr)\nlibrary(ggplot2)\n\nbase_heterocp |>\n head()\n#> # A tibble: 6 × 5\n#> id year byear cyear y\n#> <int> <int> <int> <int> <dbl>\n#> 1 1 1999 1955 1985 -0.848\n#> 2 1 2000 1955 1985 0.759\n#> 3 1 2001 1955 1985 -1.03 \n#> 4 1 2002 1955 1985 0.858\n#> 5 1 2003 1955 1985 -0.866\n#> 6 1 2004 1955 1985 -0.651\n```\n:::\n\n\nIndividual-level child penalties are estimated by `unitdid()`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmdl_base <- base_heterocp |>\n unitdid(yname = \"y\",\n iname = \"id\",\n tname = \"year\",\n ename = \"cyear\",\n bname = \"byear\")\n\n# Estimated individual-level child penalties (y_tilde)\nget_unitdid(mdl_base)\n#> # A tibble: 32,257 × 6\n#> id year byear cyear y y_tilde\n#> <int> <int> <int> <int> <dbl> <dbl>\n#> 1 705 2000 1957 2000 0.138 -0.0287 \n#> 2 997 2000 1958 2000 0.138 0.0849 \n#> 3 998 2000 1958 2000 0.119 -0.104 \n#> 4 1013 2000 1958 2000 0.115 -0.0000709\n#> 5 1082 2000 1958 2000 0.0362 0.00549 \n#> 6 1127 2000 1958 2000 0.386 0.125 \n#> 7 1225 2001 1959 2001 0.158 -0.118 \n#> 8 1228 2000 1959 2000 0.241 -0.0937 \n#> 9 1228 2001 1959 2000 0.443 0.0226 \n#> 10 1230 2000 1959 2000 0.143 -0.0266 \n#> # ℹ 32,247 more rows\n```\n:::\n\n\n### Aggregation of Individual-level Child Penalties\n\nThey can be aggregated to the `full`,\n`event` (year at event (treatment). Mainly for staggered DiD design),\n`event_age` (age at event. Mainly for child penalties) levels:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsummary(mdl_base) # default agg = \"full\"\n#> # A tibble: 6 × 3\n#> mean rel_time n\n#> <dbl> <int> <dbl>\n#> 1 -0.0653 0 4357\n#> 2 -0.193 1 4357\n#> 3 -0.307 2 4357\n#> 4 -0.310 3 4357\n#> 5 -0.350 4 4357\n#> 6 -0.349 5 4357\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nsum_eage <- summary(mdl_base, agg = \"event_age\")\n\nsum_eage |>\n filter(rel_time == 0) |>\n mutate(rel_time = -1,\n mean = 0) |>\n bind_rows(sum_eage) |>\n filter(between(event_age, 25, 34)) |>\n mutate(lbl_facet = paste0(\"Age \", event_age)) |>\n ggplot(aes(x = rel_time, y = mean)) +\n geom_point() +\n geom_line() +\n geom_vline(xintercept = -1, linetype = \"dashed\") +\n geom_hline(yintercept = 0) +\n facet_wrap(~lbl_facet, ncol = 5) +\n labs(x = \"Time to First Childbirth\",\n y = \"Child Penalties on y\") +\n theme_minimal() +\n theme(panel.grid.major.x = element_blank(),\n panel.grid.minor = element_blank())\n```\n\n::: {.cell-output-display}\n![](man/figures/README-agg_cage-1.svg){width=100%}\n:::\n:::\n\n\n### Variance of Individual-level Child Penalties\n\nSince the individual-level child penalties are estimated with measurement errors,\nthe variance of the `y_tilde` is not equal to the variance of\nthe individual-level child penalties.\n\nThe `compute_varcov = \"var\"` option of the `unitdid` estimates the variance of\nthe measurement errors and the variance of the individual-level child penalties\nby subtracting the variance of the measurement errors from the variance of `y_tilde`\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmdl_base <- base_heterocp |>\n unitdid(yname = \"y\",\n iname = \"id\",\n tname = \"year\",\n ename = \"cyear\",\n bname = \"byear\",\n compute_varcov = \"var\")\n\nsum_eage <- summary(mdl_base, agg = \"event_age\")\n\nsum_eage |>\n filter(rel_time == 0) |>\n mutate(rel_time = -1,\n var = 0) |>\n bind_rows(sum_eage) |>\n filter(between(event_age, 25, 34)) |>\n mutate(lbl_facet = paste0(\"Age \", event_age)) |>\n ggplot(aes(x = rel_time, y = sqrt(var))) +\n geom_point() +\n geom_line() +\n geom_vline(xintercept = -1, linetype = \"dashed\") +\n geom_hline(yintercept = 0) +\n facet_wrap(~lbl_facet, ncol = 5) +\n labs(x = \"Time to First Childbirth\",\n y = \"S.D. of Child Penalties\") +\n theme_minimal() +\n theme(panel.grid.major.x = element_blank(),\n panel.grid.minor = element_blank())\n```\n\n::: {.cell-output-display}\n![](man/figures/README-var_cage-1.svg){width=100%}\n:::\n:::\n",
"supporting": [],
"markdown": "<!-- README.md is generated from README.Rmd. Please edit that file -->\n\n\n\n\n\n# unitdid\n\n<!-- badges: start -->\n<!-- badges: end -->\n\nThe `unitdid` package provides a set of functions for the analysis of\nthe unit-level difference-in-differences ([Arkhangelsky, Yanagimoto, and Zohar 2024](https://arxiv.org/abs/2403.19563)).\n\n## Installation\n\nYou can install the development version of unitdid from [GitHub](https://github.com/kazuyanagimoto/unitdid) with:\n\n``` r\n# install.packages(\"remotes\")\nremotes::install_github(\"kazuyanagimoto/unitdid\")\n```\n\n## Example\n\nThis is a basic example with the simulated `base_heterocp` data set:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nlibrary(unitdid)\nlibrary(dplyr)\nlibrary(ggplot2)\n\nbase_heterocp |>\n head()\n#> # A tibble: 6 × 5\n#> id year byear cyear y\n#> <int> <int> <int> <int> <dbl>\n#> 1 1 1999 1955 1985 -0.848\n#> 2 1 2000 1955 1985 0.759\n#> 3 1 2001 1955 1985 -1.03 \n#> 4 1 2002 1955 1985 0.858\n#> 5 1 2003 1955 1985 -0.866\n#> 6 1 2004 1955 1985 -0.651\n```\n:::\n\n\nIndividual-level child penalties are estimated by `unitdid()`:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmdl_base <- base_heterocp |>\n unitdid(yname = \"y\",\n iname = \"id\",\n tname = \"year\",\n ename = \"cyear\",\n bname = \"byear\")\n\n# Estimated individual-level child penalties (y_tilde)\nget_unitdid(mdl_base)\n#> # A tibble: 32,257 × 6\n#> id year byear cyear y y_tilde\n#> <int> <int> <int> <int> <dbl> <dbl>\n#> 1 705 2000 1957 2000 0.138 -0.0287 \n#> 2 997 2000 1958 2000 0.138 0.0849 \n#> 3 998 2000 1958 2000 0.119 -0.104 \n#> 4 1013 2000 1958 2000 0.115 -0.0000709\n#> 5 1082 2000 1958 2000 0.0362 0.00549 \n#> 6 1127 2000 1958 2000 0.386 0.125 \n#> 7 1225 2001 1959 2001 0.158 -0.118 \n#> 8 1228 2000 1959 2000 0.241 -0.0937 \n#> 9 1228 2001 1959 2000 0.443 0.0226 \n#> 10 1230 2000 1959 2000 0.143 -0.0266 \n#> # ℹ 32,247 more rows\n```\n:::\n\n\n### Aggregation of Individual-level Child Penalties\n\nThey can be aggregated to the `full`,\n`event` (year at event (treatment). Mainly for staggered DiD design),\n`event_age` (age at event. Mainly for child penalties) levels:\n\n\n::: {.cell}\n\n```{.r .cell-code}\nsummary(mdl_base) # default agg = \"full\"\n#> # A tibble: 6 × 3\n#> mean rel_time n\n#> <dbl> <int> <dbl>\n#> 1 -0.0653 0 4357\n#> 2 -0.193 1 4357\n#> 3 -0.307 2 4357\n#> 4 -0.310 3 4357\n#> 5 -0.350 4 4357\n#> 6 -0.349 5 4357\n```\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nsum_eage <- summary(mdl_base, agg = \"event_age\")\n\nsum_eage |>\n filter(rel_time == 0) |>\n mutate(rel_time = -1,\n mean = 0) |>\n bind_rows(sum_eage) |>\n filter(between(event_age, 25, 34)) |>\n mutate(lbl_facet = paste0(\"Age \", event_age)) |>\n ggplot(aes(x = rel_time, y = mean)) +\n geom_point() +\n geom_line() +\n geom_vline(xintercept = -1, linetype = \"dashed\") +\n geom_hline(yintercept = 0) +\n facet_wrap(~lbl_facet, ncol = 5) +\n labs(x = \"Time to First Childbirth\",\n y = \"Child Penalties on y\") +\n theme_minimal() +\n theme(panel.grid.major.x = element_blank(),\n panel.grid.minor = element_blank())\n```\n\n::: {.cell-output-display}\n![](man/figures/README-agg_cage-1.svg){width=100%}\n:::\n:::\n\n\n### Variance of Individual-level Child Penalties\n\nSince the individual-level child penalties are estimated with measurement errors,\nthe variance of the `y_tilde` is not equal to the variance of\nthe individual-level child penalties.\n\nThe `compute_varcov = \"var\"` option of the `unitdid` estimates the variance of\nthe measurement errors and the variance of the individual-level child penalties\nby subtracting the variance of the measurement errors from the variance of `y_tilde`\n\n\n::: {.cell}\n\n```{.r .cell-code}\nmdl_base <- base_heterocp |>\n unitdid(yname = \"y\",\n iname = \"id\",\n tname = \"year\",\n ename = \"cyear\",\n bname = \"byear\",\n compute_varcov = \"var\")\n\nsum_eage <- summary(mdl_base, agg = \"event_age\")\n\nsum_eage |>\n filter(rel_time == 0) |>\n mutate(rel_time = -1,\n var = 0) |>\n bind_rows(sum_eage) |>\n filter(between(event_age, 25, 34)) |>\n mutate(lbl_facet = paste0(\"Age \", event_age)) |>\n ggplot(aes(x = rel_time, y = sqrt(var))) +\n geom_point() +\n geom_line() +\n geom_vline(xintercept = -1, linetype = \"dashed\") +\n geom_hline(yintercept = 0) +\n facet_wrap(~lbl_facet, ncol = 5) +\n labs(x = \"Time to First Childbirth\",\n y = \"S.D. of Child Penalties\") +\n theme_minimal() +\n theme(panel.grid.major.x = element_blank(),\n panel.grid.minor = element_blank())\n```\n\n::: {.cell-output-display}\n![](man/figures/README-var_cage-1.svg){width=100%}\n:::\n:::\n\n\n## References\n\nArkhangelsky, Dmitry, Kazuharu Yanagimoto, and Tom Zohar. 2024. \"Flexible Analysis of Individual Heterogeneity in Event Studies: Application to the Child Penalty.\" arXiv. [https://arxiv.org/abs/2403.19563](https://arxiv.org/abs/2403.19563).",
"supporting": [
"index_files"
],
"filters": [
"rmarkdown/pagebreak.lua"
],
Expand Down
Loading

0 comments on commit 4c121a3

Please sign in to comment.