Exporting output of custom multiple regressions from R to Latex

十年热恋 提交于 2019-12-13 03:24:13

问题


I am trying to export the results of multiple regressions in a single table. Ideally, it should be formatted similar to stargazer() output. The problem is that I have not found reliably working R functions for the kind of regressions I need (Fama-MacBeth regressions), so I use my custom regression functions, which produce all necessary output (estimates of coefficients, standard errors, t-stat, R^2).

Does stargazer() or other similar function have the parameters, which allow me to export results of multiple regressions to Latex in a nice form when output of my regression is just a dataframe?

EDIT: I was just wondering whether it is possible to create publication-style tables, looking like this:


回答1:


Here's a simple example that might help you forward (example is too long for a comment, so making this an answer):

library(stargazer)
library(broom)

## generate dummy data
set.seed(123)
x <- runif(1000)
z <- x^0.5
y <-  x + z + rnorm(1000, sd=.05)
model1 <- lm(y ~ x)
model2 <- lm(y ~ z)

## transform model summaries into dataframes
tidy(model1) -> model1_tidy
tidy(model2) -> model2_tidy

merge(model1_tidy, model2_tidy, by='term', all.x=T, all.y=T)  -> output

stargazer(output, type='latex', summary=FALSE)

You will need to figure out the column headers by yourself but I believe you get the idea.



来源:https://stackoverflow.com/questions/52650829/exporting-output-of-custom-multiple-regressions-from-r-to-latex

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!