R - stargazer add reference categories

前端 未结 2 1939
夕颜
夕颜 2021-01-13 13:46

I was wondering if someone came with a solution to show up the reference categories of categorical variables using stargazer?

library(stargazer         


        
2条回答
  •  青春惊慌失措
    2021-01-13 14:19

    If you are willing to accept my revised strategy, then extract the names of the xlevels-lidt-item in the lm1-object, and their associated first levels and substitute the pasted character values for the "(Intercept) value:

    baselines = sapply( lm1$xlevels, "[[", 1)
    names(lm1$coefficients)[1] = paste0( names(baselines), " = ", baselines, 
                                         collapse="; ")
    

    I now get:

    stargazer(lm1, single.row = TRUE,  omit.table.layout = "sn")
    
    % Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
    % Date and time: Sat, Nov 19, 2016 - 07:49:18
    \begin{table}[!htbp] \centering 
      \caption{} 
      \label{} 
    \begin{tabular}{@{\extracolsep{5pt}}lc} 
    \\[-1.8ex]\hline 
    \hline \\[-1.8ex] 
     & \multicolumn{1}{c}{\textit{Dependent variable:}} \\ 
    \cline{2-2} 
    \\[-1.8ex] & disp \\ 
    \hline \\[-1.8ex] 
     gear = 3; carb = 1 & 250.226$^{***}$ (24.363) \\ 
      gear4 & $-$202.921$^{***}$ (22.477) \\ 
      gear5 & $-$160.898$^{***}$ (36.282) \\ 
      carb2 & 71.282$^{**}$ (27.919) \\ 
      carb3 & 25.574 (39.919) \\ 
      carb4 & 155.852$^{***}$ (27.355) \\ 
      carb6 & 55.672 (68.065) \\ 
      carb8 & 211.672$^{***}$ (68.065) \\ 
     \hline \\[-1.8ex] 
    \hline 
    \hline \\[-1.8ex] 
    \end{tabular} 
    \end{table} 
    

    I don't seem to have a properly configured Latex toolchain anymore, probably due to the "enhanced security features" Apple introduced in the last OSX "upgrade".

提交回复
热议问题