`DiffinDiffsBase.TrendOrUnspecifiedPR`

— Type`TrendOrUnspecifiedPR{C,S}`

Union type of `TrendParallel{C,S}`

and `UnspecifiedParallel{C,S}`

.

`DiffinDiffsBase.AbstractDIDResult`

— Type`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 method | Default definition | Brief description |
---|---|---|

`coef(r)` | `r.coef` | Vector of point estimates for all coefficients including covariates |

`vcov(r)` | `r.vcov` | Variance-covariance matrix for estimates in `coef` |

`vce(r)` | `r.vce` | Covariance estimator |

`confint(r)` | Based on t or normal distribution | Confidence interval for estimates in `coef` |

`treatment(r)` | `r.tr` | Treatment specification |

`nobs(r)` | `r.nobs` | Number of observations (table rows) involved in estimation |

`outcomename(r)` | `r.yname` | Name of the outcome variable |

`coefnames(r)` | `r.coefnames` | Names (`Vector{String}` ) of all coefficients including covariates |

`treatcells(r)` | `r.treatcells` | `Tables.jl` -compatible tabular description of treatment coefficients in the order of `coefnames` (without covariates) |

`weights(r)` | `r.weights` | Name 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 `r` | Result object from which `r` is generated |

`dof_residual(r)` | `r.dof_residual` or `nothing` | Residual degrees of freedom |

`responsename(r)` | `outcomename(r)` | Name of the outcome variable |

`coefinds(r)` | `r.coefinds` or `nothing` | Lookup 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.AbstractParallel`

— Type`AbstractParallel{C<:ParallelCondition, S<:ParallelStrength}`

Supertype for all parallel types.

`DiffinDiffsBase.AbstractTreatment`

— Type`AbstractTreatment`

Supertype for all treatment types.

`DiffinDiffsBase.AggregatedDIDResult`

— Type`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.Approximate`

— Type`Approximate <: ParallelStrength`

Supertype for all types assuming some notion of parallel holds approximately.

`DiffinDiffsBase.CheckData`

— Type`CheckData <: StatsStep`

Call `DiffinDiffsBase.checkdata!`

for some preliminary checks of the input data.

`DiffinDiffsBase.CheckVars`

— Type`CheckVars <: StatsStep`

Call `DiffinDiffsBase.checkvars!`

to exclude invalid rows for relevant variables.

`DiffinDiffsBase.CovariateConditional`

— Type`CovariateConditional <: ParallelCondition`

Supertype for all types assuming some notion of parallel holds after conditioning on covariates.

`DiffinDiffsBase.DIDResult`

— Type`DIDResult{TR} <: AbstractDIDResult{TR}`

Supertype for all types that collect estimation results directly obtained from `DiffinDiffsEstimator`

with treatment of type `TR`

.

`DiffinDiffsBase.DefaultDID`

— Type`DefaultDID <: DiffinDiffsEstimator`

Default difference-in-differences estimator selected based on the context.

`DiffinDiffsBase.DiffinDiffsEstimator`

— Type`DiffinDiffsEstimator{A,T} <: AbstractStatsProcedure{A,T}`

Specify the estimation procedure for difference-in-differences.

`DiffinDiffsBase.DynamicTreatment`

— Type`DynamicTreatment{S<:TreatmentSharpness} <: AbstractTreatment`

Specify an absorbing binary treatment with effects allowed to evolve over time. See also `dynamic`

.

**Fields**

`time::Symbol`

: column name of data representing calendar time.`exc::Tuple{Vararg{Int}}`

: excluded relative time.`s::S`

: an instance of`TreatmentSharpness`

.

`DiffinDiffsBase.Exact`

— Type`Exact <: ParallelStrength`

Assume some notion of parallel holds exactly.

`DiffinDiffsBase.ExportFormat`

— Type`ExportFormat`

Supertype for all types representing the format for exporting an `AbstractDIDResult`

.

`DiffinDiffsBase.GroupContrasts`

— Type`GroupContrasts <: StatsStep`

Call `DiffinDiffsBase.groupcontrasts`

to obtain one of the instances of `contrasts`

that have been grouped by equality (`hash`

) for allowing later comparisons based on object-id.

This step is only useful when working with `@specset`

and `proceed`

.

`DiffinDiffsBase.GroupSample`

— Type`GroupSample <: StatsStep`

