[英]How to run fixed-effects logit model with clustered standard errors and survey weights in R?
I am using Afrobarometer survey data using 2 rounds of data for 10 countries. 我正在使用Afrobarometer调查数据,使用10个国家的2轮数据。 My DV is a binary 0-1 variable.
我的DV是二进制0-1变量。 I need to use logistic regression, fixed-effects, clustered standard errors (at country), and weighted survey data.
我需要使用逻辑回归,固定效应,聚类标准错误(在国家/地区)和加权调查数据。 A variable for the weights already exists in the dataframe.
权重的变量已存在于数据框中。
I've been looking at help files for the following packages: clogit, glm, pglm, glm2, zelig, bife , etc. Typical errors include: can't add weights, can't do fixed effects, cant do either or etc. 我一直在寻找以下软件包的帮助文件: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")
I either get error messages or the code doesn't include one of the conditions I need to include, so I can't use them. 我要么收到错误消息,要么代码不包含我需要包含的条件之一,所以我不能使用它们。 In Stata it appears this process is very simple, but in R it seems rather tedious.
在Stata看来,这个过程非常简单,但在R中似乎相当乏味。 Any help would be appreciated!
任何帮助,将不胜感激!
I would check out the survey
package which provides everything for which you are asking. 我会查看
survey
包,其中提供了您要求的所有内容。 The first step is to create the survey object, specify the survey weights and then you are off to the races. 第一步是创建调查对象,指定调查权重,然后您将参加比赛。
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())
Or at least I would go down this path given you are using survey data. 或者至少我会沿着这条路走下去,因为你正在使用调查数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.