---
title: "Introduction to sccic"
author: "Neil Hwang"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Introduction to sccic}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

## Overview

The **sccic** package implements the Changes-in-Changes (CIC) estimator of
Athey and Imbens (2006), combined with synthetic control methods for causal
inference. It provides two main functions:

- `cic()`: Standard CIC for two-group, two-period settings
- `sc_cic()`: Synthetic control + CIC for single-treated-unit settings

## Example 1: Standard CIC

We demonstrate `cic()` on the workers' compensation data from Meyer, Viscusi,
and Durbin (1995), the canonical CIC dataset.

```{r cic-example}
library(sccic)

# Load workers' comp data
if (requireNamespace("wooldridge", quietly = TRUE)) {
  data("injury", package = "wooldridge")

  result <- cic(
    y_00 = injury$ldurat[injury$highearn == 0 & injury$afchnge == 0],
    y_01 = injury$ldurat[injury$highearn == 0 & injury$afchnge == 1],
    y_10 = injury$ldurat[injury$highearn == 1 & injury$afchnge == 0],
    y_11 = injury$ldurat[injury$highearn == 1 & injury$afchnge == 1]
  )
  print(result)
}
```

The CIC estimate (0.069) is substantially smaller than the DID estimate
(0.188), consistent with Athey and Imbens (2006).

## Example 2: SC-CIC

For settings with a single treated unit and multiple donors, `sc_cic()`
combines synthetic control construction with CIC estimation. We demonstrate
on the Basque Country terrorism dataset.

```{r sccic-example}
if (requireNamespace("Synth", quietly = TRUE)) {
  data("basque", package = "Synth")

  # Reshape to wide format
  gdp <- reshape(basque[, c("regionno", "year", "gdpcap")],
                 idvar = "year", timevar = "regionno", direction = "wide")

  y_treated <- gdp[, "gdpcap.17"]  # Basque Country
  donor_cols <- grep("gdpcap\\.", names(gdp), value = TRUE)
  donor_cols <- donor_cols[!donor_cols %in% c("gdpcap.17", "gdpcap.1")]
  donors <- as.matrix(gdp[, donor_cols])

  valid <- complete.cases(y_treated, donors)
  result2 <- sc_cic(y_treated[valid], donors[valid, ],
                    treatment_period = 16, seed = 42)
  print(result2)
}
```

## Bootstrap standard errors

Both functions support bootstrap inference via the `boot` argument:

```{r boot-example, eval = FALSE}
result <- cic(y_00, y_01, y_10, y_11, boot = TRUE, boot_iters = 500, seed = 42)
```

## References

- Athey, S. and Imbens, G. W. (2006). Identification and Inference in
  Nonlinear Difference-in-Differences Models. *Econometrica*, 74(2), 431-497.
- Abadie, A. and Gardeazabal, J. (2003). The Economic Costs of Conflict:
  A Case Study of the Basque Country. *American Economic Review*, 93(1), 113-132.
- Meyer, B. D., Viscusi, W. K., and Durbin, D. L. (1995). Workers'
  Compensation and Injury Duration. *American Economic Review*, 85(3), 322-340.