Call `DiffinDiffsBase.groupsample`

to obtain one of the instances of `esample`

that have been grouped by equality (`hash`

) for allowing later comparisons based on object-id.

This step is only useful when working with `@specset`

and `proceed`

.

`DiffinDiffsBase.GroupTreatintterms`

— Type`GroupTreatintterms <: StatsStep`

Call `DiffinDiffsBase.grouptreatintterms`

to obtain one of the instances of `treatintterms`

that have been grouped by equality (`hash`

) for allowing later comparisons based on object-id.

This step is only useful when working with `@specset`

and `proceed`

.

`DiffinDiffsBase.GroupXterms`

— Type`GroupXterms <: StatsStep`

Call `DiffinDiffsBase.groupxterms`

to obtain one of the instances of `xterms`

that have been grouped by equality (`hash`

) for allowing later comparisons based on object-id.

This step is only useful when working with `@specset`

and `proceed`

.

`DiffinDiffsBase.MakeWeights`

— Type`MakeWeights <: StatsStep`

Call `DiffinDiffsBase.makeweights`

to create a generic `Weights`

vector.

`DiffinDiffsBase.NeverTreatedParallel`

— Type`NeverTreatedParallel{C,S} <: TrendParallel{C,S}`

Assume a parallel trends assumption holds between any group that received the treatment during the sample periods and a group that did not receive any treatment in any sample period. See also `nevertreated`

.

**Fields**

`e::Tuple{Vararg{ValidTimeType}}`

: group indices for units that did not receive any treatment.`c::C`

: an instance of`ParallelCondition`

.`s::S`

: an instance of`ParallelStrength`

.

`DiffinDiffsBase.NotYetTreatedParallel`

— Type`NotYetTreatedParallel{C,S} <: TrendParallel{C,S}`

Assume a parallel trends assumption holds between any group that received the treatment relatively early and any group that received the treatment relatively late (or never receved). See also `notyettreated`

.

**Fields**

`e::Tuple{Vararg{ValidTimeType}}`

: group indices for units that received the treatment relatively late.`ecut::Tuple{Vararg{ValidTimeType}}`

: user-specified period(s) when units in a group in`e`

started to receive treatment or show anticipation effects.`c::C`

: an instance of`ParallelCondition`

.`s::S`

: an instance of`ParallelStrength`

.

`ecut`

could be different from `minimum(e)`

if

- never-treated groups are included and use indices with smaller values;
- the sample has a rotating panel structure with periods overlapping with some others.

`DiffinDiffsBase.PanelStructure`

— Type`PanelStructure{R<:Signed, IP<:AbstractVector, TP<:AbstractVector}`

Panel data structure defined by unique combinations of unit ids and time periods. It contains the information required for certain operations such as `lag`

and `diff`

. See also `setpanel`

.

**Fields**

`refs::Vector{R}`

: reference values that allow obtaining time gaps by taking differences.`invrefs::Dict{R, Int}`

: inverse map from`refs`

to indices.`idpool::IP`

: unique unit ids.`timepool::TP`

: sorted unique time periods.`laginds::Dict{Int, Vector{Int}}`

: a map from lag distances to vectors of indices of lagged values.

`DiffinDiffsBase.ParallelCondition`

— Type`ParallelCondition`

Supertype for all types imposing conditions of parallel.

`DiffinDiffsBase.ParallelStrength`

— Type`ParallelStrength`

Supertype for all types specifying the strength of parallel.

`DiffinDiffsBase.RotatingTimeArray`

— Type`RotatingTimeArray{T<:RotatingTimeValue,N,C,I} <: AbstractArray{T,N}`

Array type for `RotatingTimeValue`

s that stores the field values `rotation`

and `time`

in two arrays for efficiency. The two arrays that hold the field values for all elements can be accessed as properties.

`DiffinDiffsBase.RotatingTimeArray`

— Method`RotatingTimeArray(rotation::AbstractArray, time::AbstractArray)`

Construct a `RotatingTimeValue`

from arrays of `rotation`

and `time`

.

`DiffinDiffsBase.RotatingTimeValue`

— Type`RotatingTimeValue{R, T}`

A wrapper around a time value for distinguishing potentially different rotation group it could belong to in a rotating sampling design. See also `rotatingtime`

and `settime`

.

**Fields**

`rotation::R`

: a rotation group in a rotating sampling design.`time::T`

