问题
I am running regression analysis in R and unsure how to export my regression analysis results directly into Excel in standard regression table format (with significance level stars, standard errors, p-value
, 95% confidence interval, R-sqr
, F-test
).
In stata, I would use the outreg2
command, which automatically generates a regression table, and I was wondering, if R has a similar code?
For example:
reg <- lm(imbd_score ~ budget
+ duration
+ year
+ cast_total_facebook_likes,
data = imbd)
summary(reg)
And then exporting this table into excel.
回答1:
I did the following, I don't know if there exists a smoother procedure, but the trick is to transform regression results in a data.frame object and then export them:
install.packages("outreg")
library("outreg")
table<-outreg(OLS, digits = 3L, alpha = c(0.1, 0.05, 0.01),
bracket = c("se"), starred = c("coef"), robust = FALSE, small = TRUE,
constlast = FALSE, norepeat = TRUE)
install.packages("XLConnect")
library("XLConnect")
writeWorksheetToFile("yourdirectory/OLS.xlsx",
data = table,
sheet = "OLS",
header = TRUE,
clearSheets = TRUE)
OLS is my object created by a lm regression.
Hope this can help,
Silvia D'Andrea
来源:https://stackoverflow.com/questions/49958828/exporting-and-formatting-regression-analysis-results-in-r-to-excel