再次感谢劳伦特回答问题和支持modelsummary包。
library(tidyverse)
library(fixest)
library(modelsummary)
fit<-mtcars %>% feols(c(mpg,hp )~1)
fit_1 <- mtcars %>% feols(c(mpg,hp,wt )~1)
fit_2 <- mtcars %>% feols(c(mpg,hp,gear, wt )~1)
modelsummary(c(fit, fit_1, fit_2), shape=model + statistic ~ term, output="flextable")我们从所有3种模型(简单平均数)中获得了长列估计数,如下所示:

因此,是否有一种方法可以使用内部modelsummary函数或外部工作将列和行重新排列为以下格式:

最大的问题是移动这些术语,使它们在同一行上对齐(注意,fit_1和fit_2之间的术语顺序发生了变化),其余的则填充了NA。我真的很感激你的帮助!这是我过去三周来一直试图解决的一个更大问题的一部分,但没有成功。
发布于 2022-11-03 12:07:36
一种选择是输出到数据帧并手动进行整形:
library(tidyverse)
library(fixest)
library(modelsummary)
library(flextable)
fit<-mtcars %>% feols(c(mpg,hp )~1)
fit_1 <- mtcars %>% feols(c(mpg,hp,wt )~1)
fit_2 <- mtcars %>% feols(c(mpg,hp,gear, wt )~1)
models <- c(fit, fit_1, fit_2)
modelsummary(
models,
output = "dataframe",
shape = model + statistic ~ term) |>
mutate(
fit = c(rep(1, 4), rep(2, 6), rep(3, 8)),
model = trimws(model)) |>
pivot_wider(names_from = "fit", values_from = "(Intercept)") |>
select(-statistic, -part, ` ` = model) |>
flextable()

这是一个非常定制的形状和建模上下文,因此我目前无法完全使用内部modelsummary函数参数来实现这一点。
https://stackoverflow.com/questions/74298055
复制相似问题