: a time value belonged to the rotation group.

`DiffinDiffsBase.ScaledArray`

— Type`ScaledArray{T,R,N,RA,P} <: AbstractArray{T,N}`

Array type that stores data as indices of a range.

**Fields**

`refs::RA<:AbstractArray{R,N}`

: an array of indices.`pool::P<:AbstractRange`

: a range that covers all possible values stored by the array.`invpool::Dict{T,R}`

: a map from array elements to indices of`pool`

.

`DiffinDiffsBase.ScaledArray`

— Type```
ScaledArray(x::AbstractArray, start, step[, stop]; reftype=Int32, usepool=true)
ScaledArray(x::AbstractArray, step; reftype=Int32, start, stop, usepool=true)
```

Construct a `ScaledArray`

from `x`

given the `step`

size. If `start`

or `stop`

is not specified, it will be chosen based on the extrema of `x`

.

**Keywords**

`reftype::Type=Int32`

: the element type of field`refs`

.`usepool::Bool=true`

: find extrema of`x`

based on`DataAPI.refpool`

.

`DiffinDiffsBase.SharpDesign`

— Type`SharpDesign <: TreatmentSharpness`

Assume identical treatment within each treatment group.

`DiffinDiffsBase.StataPostHDF`

— Type`StataPostHDF <: ExportFormat`

Export an `AbstractDIDResult`

for Stata module `posthdf`

.

`DiffinDiffsBase.SubDIDResult`

— Type`SubDIDResult{TR,P<:AbstractDIDResult,I,TI} <: AbstractDIDResult{TR}`

A view into a DID result of type `P`

with indices for all coefficients of type `I`

and indices for treatment coefficients of type `TI`

. See also `view(r::AbstractDIDResult, inds)`

.

`DiffinDiffsBase.TableIndexedMatrix`

— Type`TableIndexedMatrix{T,M,R,C} <: AbstractMatrix{T}`

Matrix with row and column indices that can be selected based on row values in a `Tables.jl`

-compatible table respectively. This is useful when how elements are stored into the matrix are determined by the rows of the tables.

**Parameters**

`T`

: element type of the matrix.`M`

: type of the matrix.`R`

: type of the table paired with the row indices.`C`

: type of the table paired with the column indices.

**Fields**

`m::M`

: the matrix that stores the elements.`r::R`

: a table with the same number of rows with`m`

.`c::C`

: a table of which the number of rows is equal to the number of columns of`m`

.

`DiffinDiffsBase.TermSet`

— Type`TermSet <: AbstractSet{AbstractTerm}`

Wrapped `Set{AbstractTerm}`

that specifies a collection of terms. Commonly used methods for `Set`

work in the same way for `TermSet`

.

Compared with `StatsModels.TermOrTerms`

, it does not maintain order of terms but is more suitable for dynamically constructed terms.

`DiffinDiffsBase.TermSet`

— Method```
TermSet([itr])
TermSet(ts::Union{Int, Symbol, AbstractTerm}...)
```

Construct a `TermSet`

from a collection of terms. Instead of passing an iterable collection, one may pass the terms as arguments directly. In the latter case, any `Int`

or `Symbol`

will be converted to a `Term`

. See also `termset`

, which is an alias for the constructor.

`DiffinDiffsBase.TransSubDIDResult`

