是不是可以使用stargazer将回归统计数据分成多列?

huangapple go评论70阅读模式
英文:

Is it possible to separate regression statistics into multiple columns using stargazer?

问题

我明白这可能不是一个非常具体的问题,但我基本上想知道这个问题是否已经有了答案。

我有一个回归模型的结果,我想使用stargazer输出到表格中,如下所示:

======================================================================
                   Dependent variable:    
               -------------------------------------------------------
                          coefficient            se             p-value
----------------------------------------------------------------------
male                    -0.148            (0.148)            0.316
----------------------------------------------------------------------
Observations                                183            
Log Likelihood                          -1,052.273         
======================================================================
Note:          *p<0.1; **p<0.05; ***p<0.01

我想要的输出是这样的。

有没有办法使用stargazer来实现这个目标?任何帮助都将不胜感激。

英文:

I realise this might not be a very descriptive question, but I essentially want to know if this question has an answer yet.

I have a regression whose results I'd like to output in a table using stargazer, like so:

> stargazer(model1, type = "text", report = "vcsp", single.row = T)

==========================================
                   Dependent variable:    
               ---------------------------
                          enter           
------------------------------------------
male                 -0.148 (0.148)       
                        p = 0.316         
------------------------------------------
Observations               183            
Log Likelihood         -1,052.273         
==========================================
Note:          *p<0.1; **p<0.05; ***p<0.01

The output I want is this:

======================================================================
                   Dependent variable: enter  
               -------------------------------------------------------
                      coefficient            se             p-value
----------------------------------------------------------------------
male                    -0.148            (0.148)            0.316
----------------------------------------------------------------------
Observations                                183            
Log Likelihood                          -1,052.273         
======================================================================
Note:          *p<0.1; **p<0.05; ***p<0.01

Is there any way to do this using stargazer? Any help is appreciated.

答案1

得分: 1

你可以从模型输出中收集你需要的内容到一个数据框中,然后使用 stargazer 打印出来:

library(stargazer)
model <- lm(mpg ~ disp + factor(cyl), data = mtcars)
stargazer(model, type = "text", omit = "cyl")

results <- data.frame(Coefficient = summary(model)$coefficients[, 1],
                      Standard_Error = summary(model)$coefficients[, 2],
                      p_value = summary(model)$coefficients[, 4])

stargazer(results, title = "Table 1: Results", summary = FALSE, type = "text")

表1:结果

             系数     标准误     p值

(Intercept) 29.535 1.427 0
disp -0.027 0.011 0.016
factor(cyl)6 -4.786 1.650 0.007
factor(cyl)8 -4.792 2.887 0.108


<details>
<summary>英文:</summary>

You can collect what you need from your model output into a data.frame and print this with `stargazer`:

    library(stargazer)
    model&lt;-lm(mpg~disp+factor(cyl), data=mtcars)
    stargazer(model, type=&quot;text&quot;, omit=&quot;cyl&quot;)
    
    results &lt;- data.frame(Coefficient = summary(model)$coefficients[,1],
                          Standard_Error = summary(model)$coefficients[,2],
                          p_value = summary(model)$coefficients[,4])
    
    stargazer(results, title=&quot;Table 1: Results&quot;, summary=F, type = &quot;text&quot;)

    Table 1: Results
    ===============================================
                 Coefficient Standard_Error p_value
    -----------------------------------------------
    (Intercept)    29.535        1.427         0   
    disp           -0.027        0.011       0.016 
    factor(cyl)6   -4.786        1.650       0.007 
    factor(cyl)8   -4.792        2.887       0.108 
    -----------------------------------------------


</details>



huangapple
  • 本文由 发表于 2023年7月3日 17:49:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定