2

I am running regressions using various subsets of a data set and a number of dependent variables.

An example using attitude data:

library(stargazer)

#REGRESSIONS USING DATASET 1
linear1.1 <- lm(rating ~ complaints, data = attitude) #dependent 1
linear1.2 <- lm(privileges ~ complaints, data = attitude) #dependent 2

#REGRESSIONS USING DATASET 2
linear2.1 <- lm(rating ~ complaints, data = attitude[1:15,]) #dependent 1
linear2.2 <- lm(privileges ~ complaints, data = attitude[1:15,]) #dependent 2

As you can see, both depdendent variables rating and privileges are used in regressions for both subsets of the data. Using a standard stargazer approach produces the following table:

stargazer::stargazer(linear1.1,linear1.2,linear2.1,linear2.2,
                     omit.stat = "all",
                     keep = "complaints")

Table 1

Each column represents one of the regression models. However, I'd like to have each column represent one dependent variable. Each subset of the data should represent one row:

Table 2

I have produced this table by hand. Does anyone know whether it's possible to achieve this using stargazer? I have a lot of regression subsets and dependent variables, so a highly automatic solution is appreciated. Thanks!

yrx1702
  • 1,619
  • 15
  • 27
  • Wouldn't that be confusing? By first glance, it looks like there are only two models where "complaints Data1" and "complaints Data2" are independent variables in the same model. – acylam Feb 04 '19 at 15:51
  • Correct, it's confusing in this example, however, in my application it makes quite a lot of sense and increases readability. Plus I'm planing to further modify the table afterwards to avoid ambiguities. However, I need this as a starting point. – yrx1702 Feb 04 '19 at 15:55

1 Answers1

1

I just wonder if this little modification from this (Exporting output of custom multiple regressions from R to Latex) will suit you

library(stargazer)
library(broom)

## generate dummy data
set.seed(123)
x <- runif(1000)
z <- x^0.5
y <-  x + z + rnorm(1000, sd=.05)
model1 <- lm(y ~ x)
model2 <- lm(y ~ z)

## transform model summaries into dataframes
tidy(model1) -> model1_tidy
tidy(model2) -> model2_tidy

output <- rbind(model1_tidy,model2_tidy)
stargazer(output, type='text', summary=FALSE)
LocoGris
  • 4,432
  • 3
  • 15
  • 30