Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding two rows of column names in Stargazer regression table

Tags:

r

stargazer

I'm actually surprised to find that no one has asked this question. Here it goes.

I have a 3 models, first 2 computed for black people and the last one for whites. I produce a regression output with stargazer and over the first two models I write the column label "Black" using column.labels. I label the remaining column "White". So, 3 models, two with the same column label and the last with another one.

However, I want to also add another column label above the first model specifying "Males"(I also mean above the "Black" label) and add a similar label for the 2 last models specifying "Female".

I can't see a way to add the second columns labels above the Racial category.

library(stargazer)
data <-     data.frame(dv1=rnorm(100),dv2=rnorm(100),dv3=rnorm(100),race=sample(c(1,0)    ,100, replace = T),
               iv=sample(c(1,0),100,replace = T))

m1 <- lm(dv1 ~ + iv, data = data, subset = race == 1)
m2 <- lm(dv2 ~ + sqrt(iv), data = data, subset = race == 0)
m3 <- lm(dv3 ~ + iv, data = data, subset = race == 0)

models <- stargazer(m1,m2,m3, type = "text", column.labels = c("Blacks","Whites"), column.separate = c(2,1),
                    dep.var.labels.include = FALSE)
like image 308
cimentadaj Avatar asked Jan 13 '16 18:01

cimentadaj


1 Answers

I suspect the best you can do is not quite what you want, assuming I have understood the column attribution correctly....

     models <- stargazer(m1,m2,m3, type = "text", 
                         column.labels = c("Male Blacks","Female Blacks","Female Whites"),
                         column.separate = c(1,1,1), dep.var.labels.include = FALSE)

Using dep.var.caption you could try...

dep.var.caption="\b\b\b  Males ................... Females"

but IMHO this illustrates how confused a multi-row heading might look. Since the caption seems to be centre justified, the control characters and the dots are a kludge (spaces seem to be ignored).

like image 130
Big Old Dave Avatar answered Sep 25 '22 01:09

Big Old Dave