Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include mean of dependent variable as a row in "etable" #43

Closed
bgchamps opened this issue Aug 25, 2020 · 3 comments
Closed

Include mean of dependent variable as a row in "etable" #43

bgchamps opened this issue Aug 25, 2020 · 3 comments

Comments

@bgchamps
Copy link

Hi Laurent,

In my regression tables, I'd like to have a row at the bottom indicating the mean of the dependent variable (along with the currently supported number of observations and r squared). Is there a way etable could support this feature?

@lrberge
Copy link
Owner

lrberge commented Aug 26, 2020

It is supported, there's the argument extraline doing that. Of course, you have to compute the means on your own.

Here's an example:

base = iris
names(base) = c("y", "x1", "x2", "x3", "species")
s = base$species

library(fixest)
est_setosa = feols(y ~ x1 + x2, base[s == "setosa",])
est_versicolor = feols(y ~ x1 + x2, base[s == "versicolor",])
est_virginica = feols(y ~ x1 + x2, base[s == "virginica",])

all_means = sapply(c("setosa", "versicolor", "virginica"),
                   function(v) mean(base[s == v, "y"]))

etable(est_setosa, est_versicolor, est_virginica, extraline = list("$\\bar{y}$"=all_means), tex = TRUE)

This leads to:
image

To place the line after the statistics you need to add a special markup in curly brackets (where:stat) at the beginning of the row name:

etable(est_setosa, est_versicolor, est_virginica, extraline = list("{where:stat}$\\bar{y}$"=all_means), tex = TRUE)

Which leads to:
image

You can add as many lines as you wish. For more customization of the table, there's this vignette.

@bgchamps
Copy link
Author

bgchamps commented Aug 28, 2020 via email

@lrberge
Copy link
Owner

lrberge commented Aug 29, 2020

Super :-), I'm closing then.

@lrberge lrberge closed this as completed Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants