【问题标题】:How to run fixed-effects logit model with clustered standard errors and survey weights in R?如何在 R 中运行具有聚类标准误差和调查权重的固定效应 logit 模型?
【发布时间】:2019-04-30 14:54:11
【问题描述】:

我正在使用 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 中,这似乎相当乏味。任何帮助,将不胜感激!

【问题讨论】:

  • 您可以使用接受权重的包计算 FE logit,例如clogit 并在调整 vcov-matrix 后手动计算集群 SE,例如使用sandwich 包。你可能想看看这个有用的答案:stackoverflow.com/a/37529874/6574038也许你也可以考虑固定效果假人。

标签: r logistic-regression weighted


【解决方案1】:

我会查看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())

或者至少我会走这条路,因为你正在使用调查数据。

【讨论】:

    猜你喜欢
    • 2021-12-25
    • 2017-08-18
    • 2016-01-14
    • 2012-08-13
    • 2022-06-15
    • 2015-01-31
    • 2018-05-27
    • 2016-04-13
    • 1970-01-01
    相关资源
    最近更新 更多