在自定义Stargazer表中插入星星

在自定义Stargazer表中插入星星,r,latex,stargazer,R,Latex,Stargazer,使用下图可以理解我的问题 这是一张不错的桌子,除了一个问题。我希望星星(即星号)是对数差列中的上标。我该怎么做呢 为了生成表,我使用了以下矩阵 Log Log Difference Corn "-4.6242962032095" "-7.92864907263132***" HH "-4.6298901146614" "-8.72323131664597***" ICE "-4.97319261907647" "-7.9338

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

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

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

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

这个结果的奇怪之处在于,注释正确地指定了星号(即Sig.Levels:**p查看此包中的代码,您可能最好进行一些正则表达式后处理,例如:

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$")
库(stargazer)
启动
"-7.92864907263132^{***}"
"$-7.92864907263132^{***}$" 
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$")