— Type`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.

`DiffinDiffsBase.TransformedDIDResult`

— Type`TransformedDIDResult{TR,P,M} <: AbstractDIDResult{TR}`

Estimation results obtained from a linear transformation of all coefficient estimates from `DIDResult`

. See also `TransSubDIDResult`

, `lincom`

and `rescale`

.

**Parameters**

`P`

: type of the result that is transformed.`M`

: type of the matrix representing the linear transformation.

`DiffinDiffsBase.TreatmentSharpness`

— Type`TreatmentSharpness`

Supertype for all types specifying the sharpness of treatment.

`DiffinDiffsBase.TreatmentTerm`

— Type`TreatmentTerm{T<:AbstractTreatment} <: AbstractTerm`

A term that contains specifications on treatment and parallel trends assumption. See also `treat`

.

**Fields**

`sym::Symbol`

: the column name of data representing treatment status.`tr::T`

: a treatment type that specifies the causal parameters of interest.`pr::P`

: a parallel type that specifies the parallel trends assumption.

`DiffinDiffsBase.TrendParallel`

— Type`TrendParallel{C,S} <: AbstractParallel{C,S}`

Supertype for all parallel types that assume a parallel trends assumption holds over all the relevant time periods.

`DiffinDiffsBase.Unconditional`

— Type`Unconditional <: ParallelCondition`

Assume some notion of parallel holds without conditions.

`DiffinDiffsBase.UnspecifiedParallel`

— Type`UnspecifiedParallel{C,S} <: AbstractParallel{C,S}`

A parallel trends assumption (PTA) without explicitly specified relations across treatment groups. See also `unspecifiedpr`

.

With this parallel type, operations for complying with a PTA are suppressed. This is useful, for example, when the user-provided regressors and sample restrictions need to be accepted without any PTA-specific alteration.

**Fields**

`c::C`

: an instance of`ParallelCondition`

.`s::S`

: an instance of`ParallelStrength`

.

`DiffinDiffsBase.VecColumnTable`

— Type`VecColumnTable <: AbstractColumns`

A `Tables.jl`

-compatible column table that stores data as `Vector{AbstractVector}`

and column names as `Vector{Symbol}`

. Retrieving columns by column names is achieved with a `Dict{Symbol,Int}`

that maps names to indices.

This table type is designed for retrieving and iterating dynamically generated columns for which specialization on names and order of columns are not desired. It is not intended to be directly constructed for interactive usage.

`Base.diff`

— Method`diff(panel::PanelStructure, v::AbstractArray; kwargs...)`

Return the differences of `v`

within observations for each unit in `panel`

. By default, it calculates the first differences. See also `diff!`

.

**Keywords**

`order::Integer=1`

: the order of differences to be taken.`l::Integer=1`

: the time interval between each pair of observations.`default=missing`

: default values for indices where the differences do not exist.

`Base.parent`

— Method`parent(r::AbstractDIDResult)`

Return the `AbstractDIDResult`

from which `r`

is generated.

`Base.view`

— Method`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._treatnames`

— Method`_treatnames(treatcells)`

Generate names for treatment coefficients. Assume `treatcells`

is compatible with the `Tables.jl`

interface.

`DiffinDiffsBase.agg`

— Method`agg(r::DIDResult)`

Aggregate difference-in-differences estimates and return a subtype of `AggregatedDIDResult`

. The implementation depends on the type of `r`

.

`DiffinDiffsBase.align`

— Method`align(xs::AbstractArray, sa::ScaledArrOrSub)`

Convert `xs`

into a `ScaledArray`

with a `pool`

that has the same first element and step size as the `pool`

from `sa`

.

`DiffinDiffsBase.aligntime`

— Method```
aligntime(col::AbstractArray, time::ScaledArrOrSub)
aligntime(col::AbstractArray, time::RotatingTimeArray)
aligntime(data, colname::Union{Symbol,Integer}, timename::Union{Symbol,Integer})
```

Convert a column of time values `col`

to a `ScaledArray`

with a `pool`

that has the same first element and step size as the `pool`

from the `ScaledArray`

`time`

. If `time`

is a `RotatingTimeArray`

with the `time`

field being a `ScaledArray`

, the returned array is also a `RotatingTimeArray`

with the `time`

field being the converted `ScaledArray`

. Alternative, the arrays may be specified with a `Tables.jl`

-compatible `data`

table and column indices `colname`

and `timename`

. See also `settime`

.

This is useful for representing all discretized time periods with the same scale so that the underlying reference values returned by `DataAPI.refarray`

can be directly comparable across the columns.

`DiffinDiffsBase.apply`

— Method`apply(d, by::Pair)`

Apply a function elementwise to the specified column(s) in a `Tables.jl`

-compatible table `d`

and return the result.

Depending on the argument(s) accepted by a function `f`

, it is specified with argument `by`

as either `column_index => f`

or `column_indices => f`

where `column_index`

is either a `Symbol`

or `Int`

for a column in `d`

and `column_indices`

is an iterable collection of such indices for multiple columns. `f`

is applied elementwise to each specified column to obtain an array of returned values.

`DiffinDiffsBase.apply_and!`

— Method```
apply_and!(inds::BitVector, d, by::Pair)
apply_and!(inds::BitVector, d, bys::Pair...)
```

Apply a function that returns `true`

or `false`

elementwise to the specified column(s) in a `Tables.jl`

-compatible table `d`

and then update the elements in `inds`

through bitwise `and`

with the returned array. If an array instead of a function is provided, elementwise equality (`==`

) comparison is applied between the column and the array. See also `apply_and`

.

The way a function is specified is the same as how it is done with `apply`

. If multiple `Pair`

s are provided, `inds`

are updated for each returned array through bitwise `and`

.

`DiffinDiffsBase.apply_and`

— Method```
apply_and(d, by::Pair)
apply_and(d, bys::Pair...)
```

Apply a function that returns `true`

or `false`

elementwise to the specified column(s) in a `Tables.jl`

-compatible table `d`

and return the result. If an array instead of a function is provided, elementwise equality (`==`

) comparison is applied between the column and the array. See also `apply_and!`

.

The way a function is specified is the same as how it is done with `apply`

. If multiple `Pair`

s are provided, the returned array is obtained by combining arrays returned by each function through bitwise `and`

.

`DiffinDiffsBase.cellrows`

— Method`cellrows(cols::VecColumnTable, refrows::IdDict)`

A utility function for processing the object `refrows`

returned by `findcell`

. Unique row values from `cols`

corresponding to the keys in `refrows`

are sorted lexicographically and stored as rows in a new `VecColumnTable`

. Groups of row indices from the values of `refrows`

are permuted to match the order of row values and collected in a `Vector`

.

**Returns**

`cells::VecColumnTable`

: unique row values from columns in`cols`

.`rows::Vector{Vector{Int}}`

: row indices for each combination.

`DiffinDiffsBase.checkdata!`

— Method`checkdata!(args...)`

Check `data`

is `Tables.AbstractColumns`

-compatible and find valid rows for options `subset`

and `weightname`

. See also `CheckData`

.

`DiffinDiffsBase.checktreatindex`

— Method`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.checkvars!`

— Method`checkvars!(args...)`

Exclude rows with missing data or violate the overlap condition and find rows with data from treated units. See also `CheckVars`

.

`DiffinDiffsBase.coefinds`

— Method`coefinds(r::AbstractDIDResult)`

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

`DiffinDiffsBase.didspec`

— Method`didspec(args...; kwargs...)`

Construct a `StatsSpec`

for difference-in-differences with the specified arguments.

`DiffinDiffsBase.diff!`

— Method`diff!(dest::AbstractArray, panel::PanelStructure, v::AbstractArray; kwargs...)`

Take the differences of `v`

within observations for each unit in `panel`

and store the result in `dest`

. By default, it calculates the first differences. See also `diff`

.

**Keywords**

`order::Integer=1`

: the order of differences to be taken.`l::Integer=1`

: the time interval between each pair of observations.`default=missing`

: default values for indices where the differences do not exist.

`DiffinDiffsBase.dynamic`

— Function`dynamic(time::Symbol, exc, s::TreatmentSharpness=sharp())`

Construct a `DynamicTreatment`

with fields set by the arguments. By default, `s`

is set as `SharpDesign`

. When working with `@formula`

, a wrapper method of `dynamic`

calls this method.

**Examples**

```
julia> dynamic(:month, -1)
Sharp dynamic treatment:
column name of time variable: month
excluded relative time: -1
julia> typeof(dynamic(:month, -1))
DynamicTreatment{SharpDesign}
julia> dynamic(:month, -3:-1)
Sharp dynamic treatment:
column name of time variable: month
excluded relative time: -3, -2, -1
julia> dynamic(:month, [-2,-1], sharp())
Sharp dynamic treatment:
column name of time variable: month
excluded relative time: -2, -1
```

`DiffinDiffsBase.exact`

— Method`exact()`

Alias for `Exact()`

.

`DiffinDiffsBase.exampledata`

— Method`exampledata(name::Union{Symbol,String})`

Return a `CSV.File`

containing the example dataset with the specified `name`

.

`DiffinDiffsBase.exampledata`

— Method`exampledata()`

Return the names of available example datasets.

`DiffinDiffsBase.findcell`

— Method```
findcell(cols::VecColumnTable)
findcell(names, data, esample=Colon())
```

Group the row indices of a collection of data columns so that the combination of row values from these columns are the same within each group.

Instead of directly providing the relevant portions of columns as `VecColumnTable`

``, one may specify the`

names`of columns from`

data`of any`

Tables.jl`-compatible table type over selected rows indicated by`

esample`. Note that unless`

esample`covers all rows of`

data`, the row indices are those for the subsample selected based on`

esample`rather than those for the full`

data`.

**Returns**

`IdDict{Tuple, Vector{Int}}`

: a map from unique row values to row indices.

`DiffinDiffsBase.findlag!`

— Function`findlag!(panel::PanelStructure, l::Integer=1)`

Construct a vector of indices of the `l`

th lagged values for all id-time combinations of `panel`

and save the result in `panel.laginds`

. If a lagged value does not exist, its index is filled with 0. See also `ilag!`

.

`DiffinDiffsBase.findlead!`

— Function`findlead!(panel::PanelStructure, l::Integer=1)`

Construct a vector of indices of the `l`

th lead values for all id-time combinations of `panel`

and save the result in `panel.laginds`

. If a lead value does not exist, its index is filled with 0. See also `ilead!`

.

`DiffinDiffsBase.getexportformat`

— Method`getexportformat()`

Return the default `ExportFormat`

for `post!`

.

`DiffinDiffsBase.groupcontrasts`

— Method`groupcontrasts(contrasts)`

Return the argument without change for allowing later comparisons based on object-id. See also `GroupContrasts`

.

`DiffinDiffsBase.groupsample`

— Method`groupsample(esample)`

Return the argument without change for allowing later comparisons based on object-id. See also `GroupSample`

.

`DiffinDiffsBase.grouptreatintterms`

— Method`grouptreatintterms(treatintterms)`

Return the argument without change for allowing later comparisons based on object-id. See also `GroupTreatintterms`

.

`DiffinDiffsBase.groupxterms`

— Method`groupxterms(xterms)`

Return the argument without change for allowing later comparisons based on object-id. See also `GroupXterms`

.

`DiffinDiffsBase.ilag!`

— Function`DiffinDiffsBase.ilead!`

— Function`DiffinDiffsBase.istreated`

— Function`istreated(pr::TrendParallel, x)`

Test whether `x`

represents the treatment time for a group of units that are not treated. See also `istreated!`

.

`DiffinDiffsBase.istreated!`

— Function`istreated!(out::AbstractVector{Bool}, pr::TrendParallel, x::AbstractArray)`

For each element in `x`

, test whether it represents the treatment time for a group of units that are not treated and save the result in `out`

. See also `istreated`

.

`DiffinDiffsBase.lincom`

— Function`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.makeweights`

— Method`makeweights(args...)`

Construct a generic `Weights`

vector. See also `MakeWeights`

.

`DiffinDiffsBase.ncovariate`

— Method`ncovariate(r::AbstractDIDResult)`

Return the number of covariate coefficients.

`DiffinDiffsBase.nevertreated`

— Method```
nevertreated(e, c::ParallelCondition, s::ParallelStrength)
nevertreated(e; c=Unconditional(), s=Exact())
```

Construct a `NeverTreatedParallel`

with fields set by the arguments. By default, `c`

is set as `Unconditional()`

and `s`

is set as `Exact()`

. When working with `@formula`

, a wrapper method of `nevertreated`

calls this method.

**Examples**

```
julia> nevertreated(-1)
Parallel trends with any never-treated group:
Never-treated groups: -1
julia> typeof(nevertreated(-1))
NeverTreatedParallel{Unconditional,Exact}
julia> nevertreated([-1, 0])
Parallel trends with any never-treated group:
Never-treated groups: -1, 0
julia> nevertreated([-1, 0]) == nevertreated(-1:0) == nevertreated(Set([-1, 0]))
true
```

`DiffinDiffsBase.notyettreated`

— Method```
notyettreated(e, ecut, c::ParallelCondition, s::ParallelStrength)
notyettreated(e, ecut=e; c=Unconditional(), s=Exact())
```

Construct a `NotYetTreatedParallel`

with fields set by the arguments. By default, `c`

is set as `Unconditional()`

and `s`

is set as `Exact()`

. When working with `@formula`

, a wrapper method of `notyettreated`

calls this method.

**Examples**

```
julia> notyettreated(5)
Parallel trends with any not-yet-treated group:
Not-yet-treated groups: 5
Treated since: 5
julia> typeof(notyettreated(5))
NotYetTreatedParallel{Unconditional,Exact}
julia> notyettreated([-1, 5, 6], 5)
Parallel trends with any not-yet-treated group:
Not-yet-treated groups: -1, 5, 6
Treated since: 5
julia> notyettreated([4, 5, 6], [4, 5, 6])
Parallel trends with any not-yet-treated group:
Not-yet-treated groups: 4, 5, 6
Treated since: 4, 5, 6
```

`DiffinDiffsBase.ntreatcoef`

— Method`ntreatcoef(r::AbstractDIDResult)`

Return the number of treatment coefficients.

`DiffinDiffsBase.outcomename`

— Method`outcomename(r::AbstractDIDResult)`

Return the name of outcome variable generated by `StatsModels.coefnames`

. See also `responsename`

.

`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.parse_intercept!`

— Method`parse_intercept(ts::TermSet)`

Remove any `ConstantTerm`

or `InterceptTerm`

and return Boolean values indicating whether terms explictly requiring including/excluding the intercept exist.

This function is useful for obtaining a unique way of specifying the intercept before going through the `schema`

–`apply_schema`

pipeline defined in `StatsModels`

.

`DiffinDiffsBase.post!`

— Method`post!(f, r; kwargs...)`

Export result `r`

in a default `ExportFormat`

.

The default format can be retrieved via `getexportformat`

and modified via `setexportformat!`

. The keyword arguments that can be accepted depend on the format and the type of `r`

.

`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`Pair`

s.`at::Union{AbstractVector{<:Real}, Bool, Nothing}=nothing`

: post the`at`

vector in Stata.

`DiffinDiffsBase.rescale`

— Function```
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.rotatingtime`

— Method`rotatingtime(rotation, time)`

Construct `RotatingTimeValue`

s from `rotation`

and `time`

. This method simply broadcasts the default constructor over the arguments.

`DiffinDiffsBase.scale`

— Method`scale(sa::ScaledArrOrSub)`

Return the step size of the `pool`

of `sa`

.

`DiffinDiffsBase.setexportformat!`

— Method`setexportformat!(format::ExportFormat)`

Set the default `ExportFormat`

for `post!`

.

`DiffinDiffsBase.setpanel`

— Method```
setpanel(data, idname, timename; step, reftype, rotation)
setpanel(id::AbstractArray, time::AbstractArray; step, reftype, rotation)
```

Declare a `PanelStructure`

which is required for certain operations such as `lag`

and `diff`

. Unit IDs and time values can be provided either as a table containing the relevant columns or as arrays. `timestep`

must be specified unless the `time`

array is a `ScaledArray`

that is returned by `settime`

.

**Arguments**

`data`

: a`Tables.jl`

-compatible data table.`idname::Union{Symbol,Integer}`

: the name of the column in`data`

