Learn R Programming

fixest (version 0.5.1)

did_estimate_yearly_effects: Estimates yearly treatment effects

Description

This facility helps to estimate yearly treatment effects in a difference-in-difference setup without having to manually make the estimation. It is made as general as possible such that non-fixest estimation functions can also be used.

Usage

did_estimate_yearly_effects(
  fml,
  data,
  treat_time,
  reference,
  returnData = FALSE,
  ...,
  estfun = feols
)

Arguments

fml

A formula containing the variables WITHOUT the yearly treatment effects (which will be added by this function).

data

A data.frame containing all the variables.

treat_time

Either a character vector of length two containing the name of the treatment variable and the name of the time variable (e.g. c("treat", "year")). Either a one-sided formula containing the treatment and the time (e.g. ~treat~year).

reference

The time period of reference. It should be a numeric scalar. The treatment will not be included for this time period so that it serves as reference.

returnData

Logical, default is FALSE. If TRUE, then the original database with the yearly treatment variables is returned.

...

Other arguments to be passed to estfun, the estimation function.

estfun

The estimation function. Defaults to feols.

Value

It returns an estimation object. In case of fixest estimations, it will return a fixest object.

Details

From fixest version 0.3.0 onwards, estimating yearly effects with a simple interaction of the type var::year(ref) in the formula is preferred (see details in feols). You can then plot the yearly treatment with the function coefplot. You have examples detailed in coefplot.

See Also

fixest-deprecated

Examples

Run this code
# NOT RUN {
# Sample data illustrating the DiD
data(base_did)

# Estimation of yearly effect (they are automatically added)
est = did_estimate_yearly_effects(y ~ x1 + treat + post, base_did,
                                  treat_time = ~treat+period, reference = 5)

# Now we plot the results
did_plot_yearly_effects(est)

# Now with fixed-effects:
est_fe = did_estimate_yearly_effects(y ~ x1 | id + period, base_did,
                                     treat_time = ~treat+period, reference = 5)
did_plot_yearly_effects(est_fe)

# you can change the type of SE to be plotted:
did_plot_yearly_effects(est_fe, se = "cluster") # default
did_plot_yearly_effects(est_fe, se = "standard")


# }

Run the code above in your browser using DataLab