Skip to main content

A library for Synthetic Control methods

Project description

SynthCtrl

A Python library for implementing Synthetic Control methods for causal inference, including the Classical Synthetic Control method and Synthetic Difference-in-Differences (SDID).

PyPI version License: MIT

Overview

Synthetic Control is a statistical method used for comparative case studies. It constructs a weighted combination of control units to create a synthetic version of the treated unit, allowing for the estimation of causal effects in settings where a single unit receives treatment and multiple units remain untreated.

This library provides implementations of:

  • Classical Synthetic Control (Abadie & Gardeazabal, 2003)
  • Synthetic Difference-in-Differences (Arkhangelsky et al., 2019)

Installation

pip install SynthCtrl

Features

  • Easy-to-use API with scikit-learn-like interfaces
  • Bootstrap for statistical inference
  • Comprehensive visualization tools

Quick Start

import pandas as pd
from synthetic_control import ClassicSyntheticControl

data = pd.read_csv("california_smoking.csv")

sc = ClassicSyntheticControl(
    data=data,
    metric="cigarettes",
    period_index="year",
    unit_id="state",
    treated="california",
    after_treatment="after_treatment"
)

sc.fit()

predictions = sc.predict()

effect = sc.estimate_effect()
print(f"Average Treatment Effect: {effect['att']:.4f}")

bootstrap_results = sc.bootstrap_effect()
print(f"Standard Error: {bootstrap_results['se']:.2f}")
print(f"95% CI: [{bootstrap_results['ci_lower']:.2f}, {bootstrap_results['ci_upper']:.2f}]")

sc.plot_model_results(figsize=(14, 7), show=True)

Using Synthetic Difference-in-Differences

from synthetic_control import SyntheticDIDModel

sdid_model = SyntheticDIDModel(
    data=data,
    metric="cigarettes",
    period_index="year", 
    unit_id="state",
    treated="california",
    after_treatment="after_treatment"
)

sdid_model.fit()

sdid_model.plot_model_results(figsize=(14, 7), show=True)

Documentation

For detailed documentation, visit the GitHub pages.

Examples

The examples/ directory contains Jupyter notebooks demonstrating various use cases:

  • Basic usage with California smoking data
  • Advanced features and customization
  • Comparison of different methods

Citation

If you use this library in your research, please cite:

@software{SynthCtrl_python,
  author = {Yaroslav Rogoza},
  title = {SynthCtrl: A Python Library for Causal Inference},
  year = {2025},
  url = {https://github.com/123yaroslav/SynthCtrl},
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synthctrl-0.1.0.tar.gz (309.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

synthctrl-0.1.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file synthctrl-0.1.0.tar.gz.

File metadata

  • Download URL: synthctrl-0.1.0.tar.gz
  • Upload date:
  • Size: 309.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for synthctrl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74037eeaf0a084f4a8c395f3bc7a7e221cd78e8510c6d203ea1406cae745c954
MD5 bb95bcbff0d44833053a66362ffe0167
BLAKE2b-256 83b54440beca4940c892e2c68adc6a5f62e2cd1e2328d0dca15536cb3551fd9c

See more details on using hashes here.

File details

Details for the file synthctrl-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: synthctrl-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for synthctrl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 212a589caee1a775a400f57019e262e2191c413cc555f0b0af5cc70efe09fef4
MD5 8bfe92d8e91a92929dbc67c0aaa0b518
BLAKE2b-256 cf9bbdcd20f1f099845119795f7808f61fabe6c2452476b66d78f1ceccc16ff4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page