Package 'ecic'

Title: Extended Changes-in-Changes
Description: Extends the Changes-in-Changes model a la Athey and Imbens (2006) <doi:10.1111/j.1468-0262.2006.00668.x> to multiple cohorts and time periods, which generalizes difference-in-differences estimation techniques to the entire distribution. Computes quantile treatment effects for every possible two-by-two combination in ecic(). Then, aggregating all bootstrap runs adds the standard errors in summary_ecic(). Results can be plotted with plot_ecic() aggregated over all cohort-group combinations or in an event-study style for either individual periods or individual quantiles.
Authors: Frederic Kluser [aut, cre, cph]
Maintainer: Frederic Kluser <[email protected]>
License: MIT + file LICENSE
Version: 0.0.4
Built: 2025-02-19 06:15:18 UTC
Source: https://github.com/frederickluser/ecic

Help Index


Simulated sample data

Description

A simulated sample panel data with heterogeneous treatment effects across cohorts and groups.

Usage

dat

Format

A simulated data frame with 60,000 rows and 5 columns:

countyreal

Unit ID

first.treat

Cohort

year

Period

time_to_treat

Period - Cohort

lemp

dependent variable

Source

Simulation data


Estimate a changes-in-changes model with multiple periods and cohorts

Description

Calculates a changes-in-changes model as in Athey and Imbens (2006) for multiple periods and cohorts.

Usage

ecic(
  yvar = NULL,
  gvar = NULL,
  tvar = NULL,
  ivar = NULL,
  dat = NULL,
  myProbs = seq(0.1, 0.9, 0.1),
  nMin = 40,
  boot = c("weighted", "normal", "no"),
  nReps = 10,
  weight_n0 = c("n1", "n0"),
  weight_n1 = c("n1", "n0"),
  quant_algo = 1,
  es = FALSE,
  n_digits = NULL,
  periods_es = NULL,
  save_to_temp = FALSE,
  progress_bar = c("progress", "void", "cli"),
  nCores = 1
)

Arguments

yvar

Dependent variable.

gvar

Group variable. Can be either a string (e.g., "first_treated") or an expression (e.g., first_treated). In a staggered treatment setting, the group variable typically denotes treatment cohort.

tvar

Time variable. Can be a string (e.g., "year") or an expression (e.g., year).

ivar

Individual Index variable. Can be a string (e.g., "country") or an expression (e.g., country). Only needed to check cohort sizes.

dat

The data set.

myProbs

Quantiles that the quantile treatment effects should be calculated for.

nMin

Minimum observations per groups. Small groups are deleted.

boot

Bootstrap. Resampling is done over the entire data set ("normal"), but might be weighted by period-cohort size ("weighted"). If you do not want to calculate standard error, set boot = "no".

nReps

Number of bootstrap replications.

weight_n0

Weight for the aggregation of the CDFs in the control group. n1 uses cohort sizes (Alternative: n0).

weight_n1

Weight for the aggregation of the CDFs in the treatment group. n1 uses cohort sizes (Alternative: n0).

quant_algo

Quantile algorithm (see Wikipedia for definitions).

es

Event Study (Logical). If TRUE, a quantile treatment effect is estimated for each event-period.

n_digits

Rounding the dependent variable before aggregating the empirical CDFs reduces the size of the imputation grid. This can significantly reduce the amount of RAM used in large data sets and improve running time, while reducing precision (Use with caution).

periods_es

Periods of the event study.

save_to_temp

Logical. If TRUE, results are temporarily saved. This reduces the RAM needed, but increases running time.

progress_bar

Whether progress bar should be printed (select "void" for no progress bar or "cli" for another type of bar).

nCores

Number of cores used. If set > 1, bootstrapping will run in parallel.

Value

An ecic object.

References

Athey, Susan and Guido W. Imbens (2006). Identification and Inference in Nonlinear Difference-in-Differences Models. doi:10.1111/j.1468-0262.2006.00668.x

Examples

# Example 1. Using the small mpdta data in the did package
data(dat, package = "ecic")
dat = dat[dat$first.treat <= 1983 & dat$countyreal <= 1000,] # small data for fast run

mod_res = 
  summary(
  ecic(
    yvar  = lemp,         # dependent variable
    gvar  = first.treat,  # group indicator
    tvar  = year,         # time indicator
    ivar  = countyreal,   # unit ID
    dat   = dat,          # dataset
    boot  = "normal",     # bootstrap proceduce ("no", "normal", or "weighted")
    nReps = 3             # number of bootstrap runs
    )
    )

# Basic Plot
ecic_plot(mod_res)


# Example 2. Load some larger sample data
data(dat, package = "ecic")

# Estimate a basic model with the package's sample data
mod_res =
  summary(
  ecic(
    yvar  = lemp,         # dependent variable
    gvar  = first.treat,  # group indicator
    tvar  = year,         # time indicator
    ivar  = countyreal,   # unit ID
    dat   = dat,          # dataset
    boot  = "weighted",   # bootstrap proceduce ("no", "normal", or "weighted")
    nReps = 20            # number of bootstrap runs
  )
  )
  
# Basic Plot
ecic_plot(mod_res)

# Example 3. An Event-Study Example
mod_res =
  summary(
  ecic(
    es    = TRUE,         # aggregate for every event period
    yvar  = lemp,         # dependent variable
    gvar  = first.treat,  # group indicator
    tvar  = year,         # time indicator
    ivar  = countyreal,   # unit ID
    dat   = dat,          # dataset
    boot  = "weighted",   # bootstrap proceduce ("no", "normal", or "weighted")
    nReps = 20            # number of bootstrap runs
  )
  )
  
# Plots
ecic_plot(mod_res) # aggregated in one plot
ecic_plot(mod_res, es_type = "for_quantiles") # individually for every quantile
ecic_plot(mod_res, es_type = "for_periods")   # individually for every period

Plot an extended changes-in-changes model

Description

Plots the results of the ecic model, either along the percentiles or in an event-study fashion.

Usage

ecic_plot(
  object,
  es_type = c("aggregated", "for_quantiles", "for_periods"),
  perc_plot = NULL,
  periods_plot = NULL,
  xlab = NULL,
  ylab = "QTE \n",
  ylim = NULL,
  size = 2,
  zero_line = FALSE,
  legend_title = "Percentiles"
)

Arguments

object

An ecic_table object.

es_type

If an event study was estimated with ecic, you can choose the style of the ES plot. "aggregated" puts everything in one plot. "for_quantiles" generates one plot for each percentile. "for_periods" generates one plot for each period.

perc_plot

Which percentiles to plot.

periods_plot

Which periods to plot.

xlab

Alternative x-axis label

ylab

Alternative y-axis label.

ylim

Define the y-axis limits.

size

Size of the point estimates.

zero_line

Add a horizontal line at zero.

legend_title

Change the title of the legend.

Value

A ggplot2 object.


Print ecic objects

Description

Prints an ecic model while making attributes invisible.

Usage

## S3 method for class 'ecic'
print(x, ..., details = FALSE)

Arguments

x

An ecic object.

...

further arguments

details

logical. Set to TRUE to print background information for every bootstrap run and Changes-in-Changes model.

Value

An ecic print object.


Summary for a changes-in-changes regression with multiple periods and cohorts

Description

Summarizes an ecic object by aggregating the bootstrap runs. Works also in an event-study fashion.

Usage

## S3 method for class 'ecic'
summary(object, ...)

Arguments

object

An ecic object.

...

further arguments.

Value

An ecic_table object.