Title: | Experimental Package: Plots to diagnose parallel trends in DID regression with additional control variables. |
---|---|
Description: | Experimental Package: Plots to diagnose parallel trends in DID regression with additional control variables. |
Authors: | Sebastian Kranz |
Maintainer: | Sebastian Kranz <[email protected]> |
License: | GPL >= 2.0 |
Version: | 0.1.0 |
Built: | 2024-11-16 04:34:26 UTC |
Source: | https://github.com/skranz/ParallelTrendsPlot |
The resulting data frame can be directly passed to parallel.trends.plot or be used to generate a more customized manual plot.
parallel.trends.data( df, timevar = "t", yvar = "y", treatdummy = "treat", expdummy = "exp", treat_exp_dummy = NULL, cvars = NULL, extravars = NULL, add.no.control = TRUE, constant.type = c("means", "zero")[1] )
parallel.trends.data( df, timevar = "t", yvar = "y", treatdummy = "treat", expdummy = "exp", treat_exp_dummy = NULL, cvars = NULL, extravars = NULL, add.no.control = TRUE, constant.type = c("means", "zero")[1] )
df |
The data frame used for the DID regression |
timevar |
Name of the time variable, e.g. "year" |
yvar |
Name of the dependent variable |
treatdummy |
Name of the 0-1 dummy variable indicating whether the observation belongs to the treatment group |
expdummy |
Name of the 0-1 dummy variable indicating whether the observation is in an experimental period, i.e. a period in which the treatment group gets treatment. |
treat_exp_dummy |
Optional name of the interaction variable treatdummy * expdummy. If not given a column with name "treat_exp_dummy" is added to the data frame. |
cvars |
Names of the additional control variables used in the DID regression. |
extravars |
Names of variables that are not used in the regression but shall be included in the returned data frame. |
add.no.control |
If TRUE (default) add rows that are used for a parallel trends diagnostic plot that assumes that no control variables are added. |
A data frame that can be passed to parallel.trends.plot. Essential columns are .t, .y, .group, .exp, .mode. Note that the data frame only contains rows that have no NA for the specified columns.
Generates plots to diagnose parallel trends for difference-in-difference regressions with additional control variables
parallel.trends.plot( pt.dat, facet.mode = ".mode" %in% colnames(pt.dat), add.exp.line = c("first", "all", "none")[1], exp.line.opt = list(color = "black") )
parallel.trends.plot( pt.dat, facet.mode = ".mode" %in% colnames(pt.dat), add.exp.line = c("first", "all", "none")[1], exp.line.opt = list(color = "black") )
pt.dat |
A data frame as returned by the function parallel.trends.data |
facet.mode |
If TRUE generate a facet plot with one facet for trends of control group and experimental group with and without correction of the control variables |
add.exp.line |
How shall vertical lines be added to indicate the experimental periods? "first" means a line at the first experimental period, "all" means a line at all experimental periods. Use "none" to add no lines |
exp.line.opt |
Arguments passed to geom_vert to customize the vertical lines. |
A ggplot object