MyNixOS website logo
Description

Instrumented Difference-in-Differences Decomposition.

Implements a decomposition of the two-way fixed effects instrumental variable estimator into all possible Wald difference-in-differences estimators. Provides functions to summarize the contribution of different cohort comparisons to the overall two-way fixed effects instrumental variable estimate, with or without controls. The method is described in Miyaji (2024) <doi:10.48550/arXiv.2405.16467>.

twfeivdecomp

Overview

twfeivdecomp is a package for decomposing the two-way fixed effects instrumental variable (TWFEIV) estimator under staggered instrumented difference-in-differences (DID-IV) designs.
The package decomposes the TWFEIV estimator into a weighted average of all possible Wald-DID estimators, providing a transparent view of how different 2x2 comparisons contribute to the overall estimate.

The decomposition can be performed both with and without time-varying controls.

Installation

You can install the development version of twfeivdecomp from GitHub:

library(devtools)
install_github("shomiyaji/twfeiv-decomp")

Functions

-twfeiv_decomp(): decomposes the TWFEIV estimator into all possible Wald-DID estimators, with or without time-varying controls.

Data

The package includes an example dataset simulation_data, which is a small simulated panel dataset.
It contains 72 observations (12 units observed over 6 time periods) with the following variables:

  • id: Unit identifier
  • time: Time period (2000–2005)
  • instrument: Binary instrument variable
  • treatment: Treatment variable
  • outcome: Outcome variable
  • control1, control2: Additional control variables

Example

This is a basic example which shows how to decompose the TWFEIV estimator into its Wald-DID components using the twfeivdecomp package.

library(twfeivdecomp)
decomposition_result <- twfeiv_decomp(outcome ~ treatment | instrument,
                                      data = simulation_data,
                                      id_var = "id",
                                      time_var = "time",
                                      summary_output = F)

# Decomposition result
head(decomposition_result)
#>   exposed_cohort unexposed_cohort                design_type Wald_DID_estimate
#> 1           2001             2002 Exposed vs Not Yet Exposed          6.666667
#> 2           2005             2002   Exposed vs Exposed Shift         10.000000
#> 3           2003             2002   Exposed vs Exposed Shift         10.000000
#> 4           2002             2001   Exposed vs Exposed Shift         10.000000
#> 5           2005             2001   Exposed vs Exposed Shift         10.000000
#> 6           2003             2001   Exposed vs Exposed Shift         10.000000
#>       weight
#> 1 0.02777778
#> 2 0.02777778
#> 3 0.02777778
#> 4 0.07407407
#> 5 0.07407407
#> 6 0.11111111

# Print the summary
print_summary(data = decomposition_result, return_df = FALSE)
#> # A tibble: 3 × 3
#>   design_type                weight_sum Weighted_average_Wald_DID
#>   <chr>                           <dbl>                     <dbl>
#> 1 Exposed vs Exposed Shift        0.333                     10   
#> 2 Exposed vs Not Yet Exposed      0.324                      8   
#> 3 Exposed vs Unexposed            0.343                      8.65

# Print the figure
library(ggplot2)

ggplot(decomposition_result) +
  aes(x = weight, y = Wald_DID_estimate, 
      shape = factor(design_type), 
      color = factor(design_type)) +
  geom_point(size = 3) +
  geom_hline(yintercept = 0, linetype = "dashed") +
  theme_minimal() +
  labs(x = "Weight", y = "Wald DID estimate", 
       shape = "Design type", color = "Design type") +
  theme(
    legend.position = "bottom",     
    legend.box = "horizontal"       
  )

References

  • Miyaji, Sho. (2024). Instrumented Difference-in-Differences with Heterogeneous Treatment Effects.
    arXiv:2405.12083. Available at: https://arxiv.org/abs/2405.12083

  • Miyaji, Sho. (2024). Two-Way Fixed Effects Instrumental Variable Regressions in Staggered DID-IV Designs.
    arXiv:2405.16467. Available at: https://arxiv.org/abs/2405.16467

Metadata

Version

0.1.0

License

Unknown

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows