如何在 R 中使用 stargazer 在同一行中输出多个变量

How to output several variables in the same row using stargazer in R

我想在同一行中输出多个回归的交互项,并将其命名为 "Interaction"。到目前为止,我所拥有的是交互项出现在两个不同的行中,称为 "Interaction"(请参见下面的代码)。

这里已经有人问过这个问题,但我的分数还不够高,无法对其进行投票或评论:。

library("stargazer")
stargazer(attitude)
stargazer(attitude, summary=FALSE)
# 2 OLS models with Interactions
linear.1 <- lm(rating ~ complaints + privileges + complaints*privileges
           , data=attitude)
linear.2 <- lm(rating ~ complaints + learning + complaints*learning, data=attitude)
stargazer(linear.1, linear.2, title="Regression Results", type="text", 
      covariate.labels=c("Complaints", "Privileges", "Interaction", "Learning", "Interaction"))

感谢您的帮助。

我认为这不是本地支持的,因为这不是一个好主意。您要求混淆 table 中数字的含义,这对您的 reader.

没有帮助

现在说明,您可以通过修改 lm 对象的内容来做到这一点:

# copy objects just for demonstration
m1 <- linear.1
m2 <- linear.2

# see names of coefficients
names(m1$coefficients)
# [1] "(Intercept)"           "complaints"            "privileges"            "complaints:privileges"
names(m2$coefficients)
# [1] "(Intercept)"         "complaints"          "learning"            "complaints:learning"

# replace names
names(m1$coefficients)[names(m1$coefficients) == "complaints:privileges"] <- "interaction"
names(m2$coefficients)[names(m2$coefficients) == "complaints:learning"] <- "interaction"

结果:

> stargazer(m1, m2, title="Regression Results", type="text")

Regression Results
==========================================================
                                  Dependent variable:     
                              ----------------------------
                                         rating           
                                   (1)            (2)     
----------------------------------------------------------
complaints                       1.114**         0.307    
                                 (0.401)        (0.503)   

privileges                        0.434                   
                                 (0.570)                  

learning                                        -0.171    
                                                (0.570)   

interaction                       -0.007         0.006    
                                 (0.008)        (0.009)   

Constant                          -7.737        31.203    
                                 (27.409)      (31.734)   

----------------------------------------------------------
Observations                        30            30      
R2                                0.692          0.713    
Adjusted R2                       0.657          0.680    
Residual Std. Error (df = 26)     7.134          6.884    
F Statistic (df = 3; 26)        19.478***      21.559***  
==========================================================
Note:                          *p<0.1; **p<0.05; ***p<0.01

万一有人想知道,我需要这个是为了 felm 包的不同目的。为此需要以下代码:

reg ~ felm(....)
rownames(reg$coefficients)[rownames(reg$coefficients)=='oldname']<-'newname'
rownames(reg$beta)[rownames(reg$beta)=='oldname']<-'newname'

以下回复:

reg ~ felm(....)
rownames(reg$coefficients)[rownames(reg$coefficients)=='oldname']<-'newname'
rownames(reg$beta)[rownames(reg$beta)=='oldname']<-'newname'

似乎适用于大多数情况。

尽管我有时遇到过问题。当 IV 与 felm 一起使用时,这是必需的。虽然区分适合和不适合 IV 的变量很好,但与其他模型相比,这些表格会显得很麻烦!这个语法很有用。