Results

DiffinDiffsBase.AbstractDIDResultType
AbstractDIDResult{TR<:AbstractTreatment} <: StatisticalModel

Interface supertype for all types that collect estimation results for difference-in-differences with treatment of type TR.

Interface definition

Required methodDefault definitionBrief description
coef(r)r.coefVector of point estimates for all coefficients including covariates
vcov(r)r.vcovVariance-covariance matrix for estimates in coef
vce(r)r.vceCovariance estimator
confint(r)Based on t or normal distributionConfidence interval for estimates in coef
treatment(r)r.trTreatment specification
nobs(r)r.nobsNumber of observations (table rows) involved in estimation
outcomename(r)r.ynameName of the outcome variable
coefnames(r)r.coefnamesNames (Vector{String}) of all coefficients including covariates
treatcells(r)r.treatcellsTables.jl-compatible tabular description of treatment coefficients in the order of coefnames (without covariates)
weights(r)r.weightsName of the column containing sample weights (if specified)
ntreatcoef(r)size(treatcells(r), 1)Number of treatment coefficients
treatcoef(r)view(coef(r), 1:ntreatcoef(r))A view of treatment coefficients
treatvcov(r)(N = ntreatcoef(r); view(vcov(r), 1:N, 1:N))A view of variance-covariance matrix for treatment coefficients
treatnames(r)coefnames(r)[1:ntreatcoef(r)]Names (Vector{String}) of treatment coefficients
Optional methods
parent(r)r.parent or rResult object from which r is generated
dof_residual(r)r.dof_residual or nothingResidual degrees of freedom
responsename(r)outcomename(r)Name of the outcome variable
coefinds(r)r.coefinds or nothingLookup table (Dict{String,Int}) from coefnames to integer indices (for retrieving estimates by name)
ncovariate(r)length(coef(r)) - ntreatcoef(r)Number of covariate coefficients
DiffinDiffsBase.AggregatedDIDResultType
AggregatedDIDResult{TR,P<:DIDResult} <: AbstractDIDResult{TR}

Supertype for all types that collect estimation results aggregated from a DIDResult of type P with treatment of type TR.

DiffinDiffsBase.TransSubDIDResultType
TransSubDIDResult{TR,P,M,I,TI} <: AbstractDIDResult{TR}

Estimation results obtained from a linear transformation of a subset of coefficient estimates from DIDResult. See also TransformedDIDResult, lincom and rescale.

Parameters

  • P: type of the result that is transformed.
  • M: type of the matrix representing the linear transformation.
  • I: type of indices for all coefficients.
  • TI: type of indices for treatment coefficients.
Base.parentMethod
parent(r::AbstractDIDResult)

Return the AbstractDIDResult from which r is generated.

Base.viewMethod
view(r::AbstractDIDResult, inds)

Return a SubDIDResult that lazily references elements from r at the given index or indices inds without constructing a copied subset.

DiffinDiffsBase._treatnamesMethod
_treatnames(treatcells)

Generate names for treatment coefficients. Assume treatcells is compatible with the Tables.jl interface.

DiffinDiffsBase.checktreatindexMethod
checktreatindex(inds, tinds)

Check whether all indices for treatment coefficients tinds are positioned before any other index in inds. This is required to be true for methods such as treatcoef and treatvcov to work properly. If the test fails, an ArgumentError exception is thrown.

DiffinDiffsBase.coefindsMethod
coefinds(r::AbstractDIDResult)

Return the map from coefficient names to integer indices for retrieving estimates by name.

DiffinDiffsBase.lincomFunction
lincom(r::AbstractDIDResult, linmap::AbstractMatrix{<:Real}, subset=nothing)

Linearly transform the coefficient estimates from DID result r through a matrix linmap. The number of columns of linmap must match the total number of coefficients from r. If linmap is not square (with fewer rows than columns), subset must be specified with indices representing coefficients that remain after the transformation. See also rescale.

DiffinDiffsBase.parse_didargs!Method
parse_didargs!(args::Vector{Any}, kwargs::Dict{Symbol,Any})

Return a Dict that is suitable for being passed to valid_didargs for further processing.

Any TreatmentTerm in args is decomposed. Any collection of terms is converted to TermSet. Keys are assigned to all positional arguments based on their types. An optional name for StatsSpec can be included in args as a string. The order of positional arguments is irrelevant.

This function is required for @specset to work properly.

DiffinDiffsBase.post!Method
post!(f, ::StataPostHDF, r::AbstractDIDResult; kwargs...)

Export result r for Stata module posthdf. A subset of field values from r are placed in f by setting key-value pairs, where f can be either an HDF5.Group or any object that can be indexed by strings.

