如何在R中使用stargazer在同一行中输出多个变量 [英] How to output several variables in the same row using stargazer in R

查看:61
本文介绍了如何在R中使用stargazer在同一行中输出多个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从同一行中的多个回归中输出交互项,并将其称为交互".到目前为止,我所拥有的是交互作用术语显示在两个称为交互作用"的不同行中(请参见下面的代码).

I would like to output the interaction terms from several regressions in the same row and call it "Interaction". So far what I have is that the interaction terms show up in two different rows called "Interaction" (see code below).

这里已经问过这个问题,但是我的分数还不够高,不能对其进行评论或评论:

This question has already been asked here, but my score isn't high enough yet to upvote it or comment on it: https://stackoverflow.com/questions/28859569/several-coefficients-in-one-line.

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"))

谢谢您的帮助.

推荐答案

我认为这不是本机支持的,因为这不是一个好主意.您正在要求混淆表中数字的含义,这对您的读者没有帮助.

I think this is not natively supported because it is not a good idea. You're asking to obfuscate the meaning of the numbers in your table, which won't help your reader.

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

That caveat now stated, you can do this by modifying the contents of the lm objects:

# 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

这篇关于如何在R中使用stargazer在同一行中输出多个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