TWFE#
- class differences.twfe.twfe.TWFE(data: DataFrame, cohort_name: str, cohort_data: DataFrame | None = None, intensity_name: str | None = None, freq: str | None = None, stacked: bool = False)#
Two-way fixed effect regression
balanced panels, unbalanced panels
two or multiple periods
fixed or staggered treatment timing
binary treatment, with various intensities
one or multiple treatments per entity
- Parameters:
data (DataFrame) –
pandas DataFrame
df = df.set_index(['entity', 'time'])
where df is the dataframe to use, ‘entity’ should be replaced with the name of the entity column and ‘time’ should be replaced with the name of the time column.
cohort_name (str) – cohort name
cohort_data (DataFrame) – cohort data, in place of cohort name
intensity_name (str) – name of the column with treatment intensities
freq (str | None, default:
None) – the date frequency of the panel data. Required if the time index is datetime. For example, if the time column is a monthly datetime then freq=’M’. Check offset aliases, for a list of available frequencies.
- fit(formula: str, start: int = None, end: int = None, reference_period: int | None = -1, bin_endpoints: bool | str = True, weights_name: str = None, cluster_names: str | list = None, alpha: float = 0.05, use_intensity: bool = False, drop_singletons: bool = True, drop_absorbed: bool = False, dummies_names: list[str] = None, drop_names: list[str] = None)#
fit two-way fixed effect
- Parameters:
formula (str) –
Wilkinson formula for the outcome variable and covariates
If no covariates the formula must contain only the name of the outcome variable
# example with covariates formula = 'y ~ a + b + a:b' # example without covariates formula = 'y'
Formulas are implemented using formulaic, refer to its documentation for additional details.
start – first relative period
end – last relative period
reference_period – reference period
bin_endpoints –
weights_name: str | None, default:
NoneThe name of the column containing the sampling weights. If None, all observations have same weights.
weights_name –
cluster_names –
alpha –
use_intensity –
drop_singletons –
drop_absorbed –
dummies_names –
drop_names –