Keywords

  • model::String=repr(typeof(r)): name of the model.
  • fields::Union{AbstractVector{<:Union{Symbol, Pair{String,Symbol}}}, Nothing}=nothing: additional fields to be exported; alternative names can be specified with Pairs.
  • at::Union{AbstractVector{<:Real}, Bool, Nothing}=nothing: post the at vector in Stata.
DiffinDiffsBase.rescaleFunction
rescale(r::AbstractDIDResult, scale::AbstractVector{<:Real}, subset=nothing)
rescale(r::AbstractDIDResult, by::Pair, subset=nothing)

Rescale the coefficient estimates from DID result r. The order of elements in scale must match the order of coefficients. If the length of scale is smaller than the total number of coefficient, subset must be specified with indices representing coefficients that remain after the transformation. Alternatively, if by is specified in the same way for apply, the scales can be computed based on values in treatcells(r). In this case, only treatment coefficients are transformed even if subset is not specified. See lincom for more general transformation.

DiffinDiffsBase.treatcellsMethod
treatcells(r::AbstractDIDResult)

Return a Tables.jl-compatible tabular description of treatment coefficients in the order of coefnames (without covariates).

DiffinDiffsBase.treatindexMethod
treatindex(ntcoef::Int, I)

Extract indices referencing the treatment coefficients from I based on the total number of treatment coefficients ntcoef.

DiffinDiffsBase.treatvcovMethod
treatvcov(r::AbstractDIDResult)

Return a view of variance-covariance matrix for treatment coefficients.

DiffinDiffsBase.valid_didargsMethod
valid_didargs(args::Dict{Symbol,Any})

Return a tuple of objects that can be accepted by the constructor of StatsSpec. If no DiffinDiffsEstimator is found in args, try to select one based on other information.

This function is required for @specset to work properly.

DiffinDiffsBase.vceMethod
vce(r::AbstractDIDResult)

Return the covariance estimator used to estimate variance-covariance matrix.

StatsAPI.coefMethod
coef(r::AbstractDIDResult, name::String)
coef(r::AbstractDIDResult, name::Symbol)
coef(r::AbstractDIDResult, i::Int)
coef(r::AbstractDIDResult, inds)

Retrieve a point estimate by name (as in coefnames) or integer index. Return a vector of estimates if an iterable collection of names or integers are specified.

Indexing by name requires the method coefinds(r). See also AbstractDIDResult.

StatsAPI.coefMethod
coef(r::AbstractDIDResult, bys::Pair...)

Return a vector of point estimates for treatment coefficients selected based on the specified functions that return either true or false.

Depending on the argument(s) accepted by a function f, it is specified with argument bys as either column_index => f or column_indices => f where column_index is either a Symbol or Int for a column in treatcells and column_indices is an iterable collection of such indices for multiple columns. f is applied elementwise to each specified column to obtain a BitVector for selecting coefficients. If multiple Pairs are provided, the results are combined into one BitVector through bit-wise and.

Note

This method only selects estimates for treatment coefficients. Covariates are not taken into account.

StatsAPI.coefMethod
coef(r::AbstractDIDResult)

Return the vector of point estimates for all coefficients.

StatsAPI.coefnamesMethod
coefnames(r::AbstractDIDResult)

Return a vector of coefficient names.

StatsAPI.confintMethod
confint(r::AbstractDIDResult; level::Real=0.95)

Return a confidence interval for each coefficient estimate. The returned object is of type Tuple{Vector{Float64}, Vector{Float64}} where the first vector collects the lower bounds for all intervals and the second one collects the upper bounds.

StatsAPI.dof_residualMethod
dof_residual(r::AbstractDIDResult)

Return the residual degrees of freedom.

StatsAPI.nobsMethod
nobs(r::AbstractDIDResult)

Return the number of observations (table rows) involved in estimation.

StatsAPI.responsenameMethod
responsename(r::AbstractDIDResult)

Return the name of outcome variable generated by StatsModels.coefnames. This method is an alias of outcomename.

StatsAPI.vcovFunction
vcov(r::AbstractDIDResult, name1::Union{String, Symbol}, name2::Union{String, Symbol}=name1)
vcov(r::AbstractDIDResult, i::Int, j::Int=i)
vcov(r::AbstractDIDResult, inds)

Retrieve the covariance between two coefficients by name (as in coefnames) or integer index. Return the variance if only one name or index is specified. Return a variance-covariance matrix for selected coefficients if an iterable collection of names or integers are specified.

Indexing by name requires the method coefinds(r). See also AbstractDIDResult.

