did_means | R Documentation |
This function shows the means and standard-deviations of several variables conditional on whether they are from the treated or the control group. The groups can further be split according to a pre/post variable. Results can be seamlessly be exported to Latex.
did_means(
fml,
base,
treat_var,
post_var,
tex = FALSE,
treat_dict,
dict = getFixest_dict(),
file,
replace = FALSE,
title,
label,
raw = FALSE,
indiv,
treat_first,
prepostnames = c("Before", "After"),
diff.inv = FALSE
)
fml |
Either a formula of the type |
base |
A data base containing all the variables in the formula |
treat_var |
Only if argument |
post_var |
Only if argument |
tex |
Should the result be displayed in Latex? Default is |
treat_dict |
A character vector of length two. What are the names of the treated
and the control? This should be a dictionary: e.g. |
dict |
A named character vector. A dictionary between the variables names and an alias.
For instance |
file |
A file path. If given, the table is written in Latex into this file. |
replace |
Default is |
title |
Character string giving the Latex title of the table. (Only if exported.) |
label |
Character string giving the Latex label of the table. (Only if exported.) |
raw |
Logical, default is |
indiv |
Either the variable name of individual identifiers, a one sided formula, or a vector. If the data is that of a panel, this can be used to track the number of individuals per group. |
treat_first |
Which value of the 'treatment' vector should appear on the left? By default the max value appears first (e.g. if the treatment variable is a 0/1 vector, 1 appears first). |
prepostnames |
Only if there is a 'post' variable. The names of the pre and post
periods to be displayed in Latex. Default is |
diff.inv |
Logical, default to |
By default, when the user tries to apply this function to nun-numeric variables, an error is raised. The exception is when the all variables are selected with the dot (like in . ~ treat
. In this case, non-numeric variables are automatically omitted (with a message).
NAs are removed automatically: if the data contains NAs an information message will be prompted. First all observations containing NAs relating to the treatment or post variables are removed. Then if there are still NAs for the variables, they are excluded separately for each variable, and a new message detailing the NA breakup is prompted.
It returns a data.frame or a Latex table with the conditional means and statistical differences between the groups.
# Playing around with the DiD data
data(base_did)
# means of treat/control
did_means(y+x1+period~treat, base_did)
# same but inverting the difference
did_means(y+x1+period~treat, base_did, diff.inv = TRUE)
# now treat/control, before/after
did_means(y+x1+period~treat|post, base_did)
# same but with a new line giving the number of unique "indiv" for each case
did_means(y+x1+period~treat|post, base_did, indiv = "id")
# same but with the treat case "0" coming first
did_means(y+x1+period~treat|post, base_did, indiv = ~id, treat_first = 0)
# Selecting all the variables with "."
did_means(.~treat|post, base_did, indiv = "id")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.