Output each factor level as dummy variable in stargazer summary statistics table

前端 未结 3 1047
情书的邮戳
情书的邮戳 2020-12-30 15:46

I\'m using the R package stargazer to create high-quality regression tables, and I would like to use it to create a summary statistics table. I have a factor variable in my

3条回答
  •  一生所求
    2020-12-30 16:18

    The package tables can be useful for this task.

    library(car)
    library(tables)
    data(Blackmore)
    
    # percent only:
    (x <- tabular((Factor(group, "") ) ~ (Pct=Percent()) * Format(digits=4), 
        data=Blackmore))
    ##              
    ##         Pct  
    ## control 37.99
    ## patient 62.01
    
    # percent and counts:
    (x <- tabular((Factor(group, "") ) ~ ((n=1) + (Pct=Percent())) * Format(digits=4), 
        data=Blackmore))
    ##                      
    ##         n      Pct   
    ## control 359.00  37.99
    ## patient 586.00  62.01
    

    Then it's straightforward to output this to LaTeX:

    > latex(x)
    \begin{tabular}{lcc}
    \hline
      & n & \multicolumn{1}{c}{Pct} \\ 
    \hline
    control  & $359.00$ & $\phantom{0}37.99$ \\
    patient  & $586.00$ & $\phantom{0}62.01$ \\
    \hline 
    \end{tabular}
    

提交回复
热议问题