【问题标题】:Inserting Stars in Custom Stargazer table在自定义 Stargazer 表中插入星星
【发布时间】:2016-04-14 00:05:31
【问题描述】:

我的问题可以用下图来理解

这是一张不错的桌子,除了一个问题。我希望星星(即星号)成为对数差异列中的上标。我该怎么做。

为了生成表格,我使用了以下矩阵

     Log                 Log Difference        
Corn "-4.6242962032095"  "-7.92864907263132***"
HH   "-4.6298901146614"  "-8.72323131664597***"
ICE  "-4.97319261907647" "-7.93380905076848***"
AA   "-4.1611318165187"  "-7.25071259471702***"

res <-structure(c("-4.6242962032095", "-4.6298901146614", "-4.97319261907647", 
"-4.1611318165187", "-7.92864907263132***", "-8.72323131664597***", 
"-7.93380905076848***", "-7.25071259471702***"), .Dim = c(4L, 
2L), .Dimnames = list(c("Corn", "HH", "ICE", "AA"), c("Log", 
"Log Difference")))

然后我将 res 矩阵传递给 stargazer 函数。

library(stargazer)
stargazer(res, 
          type = "latex",
          title = "Zivot-Andrews Test Statistics", 
          colnames = TRUE, 
          notes = "Sig. Levels: *** p < .01, ** p < .05, * p < .1")

这个结果的奇怪之处在于注释正确地指定了星号(即 Sig. Levels: *** p<.01>

一个尝试的修复方法是指定矩阵条目,但没有成功,例如,

"-7.92864907263132^{***}"

"$-7.92864907263132^{***}$" 

Stargazer 将这些条目读取为字符串,而不是乳胶代码。

【问题讨论】:

    标签: r latex stargazer


    【解决方案1】:

    查看此包中的代码,您可能最好进行一些正则表达式后处理,例如

    library(stargazer)
    startup <- function(x, out=NULL, ...){
      undo <- gsub("\\\\textasteriskcentered", "*", stargazer(x, ...))
      restar <- gsub("* * *", "${}^{***}$", undo, fixed = TRUE)
      restar <- gsub("* *", "${}^{**}$", restar, fixed = TRUE)
      restar <- gsub("* ", "${}^{*}$", restar, fixed = TRUE)
      if(!is.null(out)) cat(restar, file = out, sep="\n")
      restar
    }
    
    startup(res, out = "test.tex",
              type = "latex",
              title = "Zivot-Andrews Test Statistics", 
              colnames = TRUE, 
              notes = "Sig. Levels: ${}^{***} p < .01$, ${}^{**} p < .05$, ${}^{*} p < .1$")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-03
      • 2012-09-05
      • 1970-01-01
      • 2019-09-15
      • 2015-04-02
      • 2013-09-10
      • 2015-12-11
      • 1970-01-01
      相关资源
      最近更新 更多