在自定义观星器中插入星星 table

Inserting Stars in Custom Stargazer table

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

这很好table,除了一个问题。我希望星星(即星号)成为对数差异列中的上标。我该怎么做。

为了生成 table 我使用了以下矩阵

     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 将这些条目作为字符串读取,而不是乳胶代码。

查看此包中的代码,您最好做一些正则表达式 post 处理,例如

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