DiffinDiffsBase.TrendOrUnspecifiedPR
— TypeTrendOrUnspecifiedPR{C,S}
Union type of TrendParallel{C,S}
and UnspecifiedParallel{C,S}
.
DiffinDiffsBase.AbstractDIDResult
— TypeAbstractDIDResult{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
— TypeAbstractParallel{C<:ParallelCondition, S<:ParallelStrength}
Supertype for all parallel types.
DiffinDiffsBase.AbstractTreatment
— TypeAbstractTreatment
Supertype for all treatment types.
DiffinDiffsBase.AggregatedDIDResult
— TypeAggregatedDIDResult{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
— TypeApproximate <: ParallelStrength
Supertype for all types assuming some notion of parallel holds approximately.
DiffinDiffsBase.CheckData
— TypeCheckData <: StatsStep
Call DiffinDiffsBase.checkdata!
for some preliminary checks of the input data.
DiffinDiffsBase.CheckVars
— TypeCheckVars <: StatsStep
Call DiffinDiffsBase.checkvars!
to exclude invalid rows for relevant variables.
DiffinDiffsBase.CovariateConditional
— TypeCovariateConditional <: ParallelCondition
Supertype for all types assuming some notion of parallel holds after conditioning on covariates.
DiffinDiffsBase.DIDResult
— TypeDIDResult{TR} <: AbstractDIDResult{TR}
Supertype for all types that collect estimation results directly obtained from DiffinDiffsEstimator
with treatment of type TR
.
DiffinDiffsBase.DefaultDID
— TypeDefaultDID <: DiffinDiffsEstimator
Default difference-in-differences estimator selected based on the context.
DiffinDiffsBase.DiffinDiffsEstimator
— TypeDiffinDiffsEstimator{A,T} <: AbstractStatsProcedure{A,T}
Specify the estimation procedure for difference-in-differences.
DiffinDiffsBase.DynamicTreatment
— TypeDynamicTreatment{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 ofTreatmentSharpness
.
DiffinDiffsBase.Exact
— TypeExact <: ParallelStrength
Assume some notion of parallel holds exactly.
DiffinDiffsBase.ExportFormat
— TypeExportFormat
Supertype for all types representing the format for exporting an AbstractDIDResult
.
DiffinDiffsBase.GroupContrasts
— TypeGroupContrasts <: 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
— TypeGroupSample <: 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
— TypeGroupTreatintterms <: 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
— TypeGroupXterms <: 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
— TypeMakeWeights <: StatsStep
Call DiffinDiffsBase.makeweights
to create a generic Weights
vector.
DiffinDiffsBase.NeverTreatedParallel
— TypeNeverTreatedParallel{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 ofParallelCondition
.s::S
: an instance ofParallelStrength
.
DiffinDiffsBase.NotYetTreatedParallel
— TypeNotYetTreatedParallel{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 ine
started to receive treatment or show anticipation effects.c::C
: an instance ofParallelCondition
.s::S
: an instance ofParallelStrength
.
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
— TypePanelStructure{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 fromrefs
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
— TypeParallelCondition
Supertype for all types imposing conditions of parallel.
DiffinDiffsBase.ParallelStrength
— TypeParallelStrength
Supertype for all types specifying the strength of parallel.
DiffinDiffsBase.RotatingTimeArray
— TypeRotatingTimeArray{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
— MethodRotatingTimeArray(rotation::AbstractArray, time::AbstractArray)
Construct a RotatingTimeValue
from arrays of rotation
and time
.
DiffinDiffsBase.RotatingTimeValue
— TypeRotatingTimeValue{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
— TypeScaledArray{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 ofpool
.
DiffinDiffsBase.ScaledArray
— TypeScaledArray(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 fieldrefs
.usepool::Bool=true
: find extrema ofx
based onDataAPI.refpool
.
DiffinDiffsBase.SharpDesign
— TypeSharpDesign <: TreatmentSharpness
Assume identical treatment within each treatment group.
DiffinDiffsBase.StataPostHDF
— TypeStataPostHDF <: ExportFormat
Export an AbstractDIDResult
for Stata module posthdf
.
DiffinDiffsBase.SubDIDResult
— TypeSubDIDResult{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
— TypeTableIndexedMatrix{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 withm
.c::C
: a table of which the number of rows is equal to the number of columns ofm
.
DiffinDiffsBase.TermSet
— TypeTermSet <: 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
— MethodTermSet([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
— TypeTransSubDIDResult{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
— TypeTransformedDIDResult{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
— TypeTreatmentSharpness
Supertype for all types specifying the sharpness of treatment.
DiffinDiffsBase.TreatmentTerm
— TypeTreatmentTerm{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
— TypeTrendParallel{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
— TypeUnconditional <: ParallelCondition
Assume some notion of parallel holds without conditions.
DiffinDiffsBase.UnspecifiedParallel
— TypeUnspecifiedParallel{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 ofParallelCondition
.s::S
: an instance ofParallelStrength
.
DiffinDiffsBase.VecColumnTable
— TypeVecColumnTable <: 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
— Methoddiff(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
— Methodparent(r::AbstractDIDResult)
Return the AbstractDIDResult
from which r
is generated.
Base.view
— Methodview(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
— Methodagg(r::DIDResult)
Aggregate difference-in-differences estimates and return a subtype of AggregatedDIDResult
. The implementation depends on the type of r
.
DiffinDiffsBase.align
— Methodalign(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
— Methodaligntime(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
— Methodapply(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!
— Methodapply_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
— Methodapply_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
— Methodcellrows(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 incols
.rows::Vector{Vector{Int}}
: row indices for each combination.
DiffinDiffsBase.checkdata!
— Methodcheckdata!(args...)
Check data
is Tables.AbstractColumns
-compatible and find valid rows for options subset
and weightname
. See also CheckData
.
DiffinDiffsBase.checktreatindex
— Methodchecktreatindex(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!
— Methodcheckvars!(args...)
Exclude rows with missing data or violate the overlap condition and find rows with data from treated units. See also CheckVars
.
DiffinDiffsBase.coefinds
— Methodcoefinds(r::AbstractDIDResult)
Return the map from coefficient names to integer indices for retrieving estimates by name.
DiffinDiffsBase.didspec
— Methoddidspec(args...; kwargs...)
Construct a StatsSpec
for difference-in-differences with the specified arguments.
DiffinDiffsBase.diff!
— Methoddiff!(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
— Functiondynamic(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
— Methodexact()
Alias for Exact()
.
DiffinDiffsBase.exampledata
— Methodexampledata(name::Union{Symbol,String})
Return a CSV.File
containing the example dataset with the specified name
.
DiffinDiffsBase.exampledata
— Methodexampledata()
Return the names of available example datasets.
DiffinDiffsBase.findcell
— Methodfindcell(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
namesof columns from
dataof any
Tables.jl-compatible table type over selected rows indicated by
esample. Note that unless
esamplecovers all rows of
data, the row indices are those for the subsample selected based on
esamplerather than those for the full
data`.
Returns
IdDict{Tuple, Vector{Int}}
: a map from unique row values to row indices.
DiffinDiffsBase.findlag!
— Functionfindlag!(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!
— Functionfindlead!(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
— Methodgetexportformat()
Return the default ExportFormat
for post!
.
DiffinDiffsBase.groupcontrasts
— Methodgroupcontrasts(contrasts)
Return the argument without change for allowing later comparisons based on object-id. See also GroupContrasts
.
DiffinDiffsBase.groupsample
— Methodgroupsample(esample)
Return the argument without change for allowing later comparisons based on object-id. See also GroupSample
.
DiffinDiffsBase.grouptreatintterms
— Methodgrouptreatintterms(treatintterms)
Return the argument without change for allowing later comparisons based on object-id. See also GroupTreatintterms
.
DiffinDiffsBase.groupxterms
— Methodgroupxterms(xterms)
Return the argument without change for allowing later comparisons based on object-id. See also GroupXterms
.
DiffinDiffsBase.ilag!
— FunctionDiffinDiffsBase.ilead!
— FunctionDiffinDiffsBase.istreated
— Functionistreated(pr::TrendParallel, x)
Test whether x
represents the treatment time for a group of units that are not treated. See also istreated!
.
DiffinDiffsBase.istreated!
— Functionistreated!(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
— Functionlincom(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
— Methodmakeweights(args...)
Construct a generic Weights
vector. See also MakeWeights
.
DiffinDiffsBase.ncovariate
— Methodncovariate(r::AbstractDIDResult)
Return the number of covariate coefficients.
DiffinDiffsBase.nevertreated
— Methodnevertreated(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
— Methodnotyettreated(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
— Methodntreatcoef(r::AbstractDIDResult)
Return the number of treatment coefficients.
DiffinDiffsBase.outcomename
— Methodoutcomename(r::AbstractDIDResult)
Return the name of outcome variable generated by StatsModels.coefnames
. See also responsename
.
DiffinDiffsBase.parse_didargs!
— Methodparse_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!
— Methodparse_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!
— Methodpost!(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!
— Methodpost!(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 withPair
s.at::Union{AbstractVector{<:Real}, Bool, Nothing}=nothing
: post theat
vector in Stata.
DiffinDiffsBase.rescale
— Functionrescale(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
— Methodrotatingtime(rotation, time)
Construct RotatingTimeValue
s from rotation
and time
. This method simply broadcasts the default constructor over the arguments.
DiffinDiffsBase.scale
— Methodscale(sa::ScaledArrOrSub)
Return the step size of the pool
of sa
.
DiffinDiffsBase.setexportformat!
— Methodsetexportformat!(format::ExportFormat)
Set the default ExportFormat
for post!
.
DiffinDiffsBase.setpanel
— Methodsetpanel(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
: aTables.jl
-compatible data table.idname::Union{Symbol,Integer}
: the name of the column indata
that contains unit IDs.timename::Union{Symbol,Integer}
: the name of the column indata
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; trystep=one(eltype(time))
if not specified.reftype::Type{<:Signed}=Int32
: the element type of the reference values forPanelStructure
.rotation=nothing
: rotation groups in a rotating sampling design; useRotatingTimeValue
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
— Functionsettime(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; trystep=one(eltype(time))
if not specified.
Keywords
start=nothing
: the first element of thepool
of the returnedScaledArray
.stop=nothing
: the last element of thepool
of the returnedScaledArray
.reftype::Type{<:Signed}=Int32
: the element type of the reference values for theScaledArray
.rotation=nothing
: rotation groups in a rotating sampling design.
DiffinDiffsBase.sharp
— Methodsharp()
Alias for SharpDesign()
.
DiffinDiffsBase.subcolumns
— Functionsubcolumns(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
— Methodtermset([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
— Methodtreat(s::Symbol, t::AbstractTreatment, p::AbstractParallel)
Construct a TreatmentTerm
with fields set by the arguments.
DiffinDiffsBase.treatcells
— Methodtreatcells(r::AbstractDIDResult)
Return a Tables.jl
-compatible tabular description of treatment coefficients in the order of coefnames (without covariates).
DiffinDiffsBase.treatcoef
— Methodtreatcoef(r::AbstractDIDResult)
Return a view of treatment coefficients.
DiffinDiffsBase.treatindex
— Methodtreatindex(ntcoef::Int, I)
Extract indices referencing the treatment coefficients from I
based on the total number of treatment coefficients ntcoef
.
DiffinDiffsBase.treatment
— Methodtreatment(r::AbstractDIDResult)
Return the treatment specification.
DiffinDiffsBase.treatnames
— Methodtreatnames(r::AbstractDIDResult)
Return a vector of names for treatment coefficients.
DiffinDiffsBase.treatvcov
— Methodtreatvcov(r::AbstractDIDResult)
Return a view of variance-covariance matrix for treatment coefficients.
DiffinDiffsBase.unconditional
— Methodunconditional()
Alias for Unconditional()
.
DiffinDiffsBase.unspecifiedpr
— Functionunspecifiedpr(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
— Methodvalid_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
— Methodvce(r::AbstractDIDResult)
Return the covariance estimator used to estimate variance-covariance matrix.
ShiftedArrays.lag
— FunctionShiftedArrays.lead
— FunctionStatsAPI.coef
— Methodcoef(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
— Methodcoef(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
— Methodcoef(r::AbstractDIDResult)
Return the vector of point estimates for all coefficients.
StatsAPI.coefnames
— Methodcoefnames(r::AbstractDIDResult)
Return a vector of coefficient names.
StatsAPI.confint
— Methodconfint(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
— Methoddof_residual(r::AbstractDIDResult)
Return the residual degrees of freedom.
StatsAPI.nobs
— Methodnobs(r::AbstractDIDResult)
Return the number of observations (table rows) involved in estimation.
StatsAPI.responsename
— Methodresponsename(r::AbstractDIDResult)
Return the name of outcome variable generated by StatsModels.coefnames
. This method is an alias of outcomename
.
StatsAPI.vcov
— Functionvcov(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
— Methodvcov(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
— Methodvcov(r::AbstractDIDResult)
Return the variance-covariance matrix for all coefficient estimates.
StatsAPI.weights
— Methodweights(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 ofStatsSpec
.name::AbstractString
: an optional name for theStatsSpec
.args... kwargs...
: a list of arguments to be processed byparse_didargs!
andvalid_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 constructedStatsSpec
without conducting the procedure.verbose::Bool=false
: print the name of each step when it is called.keep=nothing
: names (of typeSymbol
) of additional objects to be returned.keepall::Bool=false
: return all objects generated by procedures along with arguments from theStatsSpec
s.pause::Int=0
: break the iteration overStatsStep
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.