【问题标题】:Stargazer regression table not displaying basic statisticsStargazer 回归表不显示基本统计数据
【发布时间】:2021-11-23 12:28:54
【问题描述】:

我创建了以下针对异方差进行调整的线性模型:

library(sandwich)
library(stargazer)

df <- data.frame(A = rnorm(1000, 500, 10), B = rnorm(1000, 500, 10), C = rnorm(1000, 500, 10), D = rnorm(1000, 500, 10))
mod <- lm(A ~ B + C + D, df)
vcov <- vcovHC(mod, type= "HC1")

# Creating robust standard-erros
robust_se <- sqrt(diag(vcov)) 
robust_se <- list(robust_se[1:3]) # Keeping the robust se for the intercept and variables B and C only, since I don't want to display D in the regression table

stargazer(mod, 
          summary = TRUE,
          keep = c("B", "C"),
          keep.stat = c("n", "f", "rsq", "adj.rsq"),
          notes.align = "l",
          dep.var.labels=c("Value"),
          covariate.labels=c("B", "C"),
          se = robust_se,
          out="directory.html")

我正在使用“survey”包处理调查数据。

即使我指定要显示 R²、调整后的 R² 和 F 统计量,打印的回归表也仅显示观察数:

% Table created by stargazer v.5.2.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: sex, out 01, 2021 - 20:58:05
\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] & Value \\ 
\hline \\[-1.8ex] 
 B & 0.013 \\ 
  & (0.032) \\ 
  & \\ 
 C & $-$0.019 \\ 
  & (0.031) \\ 
  & \\ 
 Constant & 497.270$^{***}$ \\ 
  & (27.587) \\ 
  & \\ 
\hline \\[-1.8ex] 
Observations & 1,000 \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{1}{l}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

为什么会这样?

【问题讨论】:

    标签: r stargazer


    【解决方案1】:

    不幸的是,我不知道如何在stargazer 中实现这一点。如果您对更现代的替代方案感兴趣(stargazer 自 2018 年以来未更新),您可能想尝试the modelsummary package.(免责声明:我是维护者):

    df <- data.frame(A = rnorm(1000, 500, 10), B = rnorm(1000, 500, 10), C = rnorm(1000, 500, 10), D = rnorm(1000, 500, 10))
    mod <- lm(A ~ B + C + D, df)
    
    library(modelsummary)
    modelsummary(mod, 
                 vcov = "HC1", 
                 output = "latex", 
                 stars = TRUE)
    
    # \begin{table}
    # \centering
    # \begin{tabular}[t]{lc}
    # \toprule
    #   & Model 1\\
    # \midrule
    # (Intercept) & \num{550.535}***\\
    #  & (\num{26.979})\\
    # B & \num{-0.018}\\
    #  & \vphantom{1} (\num{0.030})\\
    # C & \num{-0.075}*\\
    #  & (\num{0.031})\\
    # D & \num{-0.009}\\
    #  & (\num{0.030})\\
    # \midrule
    # Num.Obs. & \num{1000}\\
    # R2 & \num{0.007}\\
    # R2 Adj. & \num{0.004}\\
    # AIC & \num{7379.2}\\
    # BIC & \num{7403.7}\\
    # Log.Lik. & \num{-3684.604}\\
    # F & \num{2.341}\\
    # Std.Errors & HC1\\
    # \bottomrule
    # \multicolumn{2}{l}{\rule{0pt}{1em}+ p $<$ 0.1, * p $<$ 0.05, ** p $<$ 0.01, *** p $<$ 0.001}\\
    # \end{tabular}
    # \end{table}
    

    【讨论】:

      猜你喜欢
      • 2020-04-01
      • 2019-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-12
      • 2021-11-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多