I want to print a stargazer generated table from r into my latex document. I created the table named table_1.tex and put it in the same directory as my latex files are. First I create a simple dataset to reproduce my data:
vector <- rep(0,72)
for (i in 1:72) {
vector[i] <- rnorm(1)
}
matrix <- matrix(vector, nrow= 9)
data <- as.data.frame(matrix)
table_1 <- stargazer(data,
align=TRUE,
title = "Table 1: Main Results",
type = "text",
out.header = TRUE,
column.labels = c("Modelo", "Modelo", "Modelo","Modelo", "Modelo", "Modelo",
"Modelo", "Modelo", "Modelo"),
dep.var.labels=c("log(PIB)","log(PIB)"),
covariate.labels = c("log(DT t)", "Gini t", "log(DT t) * Gini t", "log(DT t-1)",
"Gini t-1", "log(DT t) * Gini t-1", "log(DT t-1) * Gini t-1",
"Mortinf t", "log(Prod t)", "Abertura t", "log(Pop t)"),
notes = c("All models were estimated by the fixed effects estimator. The errors are robust to heteroscedasticity and",
"autocovariance. Numbers between parenthesis are the standard-deviations of the coefficients. * represents",
"significante at 10\\%, ** at 5\\% and *** at 1\\%."),
no.space= TRUE,
style = "AER",
notes.append = FALSE,
notes.align = "l",
out = "table_1_1.tex")
Then I try to import it in latex:
\documentclass[11pt]{article}
\usepackage{fullpage}
\usepackage{graphicx}
\begin{document}
blabla
\include{table_1_1.tex}
\end{document}
However, when I compile this code, it only outputs "blabla" and not my table. Instead, there is a big, blank space where it should be. I thought it might be because I had included notes written in portuguese in stargazer. Actually, when I try to open the stargazer table file separately, it says that I should change my encoding from UTF-8 to ISO-8859-9. I've changed this in the configurations, but the code still doesn't output the table. I'm also new to latex, so excuse me if my mistakes are silly. Thanks in advance!
If you look at the table exported by stargazer, you will see that it starts by
\documentclass{article}
\usepackage{dcolumn}
\begin{document}
As you are importing the table into a document, you dont need that. You can set out.header = F
in stargazer (or leave the option out, since F is the default), and load the dcolumn
package in the main document.
Also, I think the better way to import tables is
\input{table_1_1.tex}
See here for more info:
https://www.rdocumentation.org/packages/stargazer/versions/5.2.2/topics/stargazer https://tex.stackexchange.com/questions/246/when-should-i-use-input-vs-include
Complete answer:
Stargazer
table_1 <- stargazer(data,
align=TRUE,
title = "Table 1: Main Results",
type = "text",
column.labels = c("Modelo", "Modelo", "Modelo","Modelo", "Modelo", "Modelo",
"Modelo", "Modelo", "Modelo"),
dep.var.labels=c("log(PIB)","log(PIB)"),
covariate.labels = c("log(DT t)", "Gini t", "log(DT t) * Gini t", "log(DT t-1)",
"Gini t-1", "log(DT t) * Gini t-1", "log(DT t-1) * Gini t-1",
"Mortinf t", "log(Prod t)", "Abertura t", "log(Pop t)"),
notes = c("All models were estimated by the fixed effects estimator. The errors are robust to heteroscedasticity and",
"autocovariance. Numbers between parenthesis are the standard-deviations of the coefficients. * represents",
"significante at 10\\%, ** at 5\\% and *** at 1\\%."),
no.space= TRUE,
style = "AER",
notes.append = FALSE,
notes.align = "l",
out = "table_1_1.tex")
Latex:
\documentclass[11pt]{article}
\usepackage{fullpage}
\usepackage{graphicx}
\usepackage{dcolumn}
\begin{document}
blabla
\input{table_1_1.tex}
\end{document}