stargazer 패키지를 사용하여 내 plm 모델의 일부 테이블을 인쇄하려고합니다. 테이블에 메모를 추가 할 때까지 모든 것이 괜찮 았습니다. 불행히도 메모를 추가 할 때 출력 테이블이 왜곡되어 각 열 사이에 큰 공백이 있습니다. 누구든지 문제를 해결할 수 있습니까? 미리 감사드립니다!
참고 : 아직 Latex를 배우는 중이므로 html에서도 작동하는 솔루션을 환영합니다.
#Here I create a simple data.frame just to replicate my data
vector <- rep(0,72)
for (i in 1:72) {
vector[i] <- rnorm(1)
}
data <- as.data.frame(matrix (vector, nrow = 7))
#This outputs a normal table, with normal space width between columns
stargazer(data,
type = "text",
style = "AER")
#This is the note I want to print. However, it returns an error if I space it out like that.
stargazer(data,
type = "text",
notes = c("All models were estimated by fixed effects estimator. Errors are robust to heteroscedasticity and
autocovariance. Numbers between parenthesis are the coefficient standard deviations. * represents
significance at the 10 % level, ** represents significance at the 5% level, and *** represents significance
at the 1% level. Models (1), (2) and (3) refer, respectively, to equations (7), (8) and (9)"),
style = "AER")
#This outputs the table. However, there are big blank spaces between columns. How do I fix this?
stargazer(data,
type = "text",
notes = c("All models were estimated by fixed effects estimator. Errors are robust to heteroscedasticity and autocovariance. Numbers between parenthesis are the coefficient standard deviations. * represents significance at the 10 % level, ** represents significance at the 5% level, and *** represents significance at the 1% level. Models (1), (2) and (3) refer, respectively, to equations (7), (8) and (9)"),
style = "AER")
LaTeX 솔루션
비슷한 문제가 있었고 여기에 LaTeX에 대한 솔루션이 있습니다.
먼저 메모가 포함 된 자체 미니 페이지를 생성하는 별도의 기능이 필요합니다.
library(stargazer)
stargazernote <- function(starGazerCmd, outputfile, note){
# inserts 'note' to the end of stargazer generated latex table
ssn <- gsub(x=starGazerCmd, pattern='\\end{tabular}',
replacement=paste('\\end{tabular}', '\n',
'\\centerline{\\begin{minipage}{0.95\\textwidth}~\\', '\n',
'\\footnotesize{' , note,
'} \\end{minipage}}', sep=''), fixed=T)
cat(ssn,sep='\n',file=outputfile)
}
(매개 변수로 연주하고 싶을 수 있습니다 {0.95\\textwidth}
. 어떤 사람들은 음표에 대해 약간 더 넓거나 더 좁은 너비를 선호합니다.)
다음과 같이 메모없이 Stargazer 라텍스 테이블을 만듭니다.
s <- stargazer(data,
type = "latex",
style = "AER",
notes.append=FALSE,
)
그런 다음 별도로 메모를 만듭니다.
note <- "All models were estimated by fixed effects estimator. Errors are robust to heteroscedasticity and autocovariance. Numbers between parenthesis are the coefficient standard deviations. * represents significance at the 10 \\% level, ** represents significance at the 5\\% level, and *** represents significance at the 1\\% level. Models (1), (2) and (3) refer, respectively, to equations (7), (8) and (9)"
다음은 첫 번째 문제입니다. %
기호는 LaTeX에 의해 주석 기호로 해석되므로 %
앞에 \\
.
이제 위의 기능을 사용하여 노트와 LaTeX 테이블을 대조 할 수 있습니다.
stargazernote(s, note=note, outputfile='foo.tex')
두 번째 문제는 LaTeX 파일에 graphicx를 포함해야한다는 점입니다. .tex 파일은 다음과 같습니다.
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{graphicx} %% note: the table will not render without this package.
\begin{document}
\include{foo.tex}
\end{document}
텍스트 솔루션
다음과 같은 메모에서 줄 변경을 강제 할 수 있습니다 ( 이 SO 질문 에서 복사 됨 ).
stargazer(data,
type = "text",
notes= c("All models were estimated by fixed effects estimator.",
"Errors are robust to heteroscedasticity and autocovariance.",
"Numbers between parenthesis are the coefficient standard deviations.",
"* represents significance at the 10 % level",
"** represents significance at the 5% level,",
"and *** represents significance at the 1% level.",
"Models (1), (2) and (3) refer, respectively, to equations (7), (8) and (9)"),
style = "AER")
산출:
=================================================================================
Statistic N Mean St. Dev. Min Pctl(25) Pctl(75) Max
---------------------------------------------------------------------------------
V1 7 0.184 0.380 -0.230 -0.004 0.231 0.957
V2 7 -0.083 1.018 -1.246 -0.827 0.631 1.322
V3 7 -0.058 0.752 -0.733 -0.610 0.495 1.025
V4 7 -0.316 1.106 -2.223 -0.725 0.412 1.120
V5 7 -0.242 0.927 -1.777 -0.809 0.397 0.743
V6 7 -0.020 1.403 -1.453 -1.202 0.756 2.348
V7 7 0.565 1.130 -1.459 0.156 1.224 2.023
V8 7 0.840 0.938 -0.493 0.334 1.302 2.256
V9 7 -0.191 0.761 -1.012 -0.766 0.236 1.107
V10 7 0.530 0.643 -0.222 0.144 0.680 1.768
V11 7 0.263 0.396 -0.230 -0.004 0.432 0.957
---------------------------------------------------------------------------------
All models were estimated by fixed effects estimator.
Errors are robust to heteroscedasticity and autocovariance.
Numbers between parenthesis are the coefficient standard deviations.
* represents significance at the 10 % level
** represents significance at the 5% level,
and *** represents significance at the 1% level.
Models (1), (2) and (3) refer, respectively, to equations (7), (8) and (9)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다