StatsAPI.vcovMethod
vcov(r::AbstractDIDResult, bys::Pair...)

Return a variance-covariance matrix for treatment coefficients selected based on the specified functions that return either true or false.

Depending on the argument(s) accepted by a function f, it is specified with argument bys as either column_index => f or column_indices => f where column_index is either a Symbol or Int for a column in treatcells and column_indices is an iterable collection of such indices for multiple columns. f is applied elementwise to each specified column to obtain a BitVector for selecting coefficients. If multiple Pairs are provided, the results are combined into one BitVector through bit-wise and.

Note

This method only selects estimates for treatment coefficients. Covariates are not taken into account.

StatsAPI.vcovMethod
vcov(r::AbstractDIDResult)

Return the variance-covariance matrix for all coefficient estimates.

StatsAPI.weightsMethod
weights(r::AbstractDIDResult)

Return the column name of the weight variable. Return nothing if weights is not specified for estimation.

DiffinDiffsBase.@didMacro
@did [option option=val ...] "name" args... kwargs...

Conduct difference-in-differences estimation with the specified arguments. The order of the arguments is irrelevant.

Arguments

  • [option option=val ...]: optional settings for @did including keyword arguments passed to an instance of StatsSpec.
  • name::AbstractString: an optional name for the StatsSpec.
  • args... kwargs...: a list of arguments to be processed by parse_didargs! and valid_didargs.

Notes

When expanded outside @specset, a StatsSpec is constructed and then estimated by calling this instance. Options for [StatsSpec] can be provided in a bracket [...] as the first argument after @did with each option separated by white space. For options that take a Boolean value, specifying the name of the option is enough for setting the value to be true. By default, only a result object that is a subtype of DIDResult is returned.

When expanded inside @specset, @did informs @specset the methods for processing the arguments. Any option specified in the bracket is ignored.

Options for the behavior of @did can be provided in a bracket [...] as the first argument with each option separated by white space. For options that take a Boolean value, specifying the name of the option is enough for setting the value to be true.

The following options are available for altering the behavior of @did:

  • noproceed::Bool=false: return the constructed StatsSpec without conducting the procedure.
  • verbose::Bool=false: print the name of each step when it is called.
  • keep=nothing: names (of type Symbol) of additional objects to be returned.
  • keepall::Bool=false: return all objects generated by procedures along with arguments from the StatsSpecs.
  • pause::Int=0: break the iteration over StatsSteps after finishing the specified number of steps (for debugging).
InteractionWeightedDIDs.AggregatedRegDIDResultType
AggregatedRegDIDResult{TR,Haslsweights,P<:RegressionBasedDIDResult,I} <: AggregatedDIDResult{TR,P}

Estimation results aggregated from a RegressionBasedDIDResult. See also agg.

Fields

  • parent::P: the RegressionBasedDIDResult from which the results are generated.
  • inds::I: indices of the coefficient estimates from parent used to generate the results.
  • coef::Vector{Float64}: coefficient estimates.
  • vcov::Matrix{Float64}: variance-covariance matrix for the estimates.
  • coefweights::Matrix{Float64}: coefficient weights used to aggregate the coefficient estimates from parent.
  • treatweights::Vector{Float64}: sum of treatweights from parent over combined treatcells.
  • treatcounts::Vector{Int}: sum of treatcounts from parent over combined treatcells.
  • coefnames::Vector{String}: coefficient names.
  • coefinds::Dict{String, Int}: a map from coefnames to integer indices for retrieving estimates by name.
  • treatcells::VecColumnTable: cells combined from the treatcells from parent.
  • lsweights::Union{TableIndexedMatrix, Nothing}: cell-level least-square weights.
  • cellymeans::Union{Vector{Float64}, Nothing}: cell-level averages of the outcome variable.
  • cellweights::Union{Vector{Float64}, Nothing}: total sample weights for each cell.
  • cellcounts::Union{Vector{Int}, Nothing}: number of observations for each cell.
InteractionWeightedDIDs.ContrastResultType
ContrastResult{T,M,R,C} <: AbstractMatrix{T}

Matrix type that holds least-square weights obtained from one or more RegDIDResultOrAggs computed over the same set of cells and cell-level averages. See also contrast.

The least-square weights are stored in a Matrix that can be retrieved with property name :m, where the weights for each treatment coefficient are stored columnwise starting from the second column and the first column contains the cell-level averages of outcome variable. The indices for cells can be accessed with property name :r; and indices for identifying the coefficients can be accessed with property name :c. The RegDIDResultOrAggs used to generate the ContrastResult can be accessed by calling parent.

