如何为每个列Stargazer制作一个因变量标签

时间:2017-12-09 12:17:16

标签: r stargazer

我想格式化我的stargazer表,如下所示。 这是我的代码

stargazer(reg_1a, reg_2a, reg_3a, reg_4a, reg_5a, reg_6a, type="text",
          dep.var.labels = c("Ed76", "Ed76", "Wages", "Wages", "Wages", "Wages"),
          model.names = FALSE,
          title = "Table 3", 
          keep = c("nearc4", "ed76"),
          omit.stat = c("rsq", "adj.rsq", "ser", "f"),
          single.row = FALSE,
          column.separate = c(1,1,1,1,1,1),
          multicolumn = TRUE,
          column.labels = c("OLS","OLS","OLS", "OLS", "iv", "iv"))

这些是我得到的结果

Table 3
=================================================================
                             Dependent variable:                 
             ----------------------------------------------------
                   Educ                       Educ               
               OLS      OLS      OLS     OLS       iv       iv   
               (1)      (2)      (3)     (4)      (5)      (6)   
-----------------------------------------------------------------
nearc4       0.290*** 0.273*** 0.043** 0.048***                  
             (0.081)  (0.077)  (0.018) (0.018)                   

ed76                                            0.027*** 0.035***
                                                (0.004)  (0.004) 

-----------------------------------------------------------------
Observations  3,613    3,613    3,010   3,010    3,010    3,010  
=================================================================
Note:                                 *p<0.1; **p<0.05; ***p<0.01

但这就是我想要的

Table 3
=================================================================

             ----------------------------------------------------
               ed76     ed76     wages   wages     wages   wages              
               OLS      OLS      OLS     OLS       iv       iv   
               (1)      (2)      (3)     (4)      (5)      (6)   
-----------------------------------------------------------------
nearc4       0.290*** 0.273*** 0.043** 0.048***                  
             (0.081)  (0.077)  (0.018) (0.018)                   

ed76                                            0.027*** 0.035***
                                                (0.004)  (0.004) 

-----------------------------------------------------------------
Observations  3,613    3,613    3,010   3,010    3,010    3,010  
=================================================================
Note:                                 *p<0.1; **p<0.05; ***p<0.01

我不知道如何分配dep。每列的可变行。

1 个答案:

答案 0 :(得分:1)

dep.var.labels参数只查找两个值,因为您只有两个不同的因变量。例如,以下代码使用mtcars数据集。此代码无法正常运行:

library(stargazer)
data(mtcars)
lm1 <- lm(data=mtcars, mpg ~ cyl)
lm2 <- lm(data=mtcars, mpg ~ disp)
lm3 <- lm(data=mtcars, hp ~ cyl)
lm4 <- lm(data=mtcars, hp ~ disp)
stargazer(lm1, lm2, lm3, lm4, 
          type = "text",
          dep.var.labels = c("mpg", "mpg", "hp", "hp"),
          column.labels=c("1", "2", "3", "4"),
          column.separate = c(1,1,1,1))

此代码生成正确的标签:

stargazer(lm1, lm2, lm3, lm4, 
          type = "text",
          dep.var.labels = c("mpg", "hp"),
          column.labels=c("1", "2", "3", "4"),
          column.separate = c(1,1,1,1))