Functions

didint() - Estimate ATT

The function didint() estimates the ATT while adjusting for covariates that may vary by state, time, or both.

DiDInt.didint — Function
didint(
       outcome::Union{AbstractString, Symbol},
       state::Union{AbstractString, Symbol},
       time::Union{AbstractString, Symbol},
       data::Union{DataFrame, RConnector.RDataFrame};
       gvar::Union{AbstractString, Symbol, Nothing} = nothing,
       treated_states::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing,
       treatment_times::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Date, Nothing} = nothing,
       pvar::Union{AbstractString, Symbol, Nothing} = nothing,
       treated_policies::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing,
       date_format::Union{AbstractString, Nothing} = nothing,
       covariates::Union{T, Vector{T}} where T <: Union{AbstractString, Symbol, Nothing} = nothing,
       ccc::AbstractString = "int",
       agg::AbstractString = "cohort",
       weighting::AbstractString = "both",
       policy_aggregation::Bool = false,
       policy_weighting::AbstractString = "equal",
       ref::Union{Dict{<:AbstractString, <:AbstractString}, Nothing} = nothing,
       freq::Union{AbstractString, Nothing} = nothing,
       freq_multiplier::Number = 1,
       start_date::Union{AbstractString, Number, Date, Nothing} = nothing,
       end_date::Union{AbstractString, Number, Date, Nothing} = nothing,
       nperm::Number = 999,
       ri_kernel_cutoff::Union{Number, Nothing} = 99,
       seed::Number = rand(1:1000000),
       use_pre_controls::Bool = false,
       notyet::Union{Nothing, Bool} = nothing,
       hc::Union{AbstractString, Number} = "hc1",
       truejack::Bool = false,
       edgecase::Bool = false
      )

The didint() function estimates the average effect of treatment on the treated (ATT) while accounting for covariates that may vary by state, time, or by both state and time simultaneously.

Details

The estimator of Karim & Webb (2025) is computed in five steps:

  1. First stage: a covariate-adjusted mean of the outcome, λ(s,t), is estimated for every state s and period t, with the covariate effects restricted as the ccc argument specifies.
  2. Long differences: for every state, the change in λ between a period t and the period just before a cohort's treatment time.
  3. ATT(s,t): for each treated state s and each period t from its treatment time on, its long difference minus the weighted mean of the long differences of its controls: the never-treated states and, with notyet = true, the states not yet treated at t.
  4. Sub-aggregate ATTs: weighted means of the ATT(s,t)'s within the groups of the chosen agg.
  5. Aggregate ATT: the weighted mean of the sub-aggregate ATTs.

With policy_aggregation = true, an optional sixth step pools the ATTs of different policies.

Common adoption (every treated state treated at the same time) is the one-cohort case of the same estimator, so every agg option is available whatever the adoption pattern.

The arguments treated_states and treatment_times should be entered such that the first element in treated_states refers to the state treated at the date entered as the first element in treatment_times, the second element in treated_states refers to the state treated at the date entered as the second element in treatment_times, and so on. A single treatment time applies to every treated state.

Parameters

Required Parameters

  • outcome::Union{AbstractString, Symbol} Input the name of the column which identifies the outcome of interest.
  • state::Union{AbstractString, Symbol} Input the name of the column which identifies the state membership of the observation.
  • time::Union{AbstractString, Symbol} Input the name of the column which identifies the date of the observation.
  • data::Union{DataFrame, RConnector.RDataFrame} The DataFrame to be used for the analysis.

Treatment Specification

  • gvar::Union{AbstractString, Symbol, Nothing} = nothing Name of the column which indicates time of first treatment for each state (missing or 0 for never-treated states). Use either gvar, or treated_states and treatment_times.
  • treated_states::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing A vector of strings or numbers (or a single one) noting the treated state(s), matching the type of the state column.
  • treatment_times::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Date, Nothing} = nothing A vector (or single entry) denoting the associated treatment times of the 'treated_states'.
  • pvar::Union{AbstractString, Symbol, Nothing} = nothing Name of the column which indicates the policy each state adopts (constant within a state; missing, 0, "0" or "" for never-treated states). Use either pvar or treated_policies.
  • treated_policies::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing A vector (or single entry) denoting the policies of the 'treatedstates', in the same order. It cannot be combined with gvar (use pvar instead). If neither pvar nor `treatedpoliciesis given, every treated state has the same policy. Policies only matter for the policy aggregations: controls are never-treated states (and, withnotyet`, not-yet-treated states) whatever their policy.

