如何在 R 中 运行 具有聚类标准误差和调查权重的固定效应 logit 模型?

How to run fixed-effects logit model with clustered standard errors and survey weights in R?

我正在使用 Afrobarometer 调查数据,使用 10 个国家/地区的 2 轮数据。我的 DV 是二进制 0-1 变量。我需要使用逻辑回归、固定效应、聚类标准误差(在国家/地区)和加权调查数据。数据框中已存在权重变量。

我一直在查看以下软件包的帮助文件:clogit、glm、pglm、glm2、zelig、bife 等。典型错误包括:无法添加权重、无法执行固定效果、无法执行做任何一个或等等


#Glm 

t3c1.fixed <- glm(formula = ethnic ~ elec_prox + 
elec_comp + round + country, data=afb, 
weights = afb$survey_weight, 
index c("country", "round"), 
family=binomial(link='logit'))

#clogit 

t3c1.fixed2 <- clogit(formula = ethnic ~ elec_prox + 
elec_comp + round + country, data=afb, 
weights = afb$survey_weight, 
method=c("within"))


#bife attempt 

library(bife)
t3c1.fixed3 <- bife(ethnic ~ elec_prox + elec_comp + round + 
country, model = logit,data=afb, 
weights = afb$survey_weight, 
bias_corr = "ana")

我要么收到错误消息,要么代码不包含我需要包含的条件之一,因此我无法使用它们。在 Stata 中,这个过程似乎非常简单,但在 R 中似乎相当乏味。任何帮助,将不胜感激!

我会查看 survey 包,它提供了您所要求的一切。第一步是创建调查对象,指定调查权重,然后您就可以开始比赛了。

library(survey)
my_survey <- svydesign(ids= ~1, strata = ~country, wts = ~wts, data = your_data)

# Then you can use the survey glm to do what you want via

svy_fit <- svy_glm(ethnic ~ elec_prox + 
elec_comp + round + country, data = my_survey, family = binomial())

或者至少我会在你使用调查数据的情况下走这条路。