0

The last time a similar question was asked it was partially answered.

Similar to the example from the earlier question, here is the code

library(stargazer)
stargazer(attitude)

linear.1 <- lm(rating ~ complaints + privileges + learning, data=attitude[1:10,])
linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude[11:20,])

stargazer(linear.1, linear.2, title= "Regression Results", type = 'text', flip = TRUE)

i.e. Same model on two different dataframes (in this case different subsets).

Two requirements:

  1. I want a table in which the estimate of only 'complaints' for linear.1 and linear.2 appear in one column (with se in parentheses) and stars for significance.

  2. I also want to add a column for another linear model with different specification showing the same outputs for 'complaints' for each subset.

Apologies if anything is unclear, happy to clarify.

learningR
  • 1
  • 1

1 Answers1

0

Here is my solution:

library(broom)
library(tidyverse)

library(stargazer)
stargazer(attitude)

linear.1 <- lm(rating ~ complaints + privileges + learning, data=attitude[1:10,])
linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude[11:20,])

rbind(tidy(linear.1),
tidy(linear.1))%>%filter(term=="complaints")->df

stargazer(df, title= "Regression Results", summary = FALSE) 

You can include more models using tidy(lm) within the rbind function

user438383
  • 5,716
  • 8
  • 28
  • 43