Model Specification

  • ccc::AbstractString = "int" Specify which version of DID-INT should be used. Options are: "hom", "time", "state", "add", and "int". The long differences are the integrated ones of Karim & Webb (2025, eqs. 46-47): the change in a state's covariate slopes is evaluated at the treated state's covariate means. That covariate term cancels in every ATT(s,t) except under "int", so only "int" estimates with covariates depend on it.
  • agg::AbstractString = "cohort" Enter the aggregation method as a string. Each option groups the ATT(s,t)'s differently: "cohort" (by treatment time), "simple" (by treatment time and period), "state" (by treated state), "sgt" (no grouping: one ATT per treated state and period), "time" (by periods since treatment), "calendar" (by period), and the policy aggregations "policy", "policy_gt", "policy_cohort", "policy_calendar" and "policy_time". Every sub-aggregate is a weighted mean of ATT(s,t) estimates, and agg_att is a weighted mean of the sub-aggregates, so agg_att can differ across agg options (it does not under weighting = "att" or "both"). The policy aggregations form the same sub-aggregates within each policy ("policy" has one per policy) and report each policy's ATT in att_p, on the first row of that policy, instead of agg_att. Unlike the group effects of Callaway & Sant'Anna (2021), which weight a cohort's post-treatment periods equally, "cohort" weights them as weighting specifies.
  • weighting::AbstractString = "both" Decides which of the three averages behind an estimate are weighted by numbers of observations: the controls' long differences within each ATT(s,t) (first), the ATT(s,t)'s within each sub-aggregate ATT (second), and the sub-aggregate ATTs within the aggregate ATT (third). "diff" weights the first, "att" the second and third, "both" all three, and "none" none. Options are: "both", "att", "diff", or "none".
  • policy_aggregation::Bool = false With a policy aggregation, also report the pooled estimate across policies, att_pool, the policy_weighting-weighted mean of the policies' ATTs, with its own inference columns. Its HC standard error has (number of policies - 1) degrees of freedom, so two policies give one degree of freedom. att_pool is the overall ATT across policies for the policy aggregations (they have no agg_att). With a non-policy aggregation there is nothing to pool and the argument is ignored.
  • policy_weighting::AbstractString = "equal" Weight of each policy in att_pool: "equal" (the typical policy), "treated_obs" (the policy's treated observations), "treated_cells" (its number of treated state-periods) or "treated_states" (its number of treated states). Only used with policy_aggregation = true.
  • covariates::Union{T, Vector{T}} where T <: Union{AbstractString, Symbol, Nothing} = nothing A vector of covariates entered as either strings or symbols (or a single covariate string or symbol), or, nothing (default). The order of the covariates matters when covariates are collinear: under ccc = "hom", "state", "time" and "int", a covariate that is a linear combination of covariates listed before it is dropped wherever the covariate slopes are estimated (in all the data, in each state, in each period, or in each state-period cell). A warning names the dropped covariates under "hom", "state" and "time", and under "int" the ATT(s,t)'s that depend on a dropped covariate.
  • notyet::Union{Nothing, Bool} = nothing Determine if pre-treatment periods from treated states should be used as controls (use_pre_controls is an alias).
  • ref::Union{Dict{<:AbstractString, <:AbstractString}, Nothing} = nothing A dictionary specifying which category in a categorical variable should be used as the reference (baseline) category.

Date Processing & Period Grid Construction

  • date_format::Union{AbstractString, Nothing} = nothing Date format (e.g. "yyyy" or "yyyy-mm-dd") to be used when parsing string dates from the time column, or start_date, end_date, and treatment_times arguments.
  • freq::Union{AbstractString, Nothing} = nothing A string indicating the desired timeframe of a period for the analysis. Options are: "year", "month", "week", "day".
  • freq_multiplier::Number = 1 An integer by which the 'freq' argument should be multiplied, e.g. if a two-year period is desired, set freq = "year" and freq_multiplier = 2.
  • start_date::Union{AbstractString, Number, Date, Nothing} = nothing Any data prior this date is dropped, and serves as the starting date for the period grid construction if activated.
  • end_date::Union{AbstractString, Number, Date, Nothing} = nothing Any data after this date is dropped, and serves as the end date for the period grid construction if activated.

Inference

  • nperm::Number = 999 The number of unique permutations (not including the initial assignment of treatment times) to be considered when performing the randomization inference. If no more than nperm unique permutations exist, all of them are used.
  • ri_kernel_cutoff::Union{Number, Nothing} = 99 When the randomization inference uses fewer than ri_kernel_cutoff permutations (because nperm is that small, or because no more unique permutations exist), its p-values are kernel-smoothed (Racine & MacKinnon 2007) instead of counting the placebo estimates at least as large as the observed one. Set it to nothing, false or 0 to never smooth.
  • seed::Number = rand(1:1000000) An integer to set the random seed for the randomization inference procedure. The same seed gives the same permutations. When a seed is given, the global random number generator is left untouched (the default seed is drawn from it).
  • hc::Union{AbstractString, Number} = "hc1" Specify which heteroskedasticity-consistent covariance matrix estimator (HCCME) should be used. Options are 0, 1, 2, 3, and 4 (or "hc0", "hc1", "hc2", "hc3", "hc4"). An ATT(s,t) is estimated from one treated state and its controls, and the treated state's leverage is 1, so its HC2, HC3 and HC4 standard errors are NaN. The HC standard error of a sub-aggregate or aggregate comes from the spread of the estimates it averages and treats them as independent; estimates that share control states are not, so it can be too small. The jackknife and the randomization inference do not rely on that independence.
  • truejack::Bool = false When ccc is set to either "add", "time", or "hom", then in order to get valid jackknife standard errors, we need to re-estimate the DID-INT model from square one (re-running the first stage). This is because the covariate effects in those cases depend on values from across states, so dropping a state will change the lambda values, this is not true for the ccc options of "int" or "state".
  • edgecase::Bool = false When an ATT(s,t) has at least two control states, its standard error can be calculated directly from the regression of differences on the intercept term and treatment indicator. However, when there is only one control state for a particular ATT(s,t), the standard error can still be constructed from the variance and covariance terms of the relevant means. Calculating these edgecase standard errors can be computationally expensive, therefore by default this argument is set to false, but may be toggled on by setting edgecase = true. Under ccc = "int" with covariates the ATT also depends on the treated state's covariate means, and the edgecase standard error is conditional on the observed covariates: it treats those means as fixed. Every edgecase standard error assumes that observations in different state-period cells are independent, as in repeated cross-sections. With panel data, where the same individuals are observed in several periods, it omits the covariances between a state's periods, and the edgecase standard errors are then generally biased. Not available for ccc = "add".

Returns

A DiDIntResult. Displaying it prints a summary of the specification, the aggregate ATT and the sub-aggregate ATTs. Its fields hold the results as tables:

  • agg: the aggregate ATT (for the policy aggregations, the ATT of each policy and, with policy_aggregation = true, the pooled ATT).
  • sub: the sub-aggregate ATTs of the chosen agg, with the weight of each in the aggregate ATT (missing when they are weighted equally).
  • att_st: the ATT of each treated state in each period from its treatment time on.
  • specs: the specification that was estimated, including the period length, the date range and the number of permutations used.
  • table: every result in one wide table (also returned by DataFrame(result)).

In agg and sub the estimates are in the column att, with se and pval (HC standard error and p-value), jknife_se and jknife_pval (jackknife standard error and p-value) and ri_pval (randomization inference p-value). coef(result), stderror(result) and coefnames(result) return the estimates, standard errors and labels as vectors.

The wide table has one row per sub-aggregate ATT:

  • The columns identifying the sub-aggregate: treatment_time ("cohort"), r1, time and gvar ("simple": the period before treatment, the period, and the treatment time), state ("state"), state, gvar and t ("sgt"), periods_post_treat ("time"), t ("calendar"). The policy aggregations add a policy column.
  • The sub-aggregate ATT, in att_cohort, att_gt, att_s, att_sgt, att_t, att_calendar or att_p, and its inference in the columns with the same name prefixed by se_ and pval_ (HC standard error and p-value), jknifese_ and jknifepval_ (jackknife standard error and p-value) and ri_pval_ (randomization inference p-value).
  • The aggregate ATT, agg_att, with se_agg_att, pval_agg_att, jknifese_agg_att, jknifepval_agg_att and ri_pval_agg_att, on the first row. For the policy aggregations each policy's ATT is in att_p (with the same prefixes) on the first row of that policy and, with policy_aggregation = true, the pooled ATT is in att_pool (with the same prefixes) on the first row and each policy's weight in it is in policy_weights.
  • nperm: the number of permutations used in the randomization inference (first row).
  • weights: the weight of each sub-aggregate in the aggregate ATT (for the policy aggregations, in its policy's ATT). It is empty (missing; nothing in the table passed to the wrappers) when the sub-aggregates are weighted equally, under weighting = "none" or "diff".
  • period, start_date and end_date: the period length and the date range of the data used.

A jackknife needs at least two treated and two control states, overall and for each estimate, and the sub-aggregates of "state" and "sgt", which each have a single treated state, never have jackknife standard errors. Estimates that cannot be computed are missing.

Citations

  • Karim & Webb (2025). "Good Controls Gone Bad: Difference-in-Differences with Covariates". https://arxiv.org/abs/2412.14447
  • MacKinnon & Webb (2020). "Randomization inference for difference-in-differences with few treated clusters". https://doi.org/10.1016/j.jeconom.2020.04.024
  • Racine & MacKinnon (2007). "Inference via kernel smoothing of bootstrap P values". https://doi.org/10.1016/j.csda.2006.11.013
  • Callaway & Sant'Anna (2021). "Difference-in-Differences with multiple time periods". https://doi.org/10.1016/j.jeconom.2020.12.001
source

DiDIntResult - Results of didint()

didint() returns its results as a DiDIntResult, which prints a summary when displayed and stores the estimates as tables.

DiDInt.DiDIntResult — Type
DiDIntResult

The results of didint. Displaying it prints a summary of the specification and of the estimates. Its fields hold the estimates as tables:

  • agg::DataFrame: the top-level estimates, one row each. For most aggregations this is the single aggregate ATT. For the policy aggregations it is the ATT of each policy, preceded by the pooled ATT across policies when policy_aggregation = true (the column policy_weight then holds each policy's weight in the pooled ATT).
  • sub::DataFrame: the sub-aggregate ATTs of the chosen agg, one row each, identified by the leading column(s) (for example treatment_time under agg = "cohort"). weight is the weight of each sub-aggregate in the aggregate ATT (or in its policy's ATT); it is missing when the sub-aggregates are weighted equally (weighting = "none" or "diff").
  • att_st::DataFrame: the ATT of each treated state (state) in each period (t) from its treatment time (gvar) on, from which every other estimate is computed, with the number of control states behind it (n_controls) and the treated state's numbers of observations (n_t in period t; n in period t and in the period before treatment, r1, together).
  • specs::NamedTuple: the specification that was estimated (agg, ccc, weighting, nperm, seed, the period length and date range, and so on).
  • table::DataFrame: every result in one wide table, as passed to the Stata and R wrappers.

In agg and sub, the estimate is in att and its inference in se and pval (heteroskedasticity-consistent standard error and p-value), jknife_se and jknife_pval (jackknife standard error and p-value) and ri_pval (randomization inference p-value). Entries that could not be computed are missing.

Methods

  • coef(result; level = :agg), stderror(result; level = :agg, type = :hc) and coefnames(result; level = :agg) return the estimates, their standard errors (type = :hc or :jackknife) and their labels as vectors, for the top-level estimates (level = :agg) or the sub-aggregate ATTs (level = :sub).
  • DataFrame(result) returns the wide table (result.table). A DiDIntResult is also a Tables.jl table, so it can be passed directly to functions such as CSV.write.

Example

result = didint("coll", "state", "year", data; treated_states = states, treatment_times = times)
result                 # prints a summary
result.agg             # the aggregate ATT with its standard errors and p-values
result.sub             # the sub-aggregate ATTs
coef(result)           # the aggregate ATT as a vector
DataFrame(result)      # everything in one wide table
source

The estimates, their standard errors and their labels can also be extracted as vectors:

StatsAPI.coef — Method
coef(result::DiDIntResult; level = :agg)

The ATT estimates as a vector: the top-level estimates (level = :agg, the aggregate ATT or, for the policy aggregations, the pooled ATT and the ATT of each policy) or the sub-aggregate ATTs (level = :sub).

source
StatsAPI.stderror — Method
stderror(result::DiDIntResult; level = :agg, type = :hc)

The standard errors of the estimates returned by coef(result; level = level): heteroskedasticity-consistent (type = :hc) or jackknife (type = :jackknife).

source
StatsAPI.coefnames — Method
coefnames(result::DiDIntResult; level = :agg)

Labels of the estimates returned by coef(result; level = level).

source

The didint_plot() function prepares the data for parallel trends plots and event study plots.

DiDInt.didint_plot — Function
didint_plot(
            outcome::Union{AbstractString, Symbol},
            state::Union{AbstractString, Symbol},
            time::Union{AbstractString, Symbol},
            data::DataFrame;
            gvar::Union{AbstractString, Symbol, Nothing} = nothing,
            treated_states::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing,
            treatment_times::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Date, Nothing} = nothing,
            date_format::Union{AbstractString, Nothing} = nothing,
            covariates::Union{T, Vector{T}} where T <: Union{AbstractString, Symbol, Nothing} = nothing,
            ref::Union{Dict{<:AbstractString, <:AbstractString}, Nothing} = nothing,
            ccc::Union{AbstractString, Vector{<:AbstractString}} = "all",
            plot_type::Union{AbstractString, Vector{<:AbstractString}} = "all",
            notyet::Bool = false,
            weights::Bool = true,
            ci::Number = 0.95,
            freq::Union{AbstractString, Nothing} = nothing,
            freq_multiplier::Number = 1,
            start_date::Union{AbstractString, Number, Date, Nothing} = nothing,
            end_date::Union{AbstractString, Number, Date, Nothing} = nothing,
            hc::Union{AbstractString, Number} = "hc1"
           )

The didint_plot() function prepares the data for parallel trends plots and event study plots. It returns them as a DiDIntPlot, which holds one table per kind of plot and is drawn with plot once a Makie backend such as CairoMakie is loaded.

Details

didint_plot() prepares the data for five kinds of plots (the plot_type argument), all from the first-stage estimates λ(s,t) of Karim & Webb (2025, eq. 45), the mean of the outcome for each state and period, adjusted for covariates as each ccc option specifies and estimated on all states as in didint():

  • "conditional": conditional parallel trends, the λ(s,t) of every state and period under every ccc option except "int".
  • "conditional2": for each treated state, the change in λ of that state and of its control states since the period before the treated state's treatment (the pre-treatment period). These are the differences from which didint() computes its estimates.
  • "integrated": integrated parallel trends (ccc = "int"), the diagnostic of Karim & Webb (2025, eqs. 36-38). The outcome is regressed on the covariates separately in every state-period cell. For each treated state, the change from one period to the next in the predicted outcome is computed for that state and for its control states, all evaluated at the treated state's covariate means in the later period.
  • "integrated2": the same changes measured from the pre-treatment period of the treated state, which are the integrated differences from which didint() computes its estimates under ccc = "int".
  • "event": event study, the λ(s,t) of the treated states averaged by period relative to treatment, for each ccc option.

In "conditional2" and "integrated2", the change of a treated state minus the average change of its control states is its ATT in a treated period, and a placebo estimate in a period before treatment.

The arguments treated_states and treatment_times should be entered such that the first element in treated_states refers to the state treated at the date entered as the first element in treatment_times, the second element in treated_states refers to the state treated at the date entered as the second element in treatment_times, and so on.

Parameters

Required Parameters

  • outcome::Union{AbstractString, Symbol} Input the name of the column which identifies the outcome of interest.
  • state::Union{AbstractString, Symbol} Input the name of the column which identifies the state membership of the observation.
  • time::Union{AbstractString, Symbol} Input the name of the column which identifies the date of the observation.
  • data::DataFrame The DataFrame to be used for the analysis.

Treatment Specification

  • gvar::Union{AbstractString, Symbol, Nothing} = nothing Name of the column which indicates time of first treatment for each state.
  • treatment_times::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Date, Nothing} = nothing A vector (or single entry) denoting the associated treatment times of the 'treated_states'.
  • treated_states::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothing A vector of strings or numbers (or a single one) noting the treated state(s), matching the type of the state column. Every kind of plot data except "conditional" needs the treated states. For "conditional" they are optional; with them, the plot tells the treated states from the control states.

Plot Data

  • plot_type::Union{AbstractString, Vector{<:AbstractString}} = "all" The kinds of plot data to prepare: "all", or any combination of "event", "conditional", "conditional2", "integrated" and "integrated2". With "all", the kinds that the other arguments do not allow are left out: without the treated states only "conditional" is prepared (with a warning).
  • ccc::Union{AbstractString, Vector{<:AbstractString}} = "all" Specify which versions of DID-INT should be used. Options are either "all", or any combination of: "none", "hom", "time", "state", "add", and "int". "none" uses the unadjusted means of the outcome. "int" is the option of the integrated parallel trends data ("integrated" and "integrated2"), and every other option gives conditional parallel trends data ("conditional" and "conditional2"). The event study uses every option given.
  • covariates::Union{T, Vector{T}} where T <: Union{AbstractString, Symbol, Nothing} = nothing A vector of covariates entered as either strings or symbols (or a single covariate string or symbol), or, nothing (default).
  • ref::Union{Dict{<:AbstractString, <:AbstractString}, Nothing} = nothing A dictionary specifying which category in a categorical variable should be used as the reference (baseline) category.

Control States

  • notyet::Bool = false The control states of a treated state are the never-treated states and, with notyet = true, also the states of later cohorts while they are not yet treated, as in didint(). This applies to "conditional2", "integrated" and "integrated2", and to the plots that compare a treated state with its control states.

Event Study

  • weights::Bool = true Whether to use weighted means when computing event study estimates. If true, estimates are computed as weighted averages of state-level means for each period relative to treatment, weighted by the states' numbers of observations; if false, uses simple unweighted averages.
  • ci::Number = 0.95 Define the size of confidence bands for the event study plot.
  • hc::Union{AbstractString, Number} = "hc1" Specify which heteroskedasticity-consistent covariance matrix estimator (HCCME) should be used. Options are 0, 1, 2, 3, and 4 (or "hc0", "hc1", "hc2", "hc3", "hc4").

Date Processing & Period Grid Construction

  • date_format::Union{AbstractString, Nothing} = nothing Date format (e.g. "yyyy" or "yyyy-mm-dd") to be used when parsing string dates from the time column, or start_date, end_date, and treatment_times arguments.
  • freq::Union{AbstractString, Nothing} = nothing A string indicating the desired timeframe of a period for the analysis. Options are: "year", "month", "week", "day".
  • freq_multiplier::Number = 1 An integer by which the 'freq' argument should be multiplied, e.g. if a two-year period is desired, set freq = "year" and freq_multiplier = 2.
  • start_date::Union{AbstractString, Number, Date, Nothing} = nothing Any data prior this date is dropped, and serves as the starting date for the period grid construction if activated.
  • end_date::Union{AbstractString, Number, Date, Nothing} = nothing Any data after this date is dropped, and serves as the end date for the period grid construction if activated.

Returns

A DiDIntPlot, which is drawn with plot. It has one table (a DataFrame) for each kind of plot data that was prepared, in the field of the same name; the others are empty. In every table time is the date of a period and period its number, counted from 0.

  • conditional: one row per state, period and ccc option, with the state's mean outcome in that period, residualized by the covariates as the ccc option specifies (lambda), and the number of observations of the state in that period (n).
  • conditional2: one row per ccc option, treated state (treated_state), state (state: that treated state itself or one of its control states) and period other than the pre-treatment period of treated_state (base_period), with the change in the state's lambda since that period (delta), the number of observations of the state in the two periods (n), and the period in which treated_state is first treated (treat_period).
  • integrated: one row per treated state (treated_state_covars), state (state: that treated state itself or one of its control states) and period from the second one on, with the change in the state's predicted outcome since the previous period, evaluated at the covariate means of treated_state_covars (delta), the number of observations of the state in the two periods (n), and treat_period.
  • integrated2: as integrated, with the change measured from the pre-treatment period of treated_state_covars (base_period), for every other period.
  • event: one row per ccc option and period relative to treatment (time_since_treatment), with the mean of the treated states' lambda values (y), its standard error (se), the bounds of its confidence interval (ci_lower, ci_upper) and the number of treated states behind it (ngroup).

Citations

  • Karim & Webb (2025). "Good Controls Gone Bad: Difference-in-Differences with Covariates". https://arxiv.org/abs/2412.14447
source

DiDIntPlot - Plot Data and Plots

didint_plot() returns its data as a DiDIntPlot, which prints a summary when displayed, stores the data of each kind of plot as a table, and is drawn with plot once a Makie backend such as CairoMakie is loaded.

DiDInt.DiDIntPlot — Type
DiDIntPlot

The data that didint_plot prepares, which are drawn with plot. Displaying it prints a summary.

Fields

One table (a DataFrame) for each kind of plot, described under "Returns" in didint_plot. A table is empty if that kind of plot data was not prepared.

  • conditional: the mean outcome of each state and period, adjusted for covariates (lambda), by ccc option.
  • conditional2: for each ccc option and treated state, the change in lambda of that state and of its control states since the period before its treatment (delta).
  • integrated: for each treated state, the change in the predicted outcome of that state and of its control states since the previous period, at the treated state's covariate means (delta).
  • integrated2: the same change measured from the period before the treated state's treatment.
  • event: the event study estimates by ccc option and period relative to treatment.
  • event_lambdas: the lambda of each treated state behind event, by ccc option and period relative to treatment (time_since_treatment), with the state's number of observations (n).
  • specs::NamedTuple: the specification (outcome, plot_types, ccc, covariates, treated_states with their treatment_times and treatment_periods, notyet, weights, ci, the period length and date range, and so on).

Plotting

Plots are drawn with Makie: load one of its backends and call plot, which returns a Makie Figure.

using CairoMakie
x = didint_plot("coll", "state", "year", data;
                treated_states = states, treatment_times = times,
                covariates = ["asian", "black", "male"])

# Conditional parallel trends, one panel per ccc option
plot(x)

# Integrated parallel trends, one panel per treated state
plot(x; plot_type = "integrated")

# Two treated states next to their control states, under ccc = "hom"
figure = plot(x; facet = "state", ccc = "hom", treated_states = ["71", "58"])
save("trends.png", figure)
plot(x::DiDIntPlot; plot_type, treated_states, ccc, window,
     facet, controls, weights, groupmin, ncols, size, title, theme)

What is plotted

  • plot_type::Union{AbstractString, Nothing} = nothing One of the kinds of plot data that x holds:

    • "event": the event study, one panel per ccc option.
    • "conditional": the conditional parallel trends, the mean outcome (adjusted for covariates) by period (see facet).
    • "conditional2": the conditional parallel trends as changes since the pre-treatment period, one panel per treated state and ccc option: the change in the treated state's adjusted mean outcome since the period before its treatment, next to the average change of its control states.
    • "integrated": the integrated parallel trends of ccc = "int", one panel per treated state, as changes since the previous period.
    • "integrated2": the same as changes since the pre-treatment period.

    In "conditional2" and "integrated2" both lines are zero in the pre-treatment period. The gap between them is the treated state's ATT in each treated period, as didint() estimates it, and a placebo estimate in each period before treatment, which is close to zero if the trends were parallel before treatment.

    By default: the conditional parallel trends if x has them, otherwise the first kind that it has.

  • treated_states = nothing The treated state(s) to show, as a single value or a vector. By default all of them.

  • ccc = nothing The ccc option(s) to show in an event study or a conditional parallel trends plot, as a string or a vector of strings. By default all of those in the data. The integrated parallel trends plots are those of "int".

  • window = nothing A pair (first, last) that limits the horizontal axis: periods relative to treatment for an event study, period numbers (the period column) otherwise.

Parallel trends plots

  • facet::AbstractString = "ccc" For plot_type = "conditional": "ccc" draws one panel per ccc option with a line for every state; "state" draws one panel per treated state and ccc option (a row of panels per treated state), comparing the treated state with its control states. "conditional2" is always drawn that way. ccc selects the options in both.
  • controls::AbstractString = "average" In the panels of a treated state (every plot type except "event" and "conditional" with facet = "ccc"): "average" draws one line for the average of the control states, "separate" a line for each control state.
  • weights::Union{Bool, Nothing} = nothing Whether the average of the control states weights them by their numbers of observations (true, the default) or equally (false). For an event study: whether the treated states are weighted by their numbers of observations; the default is the choice made in didint_plot().

Event study plots

  • groupmin::Integer = 3 The smallest number of treated states behind an estimate for its confidence interval to be drawn. Intervals that rest on very few states are too wide to be of use.

Appearance

  • ncols::Union{Integer, Nothing} = nothing: number of columns of panels. By default one per ccc option when the panels are those of treated states under several options, otherwise about the square root of the number of panels.
  • size::Union{Tuple, Nothing} = nothing: size of the figure, as (width, height).
  • title::Union{AbstractString, Nothing} = nothing: title of the figure; "" for none.
  • theme: a Makie Theme that replaces the default look.

The control states of a treated state are the never-treated states and, if didint_plot() was called with notyet = true, the states of later cohorts while they are not yet treated, as in didint(). Panels of treated states are ordered from the earliest treated state to the latest. A dashed vertical line marks the first treated period.

source