【发布时间】:2021-12-05 04:42:40
【问题描述】:
我正在尝试编写一个函数来返回回归系数和标准误差,因为我需要运行大量回归。 数据可能如下所示
library(tidyverse)
library(fixest)
library(broom)
data<-tibble(Date = c("2020-01-01","2020-01-01","2020-01-01","2020-01-01","2020-02-01","2020-02-01","2020-02-01","2020-02-01"),
Card = c(1,2,3,4,1,2,3,4),
A = rnorm(8),
B = rnorm(8),
C = rnorm(8)
)
我目前的代码如下
estimation_fun <- function(col1,col2,df) {
regression<-feols(df[[col1]] ~ df[[col2]] | Card + Date, df)
est =tidy(regression)$estimate
se = tidy(regression)$std.error
output <- list(est,se)
return(output)
}
estimation_fun("A","B",example)
但是,它不起作用。我猜它与 feols 中的列名有关,因为我可以使它适用于 lm()。
【问题讨论】:
标签: r regression