InteractionWeightedDIDs.RegressionBasedDIDResultType
RegressionBasedDIDResult{TR,CohortInteracted,Haslsweights} <: DIDResult{TR}

Estimation results from regression-based difference-in-differences.

Fields

  • coef::Vector{Float64}: coefficient estimates.
  • vcov::Matrix{Float64}: variance-covariance matrix for the estimates.
  • vce::CovarianceEstimator: variance-covariance estiamtor.
  • tr::TR: treatment specification.
  • pr::AbstractParallel: parallel trend assumption.
  • treatweights::Vector{Float64}: total sample weights from observations for which the corresponding treatment indicator takes one.
  • treatcounts::Vector{Int}: total number of observations for which the corresponding treatment indicator takes one.
  • esample::BitVector: indicator for the rows from data involved in estimation.
  • nobs::Int: number of observations involved in estimation.
  • dof_residual::Int: residual degree of freedom.
  • F::Float64: F-statistic for overall significance of regression model.
  • p::Float64: p-value corresponding to the F-statistic.
  • yname::String: name of the outcome variable.
  • coefnames::Vector{String}: coefficient names.
  • coefinds::Dict{String, Int}: a map from coefnames to integer indices for retrieving estimates by name.
  • treatcells::VecColumnTable: a tabular description of cells where a treatment indicator takes one.
  • treatname::Symbol: column name for the variable representing treatment time.
  • yxterms::Dict{AbstractTerm, AbstractTerm}: a map from all specified terms to concrete terms.
  • yterm::AbstractTerm: the specified term for outcome variable.
  • xterms::Vector{AbstractTerm}: the specified terms for covariates and fixed effects.
  • contrasts::Union{Dict{Symbol, Any}, Nothing}: contrast coding to be processed by StatsModels.jl.
  • weightname::Union{Symbol, Nothing}: column name of the sample weight variable.
  • fenames::Vector{String}: names of the fixed effects.
  • nfeiterations::Union{Int, Nothing}: number of iterations for the fixed effect solver to reach convergence.
  • feconverged::Union{Bool, Nothing}: whether the fixed effect solver has converged.
  • nfesingledropped::Int: number of singleton observations for fixed effects that have been dropped.
  • lsweights::Union{TableIndexedMatrix, Nothing}: cell-level least-square weights.
  • cellymeans::Union{Vector{Float64}, Nothing}: cell-level averages of the outcome variable.
  • cellweights::Union{Vector{Float64}, Nothing}: total sample weights for each cell.
  • cellcounts::Union{Vector{Int}, Nothing}: number of observations for each cell.
DiffinDiffsBase.aggFunction
agg(r::RegressionBasedDIDResult{<:DynamicTreatment}, names=nothing; kwargs...)

Aggregate coefficient estimates from r by values taken by the columns from r.treatcells indexed by names with weights proportional to treatweights within each relative time.

Keywords

  • bys=nothing: columnwise transformations over r.treatcells before grouping by names.
  • subset=nothing: subset of treatment coefficients used for aggregation.
DiffinDiffsBase.post!Function
post!(gl, gr, gd, ::StataPostHDF, cr::ContrastResult, left::Int=2, right::Int=3; kwargs...)

Export the least-square weights for coefficients indexed by left and right from cr for Stata module posthdf. The contribution of each cell to the difference between two coefficients are computed and also exported. The weights and contributions are stored as coefficient estimates in three groups gl, gr and gd respectively. The groups can be HDF5.Groups or objects that can be indexed by strings.

Keywords

  • lefttag::String=string(left): name to be used as depvar in Stata after being prefixed by "l_" for the coefficient indexed by left.
  • righttag::String=string(right): name to be used as depvar in Stata after being prefixed by "r_" for the coefficient indexed by right.
  • model::String="InteractionWeightedDIDs.ContrastResult": name of the model.
  • eqnames::Union{AbstractVector, Nothing}=nothing: equation names prefixed to coefficient names in Stata.
  • colnames::Union{AbstractVector, Nothing}=nothing: column names used as coefficient names in Stata.
  • at::Union{AbstractVector{<:Real}, Nothing}=nothing: the at vector in Stata.
FixedEffectModels.has_feMethod
has_fe(r::RegressionBasedDIDResult)

Test whether any fixed effect is involved in regression.

InteractionWeightedDIDs.contrastMethod
contrast(r1::RegDIDResultOrAgg, rs::RegDIDResultOrAgg...; kwargs)

Construct a ContrastResult by collecting the computed least-square weights from each of the RegDIDResultOrAgg.

Keywords

  • subset=nothing: indices for cells to be included (rows in output).
  • coefs=nothing: indices for coefficients from each result to be included (columns in output).