did_estimate_yearly_effects {fixest} | R Documentation

## 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.

### Author(s)

Laurent Berge

### See Also

`did_plot_yearly_effects`, `errbar`.

### Examples

    # 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")

[Package fixest version 0.1.0 Index]