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:
- First stage: a covariate-adjusted mean of the outcome,
λ(s,t), is estimated for every statesand periodt, with the covariate effects restricted as thecccargument specifies. - Long differences: for every state, the change in
λbetween a periodtand the period just before a cohort's treatment time. - ATT(s,t): for each treated state
sand each periodtfrom its treatment time on, its long difference minus the weighted mean of the long differences of its controls: the never-treated states and, withnotyet = true, the states not yet treated att. - Sub-aggregate ATTs: weighted means of the ATT(s,t)'s within the groups of the chosen
agg. - 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} = nothingName of the column which indicates time of first treatment for each state (missing or0for never-treated states). Use eithergvar, ortreated_statesandtreatment_times.treated_states::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothingA vector of strings or numbers (or a single one) noting the treated state(s), matching the type of thestatecolumn.treatment_times::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Date, Nothing} = nothingA vector (or single entry) denoting the associated treatment times of the 'treated_states'.pvar::Union{AbstractString, Symbol, Nothing} = nothingName of the column which indicates the policy each state adopts (constant within a state; missing,0,"0"or""for never-treated states). Use eitherpvarortreated_policies.treated_policies::Union{T, Vector{T}} where T <: Union{AbstractString, Number, Nothing} = nothingA vector (or single entry) denoting the policies of the 'treatedstates', in the same order. It cannot be combined withgvar(usepvarinstead). If neitherpvarnor `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, andagg_attis a weighted mean of the sub-aggregates, soagg_attcan differ acrossaggoptions (it does not underweighting = "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 inatt_p, on the first row of that policy, instead ofagg_att. Unlike the group effects of Callaway & Sant'Anna (2021), which weight a cohort's post-treatment periods equally,"cohort"weights them asweightingspecifies.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 = falseWith a policy aggregation, also report the pooled estimate across policies,att_pool, thepolicy_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_poolis the overall ATT across policies for the policy aggregations (they have noagg_att). With a non-policy aggregation there is nothing to pool and the argument is ignored.policy_weighting::AbstractString = "equal"Weight of each policy inatt_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 withpolicy_aggregation = true.covariates::Union{T, Vector{T}} where T <: Union{AbstractString, Symbol, Nothing} = nothingA 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: underccc = "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} = nothingDetermine if pre-treatment periods from treated states should be used as controls (use_pre_controlsis an alias).ref::Union{Dict{<:AbstractString, <:AbstractString}, Nothing} = nothingA 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} = nothingDate format (e.g. "yyyy" or "yyyy-mm-dd") to be used when parsing string dates from the time column, orstart_date,end_date, andtreatment_timesarguments.freq::Union{AbstractString, Nothing} = nothingA string indicating the desired timeframe of a period for the analysis. Options are:"year","month","week","day".freq_multiplier::Number = 1An integer by which the 'freq' argument should be multiplied, e.g. if a two-year period is desired, setfreq = "year"andfreq_multiplier = 2.start_date::Union{AbstractString, Number, Date, Nothing} = nothingAny 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} = nothingAny data after this date is dropped, and serves as the end date for the period grid construction if activated.
Inference
nperm::Number = 999The number of unique permutations (not including the initial assignment of treatment times) to be considered when performing the randomization inference. If no more thannpermunique permutations exist, all of them are used.ri_kernel_cutoff::Union{Number, Nothing} = 99When the randomization inference uses fewer thanri_kernel_cutoffpermutations (becausenpermis 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 tonothing,falseor0to 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 are0,1,2,3, and4(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 areNaN. 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 = falseWhencccis 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 thecccoptions of"int"or"state".edgecase::Bool = falseWhen 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 theseedgecasestandard errors can be computationally expensive, therefore by default this argument is set tofalse, but may be toggled on by settingedgecase = true. Underccc = "int"with covariates the ATT also depends on the treated state's covariate means, and theedgecasestandard error is conditional on the observed covariates: it treats those means as fixed. Everyedgecasestandard 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 theedgecasestandard errors are then generally biased. Not available forccc = "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, withpolicy_aggregation = true, the pooled ATT).sub: the sub-aggregate ATTs of the chosenagg, with the weight of each in the aggregate ATT (missingwhen 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 byDataFrame(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,timeandgvar("simple": the period before treatment, the period, and the treatment time),state("state"),state,gvarandt("sgt"),periods_post_treat("time"),t("calendar"). The policy aggregations add apolicycolumn. - The sub-aggregate ATT, in
att_cohort,att_gt,att_s,att_sgt,att_t,att_calendaroratt_p, and its inference in the columns with the same name prefixed byse_andpval_(HC standard error and p-value),jknifese_andjknifepval_(jackknife standard error and p-value) andri_pval_(randomization inference p-value). - The aggregate ATT,
agg_att, withse_agg_att,pval_agg_att,jknifese_agg_att,jknifepval_agg_attandri_pval_agg_att, on the first row. For the policy aggregations each policy's ATT is inatt_p(with the same prefixes) on the first row of that policy and, withpolicy_aggregation = true, the pooled ATT is inatt_pool(with the same prefixes) on the first row and each policy's weight in it is inpolicy_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;nothingin the table passed to the wrappers) when the sub-aggregates are weighted equally, underweighting = "none"or"diff".period,start_dateandend_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
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
DiDIntResultThe 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 whenpolicy_aggregation = true(the columnpolicy_weightthen holds each policy's weight in the pooled ATT).sub::DataFrame: the sub-aggregate ATTs of the chosenagg, one row each, identified by the leading column(s) (for exampletreatment_timeunderagg = "cohort").weightis the weight of each sub-aggregate in the aggregate ATT (or in its policy's ATT); it ismissingwhen 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_tin periodt;nin periodtand 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)andcoefnames(result; level = :agg)return the estimates, their standard errors (type = :hcor: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). ADiDIntResultis also a Tables.jl table, so it can be passed directly to functions such asCSV.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 tableThe 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).
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).
StatsAPI.coefnames — Method
coefnames(result::DiDIntResult; level = :agg)Labels of the estimates returned by coef(result; level = level).
didint_plot() - Parallel Trends and Event Study Plots
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 everycccoption 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 whichdidint()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 whichdidint()computes its estimates underccc = "int"."event": event study, theλ(s,t)of the treated states averaged by period relative to treatment, for eachcccoption.
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::DataFrameThe DataFrame to be used for the analysis.
Treatment Specification
gvar::Union{AbstractString, Symbol, Nothing} = nothingName 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} = nothingA 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} = nothingA vector of strings or numbers (or a single one) noting the treated state(s), matching the type of thestatecolumn. 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} = nothingA 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} = nothingA dictionary specifying which category in a categorical variable should be used as the reference (baseline) category.
Control States
notyet::Bool = falseThe control states of a treated state are the never-treated states and, withnotyet = true, also the states of later cohorts while they are not yet treated, as indidint(). This applies to"conditional2","integrated"and"integrated2", and to the plots that compare a treated state with its control states.
Event Study
weights::Bool = trueWhether to use weighted means when computing event study estimates. Iftrue, estimates are computed as weighted averages of state-level means for each period relative to treatment, weighted by the states' numbers of observations; iffalse, uses simple unweighted averages.ci::Number = 0.95Define 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 are0,1,2,3, and4(or"hc0","hc1","hc2","hc3","hc4").
Date Processing & Period Grid Construction
date_format::Union{AbstractString, Nothing} = nothingDate format (e.g. "yyyy" or "yyyy-mm-dd") to be used when parsing string dates from the time column, orstart_date,end_date, andtreatment_timesarguments.freq::Union{AbstractString, Nothing} = nothingA string indicating the desired timeframe of a period for the analysis. Options are:"year","month","week","day".freq_multiplier::Number = 1An integer by which the 'freq' argument should be multiplied, e.g. if a two-year period is desired, setfreq = "year"andfreq_multiplier = 2.start_date::Union{AbstractString, Number, Date, Nothing} = nothingAny 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} = nothingAny 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 andcccoption, with the state's mean outcome in that period, residualized by the covariates as thecccoption specifies (lambda), and the number of observations of the state in that period (n).conditional2: one row percccoption, treated state (treated_state), state (state: that treated state itself or one of its control states) and period other than the pre-treatment period oftreated_state(base_period), with the change in the state'slambdasince that period (delta), the number of observations of the state in the two periods (n), and the period in whichtreated_stateis 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 oftreated_state_covars(delta), the number of observations of the state in the two periods (n), andtreat_period.integrated2: asintegrated, with the change measured from the pre-treatment period oftreated_state_covars(base_period), for every other period.event: one row percccoption and period relative to treatment (time_since_treatment), with the mean of the treated states'lambdavalues (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
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
DiDIntPlotThe 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), bycccoption.conditional2: for eachcccoption and treated state, the change inlambdaof 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 bycccoption and period relative to treatment.event_lambdas: thelambdaof each treated state behindevent, bycccoption 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_stateswith theirtreatment_timesandtreatment_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} = nothingOne of the kinds of plot data thatxholds:"event": the event study, one panel percccoption."conditional": the conditional parallel trends, the mean outcome (adjusted for covariates) by period (seefacet)."conditional2": the conditional parallel trends as changes since the pre-treatment period, one panel per treated state andcccoption: 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 ofccc = "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, asdidint()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
xhas them, otherwise the first kind that it has.treated_states = nothingThe treated state(s) to show, as a single value or a vector. By default all of them.ccc = nothingThecccoption(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 = nothingA pair(first, last)that limits the horizontal axis: periods relative to treatment for an event study, period numbers (theperiodcolumn) otherwise.
Parallel trends plots
facet::AbstractString = "ccc"Forplot_type = "conditional":"ccc"draws one panel percccoption with a line for every state;"state"draws one panel per treated state andcccoption (a row of panels per treated state), comparing the treated state with its control states."conditional2"is always drawn that way.cccselects the options in both.controls::AbstractString = "average"In the panels of a treated state (every plot type except"event"and"conditional"withfacet = "ccc"):"average"draws one line for the average of the control states,"separate"a line for each control state.weights::Union{Bool, Nothing} = nothingWhether 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 indidint_plot().
Event study plots
groupmin::Integer = 3The 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 percccoption 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 MakieThemethat 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.