[英]Inserting Stars in Custom Stargazer 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會將這些條目讀取為字符串,而不是乳膠代碼。
查看此包中的代碼,最好進行一些正則表達式后處理,例如
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$")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.