简体   繁体   English

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

[英]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.

相关问题 R中的加权随机效应Logit模型 - Survey Weighted Random Effects Logit Model in R 使用plm(具有固定效果)的R中的聚类标准错误 - Clustered standard errors in R using plm (with fixed effects) R:具有组固定效应的回归和具有估算数据集的聚类标准误差 - R: Regressions with group fixed effects and clustered standard errors with imputed dataset 使用调查权重时,如何为Logit模型产生边际效应? - How can I generate marginal effects for a logit model when using survey weights? R:如何用权重估计固定效应模型 - R: how to estimate a fixed effects model with weights 如何计算纵向/面板数据的非线性(二进制)固定效应 Logit? - How to calculate nonlinear (binary) Fixed-Effects Logit for Longitudinal/Panel Data? 使用 R 报告调查加权 logit 模型的平均边际效应 - Reporting average marginal effects of a survey-weighted logit model with R R中的稳健的聚类标准误差和回归权重 - Robust Clustered Standard Errors and Regression Weights in R 如何在R中运行调查权重? - How to run survey weights in R? lm_robust model 的 ggpredict 错误,包括固定效应和聚集标准错误 - ggpredict error with lm_robust model including fixed effects and clustered standard errors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM