R - stargazer添加参考类别

时间:2016-11-18 18:19:05

标签: r latex summary stargazer

我想知道是否有人使用Declare @SQL as varchar(1000) Set @SQL = 'Select ''create synonym syn_'' + t.name + '' for ['' + DB_NAME() + ''].[''+ s.name + ''].['' + t.name + '']'' from sys.tables t inner join sys.schemas s on t.schema_id = s.schema_id where t.type = ''U'' and t.name in (''Episode'',''MasterNPI'',''Patient'',''Enterprises'')' Print @SQL 来提供显示分类变量参考类别的解决方案?

stargazer

让我们假设library(stargazer) gear是分类变量

carb

我使用

运行mtcars$gear = factor(mtcars$gear) mtcars$carb = factor(mtcars$carb)
ols

lm1 = lm(disp ~ gear + carb, mtcars) 结果。

stargaze

我得到了

enter image description here

但是,我发现自己总是回到stargazer(lm1, single.row = TRUE, omit.table.layout = "sn") 文件来自定义参考类别

enter image description here

基本上,我所做的是在变量之间添加tex

latex

等等。

任何人都知道我是否可以在gear (ref = 3) & \\ \-\hspace{0.3cm} gear4 & $-$202.921$^{***}$ (22.477) \\ 函数中添加这些lines

2 个答案:

答案 0 :(得分:2)

您可以通过向foreach (var @class in classes) { foreach (var pupil in @class.Pupils) pupil.GradutaionYear = @class.GraduationYear; await _classRepository.AddClass(@class); } await _classRepository.SaveChanges(); 提供covariate.labels来获得所需的输出:

stargazer

产量

library(magrittr)
library(stringr) 
library(stargazer) 

covlabels <-
    names(lm1$coefficients)[-1] %>%
    if_else(str_sub(., 1, 4) == "gear" | str_sub(., 1, 4) == "carb", paste("\\-\\hspace{0.3cm}", .), .) %>%
    if_else(str_sub(., 18, 24) == "gear4", paste("gear (ref=3) \\\\", .), .) %>%
    if_else(str_sub(., 18, 24) == "carb2", paste("carb (ref=1) \\\\", .), .) 

stargazer(lm1, single.row = TRUE,  omit.table.layout = "sn", covariate.labels=covlabels)

答案 1 :(得分:1)

如果您愿意接受我修改后的策略,请提取lm1-object中xlevels - lidt-item的名称及其相关的第一级,并替换&#34的粘贴字符值;(拦截)值:

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

我现在得到:

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} 

我似乎没有正确配置的Latex工具链,可能是因为增强的安全功能&#34; Apple推出了上一次OSX&#34;升级&#34;。