that contains unit IDs.`timename::Union{Symbol,Integer}`

: the name of the column in`data`

that contains time values.`id::AbstractArray`

: the array containing unit IDs (only needed for the alternative method).`time::AbstractArray`

: the array containing time values (only needed for the alternative method).

**Keywords**

`step=nothing`

: the length of each time interval; try`step=one(eltype(time))`

if not specified.`reftype::Type{<:Signed}=Int32`

: the element type of the reference values for`PanelStructure`

.`rotation=nothing`

: rotation groups in a rotating sampling design; use`RotatingTimeValue`

s as reference values.

If the underlying data used to create the `PanelStructure`

are modified. The changes will not be reflected in the existing instances of `PanelStructure`

. A new instance needs to be created with `setpanel`

.

`DiffinDiffsBase.settime`

— Function`settime(time::AbstractArray, step; start, stop, reftype, rotation)`

Convert a column of time values to a `ScaledArray`

for representing discretized time periods of uniform length. If `rotation`

is specified (time values belong to multiple rotation groups), a `RotatingTimeArray`

is returned with the `time`

field being a `ScaledArray`

. The returned array ensures well-defined time intervals for operations involving relative time (such as `lag`

and `diff`

). See also `aligntime`

.

**Arguments**

`time::AbstractArray`

: the array containing time values.`step=nothing`

: the length of each time interval; try`step=one(eltype(time))`

if not specified.

**Keywords**

`start=nothing`

: the first element of the`pool`

of the returned`ScaledArray`

.`stop=nothing`

: the last element of the`pool`

of the returned`ScaledArray`

.`reftype::Type{<:Signed}=Int32`

