# Treatment Terms

`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.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.eachterm`

— Method`eachterm(t)`

Return an iterable collection of terms in `t`

.

`DiffinDiffsBase.hastreat`

— Method`hastreat(t)`

Determine whether the term `t`

contains an instance of `TreatmentTerm`

.

`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.parse_treat`

— Method`parse_treat(formula::FormulaTerm)`

Extract terms related to treatment specifications from `formula`

.

**Returns**

`TreatmentTerm`

: the unique`TreatmentTerm`

contained in the`formula`

.`TermSet`

: a set of terms that are interacted with the`TreatmentTerm`

.`TermSet`

: a set of remaining terms in`formula.rhs`

.

Error will be raised if either existence or uniqueness of the `TreatmentTerm`

is violated.

`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.treat`

— Method`treat(s::Term, t::FunctionTerm{FT}, p::FunctionTerm{FP})`

Construct a `TreatmentTerm`

with fields set by `s.sym`

, `FT.instance(t.args_parsed...)`

and `FP.instance(p.args_parsed...)`

. This method is called by `parse_treat(formula)`

when the formula is constructed by `@formula`

.