## ----setup, include=FALSE-----------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment  = "#>",
  fig.width  = 7,
  fig.height = 5
)

## ----example------------------------------------------------------------------
library(fdid)
data(fdid)   # loads `mortality`

# Unique unit ID and binary treatment factor
mortality$uniqueid <- paste(mortality$provid, mortality$countyid, sep = "-")
mortality$G <- as.integer(mortality$pczupu >= median(mortality$pczupu, na.rm = TRUE))

# Prepare wide-format data
s <- fdid_prepare(
  data       = mortality,
  Y_label    = "mortality",
  X_labels   = c("avggrain", "nograin", "urban", "dis_bj",
                 "dis_pc", "rice", "minority", "edu", "lnpop"),
  G_label    = "G",
  unit_label = "uniqueid",
  time_label = "year"
)

# Estimate
result <- fdid(s, tr_period = 1958:1961, ref_period = 1957)
summary(result)

## ----plots, fig.show="hold"---------------------------------------------------
plot(result, type = "raw")
plot(result, type = "dynamic")