: the element type of the reference values for the`ScaledArray`

.`rotation=nothing`

: rotation groups in a rotating sampling design.

`DiffinDiffsBase.sharp`

— Method`sharp()`

Alias for `SharpDesign()`

.

`DiffinDiffsBase.subcolumns`

— Function`subcolumns(data, names, rows=Colon(); nomissing=true)`

Construct a `VecColumnTable`

from `data`

using columns specified with `names`

over selected `rows`

.

By default, columns are converted to drop support for missing values. When possible, resulting columns share memory with original columns.

`DiffinDiffsBase.termset`

— Method```
termset([itr])
termset(ts::Union{Int, Symbol, AbstractTerm}...)
```

Construct a `TermSet`

from a collection of terms. Instead of passing an iterable collection, one may pass the terms as arguments directly. In the latter case, any `Int`

or `Symbol`

will be converted to a `Term`

.

`DiffinDiffsBase.treat`

— Method`treat(s::Symbol, t::AbstractTreatment, p::AbstractParallel)`

Construct a `TreatmentTerm`

with fields set by the arguments.

`DiffinDiffsBase.treatcells`

— Method`treatcells(r::AbstractDIDResult)`

Return a `Tables.jl`

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

`DiffinDiffsBase.treatcoef`

— Method`treatcoef(r::AbstractDIDResult)`

Return a view of treatment coefficients.

`DiffinDiffsBase.treatindex`

— Method`treatindex(ntcoef::Int, I)`

Extract indices referencing the treatment coefficients from `I`

based on the total number of treatment coefficients `ntcoef`

.

`DiffinDiffsBase.treatment`

— Method`treatment(r::AbstractDIDResult)`

Return the treatment specification.

`DiffinDiffsBase.treatnames`

— Method`treatnames(r::AbstractDIDResult)`

Return a vector of names for treatment coefficients.

`DiffinDiffsBase.treatvcov`

— Method`treatvcov(r::AbstractDIDResult)`

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

`DiffinDiffsBase.unconditional`

— Method`unconditional()`

Alias for `Unconditional()`

.

`DiffinDiffsBase.unspecifiedpr`

— Function`unspecifiedpr(c::ParallelCondition=Unconditional(), s::ParallelStrength=Exact())`

Construct an `UnspecifiedParallel`

with fields set by the arguments. This is an alias of the inner constructor of `UnspecifiedParallel`

.

`DiffinDiffsBase.valid_didargs`

— Method`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.vce`

— Method`vce(r::AbstractDIDResult)`

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

`ShiftedArrays.lag`

— Function`ShiftedArrays.lead`

— Function`StatsAPI.coef`

— Method```
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.coef`

— Method`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 `Pair`

s are provided, the results are combined into one `BitVector`

through bit-wise `and`

.

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

`StatsAPI.coef`

— Method`coef(r::AbstractDIDResult)`

Return the vector of point estimates for all coefficients.

`StatsAPI.coefnames`

— Method`coefnames(r::AbstractDIDResult)`

Return a vector of coefficient names.

`StatsAPI.confint`

— Method`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_residual`

— Method`dof_residual(r::AbstractDIDResult)`

Return the residual degrees of freedom.

`StatsAPI.nobs`

— Method`nobs(r::AbstractDIDResult)`

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

`StatsAPI.responsename`

— Method`responsename(r::AbstractDIDResult)`

Return the name of outcome variable generated by `StatsModels.coefnames`

. This method is an alias of `outcomename`

.

`StatsAPI.vcov`

— Function```
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.vcov`

— Method`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 `Pair`

s are provided, the results are combined into one `BitVector`

through bit-wise `and`

.

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

`StatsAPI.vcov`

— Method`vcov(r::AbstractDIDResult)`

Return the variance-covariance matrix for all coefficient estimates.

`StatsAPI.weights`

— Method`weights(r::AbstractDIDResult)`

Return the column name of the weight variable. Return `nothing`

if `weights`

is not specified for estimation.

`DiffinDiffsBase.@did`

— Macro`@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`StatsSpec`

s.`pause::Int=0`

: break the iteration over`StatsStep`

s after finishing the specified number of steps (for debugging).

`DiffinDiffsBase.@fieldequal`

— Macro`@fieldequal Supertype`

Define a method of `==`

for all subtypes of `Supertype`

such that `==`

returns true if two instances have the same field values.