knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

orddid

r badger::badge_devel("soichiroy/orddid", "blue") Travis build status Codecov test coverage R build status

Installation Instructions

You can install the development version from GitHub with:

require("devtools")
install_github("soichiroy/orddid", dependencies=TRUE)

Example: Two Time Periods

## load package
library(orddid)
library(dplyr)

## load example data
data("gun_twowave")
## Estimate causal effects
set.seed(1234)
fit <- ord_did(
  Ynew = gun_twowave %>% filter(year == 2012) %>% pull(guns),
  Yold = gun_twowave %>% filter(year == 2010) %>% pull(guns),
  treat = gun_twowave %>% filter(year == 2012) %>% pull(treat_100mi),
  id_cluster = gun_twowave %>% filter(year == 2010) %>% pull(reszip),
  n_boot = 100,
  pre = FALSE,
  verbose = FALSE
)

## view summary of the output 
## non-cumulative effects
summary(fit, cumulative = FALSE)

## cumulative effects
summary(fit)

Example: Additional Pre-treatment Period is Available

## load data
data("gun_threewave")
gun_threewave <- na.omit(gun_threewave)

## further subset to no-treated people through 2012
case_use <- gun_threewave %>%
  filter(year == 2012) %>%
  filter(pds_100mi == "Untreated in Previous Decade" & t_100mi == 0) %>%
  pull(caseid)
dat_14   <- gun_threewave %>% filter(caseid %in% case_use)

## check if subsetting is success full
## there should be no one treated until 2014
dat_14 %>% group_by(year, t_100mi) %>% summarize(n = n())


## subset to comple-cases (exist from 2010 through 2014)
case14    <- dat_14 %>% filter(year == 2014) %>% pull(caseid)
case12    <- dat_14 %>% filter(year == 2012) %>% pull(caseid)
case10    <- dat_14 %>% filter(year == 2010) %>% pull(caseid)
case_full <- intersect(intersect(case14, case12), case10)

## treat Y2012 as "post" and Y2010 as "pre"
Ynew  <- dat_14 %>% filter(caseid %in% case_full & year == 2012) %>%
          pull(guns)
Yold  <- dat_14 %>% filter(caseid %in% case_full & year == 2010) %>%
          pull(guns)
treat <- dat_14 %>% filter(caseid %in% case_full & year == 2014) %>%
          pull(t_100mi)
zip   <- dat_14 %>% filter(caseid %in% case_full & year == 2014) %>%
          pull(reszip)

## estimate parameters
fit <- ord_did(Ynew, Yold, treat, zip,
               n_boot = 100, pre = TRUE, verbose = FALSE)

## equivalence test
equiv_test <- equivalence_test(
  object = fit, alpha = 0.05
)

## view result
summary(equiv_test)

## plot result
plot(equiv_test, ylim = c(-0.1, 0.1), fill = FALSE)

## test with different threshold
equiv_test2 <- equivalence_test(
  object = fit, alpha = 0.05, threshold = 0.01
)

## view result
summary(equiv_test2)


soichiroy/orddid documentation built on Oct. 3, 2020, 5:10 a.m.