英文:
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<-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=F, type = "text")
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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论