rtexreg

Remove the row with the model names from a texreg output in R


How do I remove the row with the model names from a texreg output?

custom.model.names = "" or include.model.names = FALSE

don't do the trick. I have only found how to change the names from default 'Model1', 'Model2', etc to custom 'M1', 'M2', etc

Here is a reproducible example:

# data sim
library(texreg)
set.seed(1)
x <- rnorm(1000)
z <- rnorm(1000)
y <- 5 + 2*x - z + rnorm(1000,0,40)/100
# regression
m1 <- lm(y~x)
summary(m1)
m2 <- lm(y~z)
summary(m2)
m3 <- lm(y~x+z)
summary(m3)
texreg(list(m1,m2,m2),
       caption = "No Model Names or numbers, please!",
       label = NULL,
       model.names=c("M1","M2","M3"))

which generates the output:

\begin{table}
\begin{center}
\begin{tabular}{l c c c}
\hline
 & Model 1 & Model 2 & Model 3 \\
\hline
(Intercept) & $5.02^{***}$ & $4.98^{***}$  & $4.98^{***}$  \\
            & $(0.04)$     & $(0.07)$      & $(0.07)$      \\
x           & $2.01^{***}$ &               &               \\
            & $(0.03)$     &               &               \\
z           &              & $-0.98^{***}$ & $-0.98^{***}$ \\
            &              & $(0.06)$      & $(0.06)$      \\
\hline
R$^2$       & $0.78$       & $0.19$        & $0.19$        \\
Adj. R$^2$  & $0.78$       & $0.18$        & $0.18$        \\
Num. obs.   & $1000$       & $1000$        & $1000$        \\
\hline
\multicolumn{4}{l}{\scriptsize{$^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$}}
\end{tabular}
\caption{No Model Names or numbers, please!}
\label{}
\end{center}
\end{table}

I would like to suppress/exclude the line in the output with

 & Model 1 & Model 2 & Model 3 \\

Solution

  • The solution is to edit the texregTable produced by texreg()

    in the above example,

    mod <- texreg(list(m1,m2,m2),
           caption = "No Model Names or numbers, please!")
    

    alter post the texreg() command the texregTable

    mod <- gsub("\\hline\n & Model 1 & Model 2 & Model 3 \\\\\n", "", mod, fixed = T)
    

    Now the output in the texregTable is

    > mod
    
    \begin{table}
    \begin{center}
    \begin{tabular}{l c c c}
    \hline
    (Intercept) & $5.02^{***}$ & $4.98^{***}$  & $4.98^{***}$  \\
                & $(0.04)$     & $(0.07)$      & $(0.07)$      \\
    x           & $2.01^{***}$ &               &               \\
                & $(0.03)$     &               &               \\
    z           &              & $-0.98^{***}$ & $-0.98^{***}$ \\
                &              & $(0.06)$      & $(0.06)$      \\
    \hline
    R$^2$       & $0.78$       & $0.19$        & $0.19$        \\
    Adj. R$^2$  & $0.78$       & $0.18$        & $0.18$        \\
    Num. obs.   & $1000$       & $1000$        & $1000$        \\
    \hline
    \multicolumn{4}{l}{\scriptsize{$^{***}p<0.001$; $^{**}p<0.01$; $^{*}p<0.05$}}
    \end{tabular}
    \caption{No Model Names or numbers, please!}
    \label{table:coefficients}
    \end{center}
    \end{table}