I am hoping to run a logit regression which predicts the marginal effect at the mean of family size and age, and the effect of binary indicators (whether an individual is an immigrant, has health insurance, or smokes) on the predicted probability of developing hypertension.
This data comes from a clustered survey, and I am hoping to include robust clustered standard errors in the output.
But when I add the code to include robust cluster SE, I receive an error that the variables in my regression are not longer found and I'm not sure why. Any advice would be great! Thanks.
AGE IMMIGRANT FAMSIZE HLTH_INS HYPERTEN SMOKE PSU
<int> <dbl> <int> <dbl> <dbl> <dbl> <int>
40 0 2 1 0 0 2
23 0 2 1 0 0 1
24 0 2 1 0 0 2
18 0 3 1 1 0 2
30 0 2 1 0 0 2
33 1 6 0 0 0 1
#or if this is an easier output to reproduce:
structure(list(AGE = c(40L, 23L, 24L, 18L, 30L, 33L, 32L, 63L,
22L, 24L), IMMIGRANT = c(0, 0, 0, 0, 0, 1, 0, 0, 0, 1), FAMSIZE = c(2L,
2L, 2L, 3L, 2L, 6L, 2L, 1L, 2L, 1L), HLTH_INS = c(1, 1, 1, 1,
1, 0, 1, 1, 1, 0), HYPERTEN = c(0, 0, 0, 0, 0, 0, 0, 1, 0, 0),
SMOKE = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 1), PSU = c(2L, 1L,
2L, 2L, 2L, 1L, 2L, 2L, 1L, 2L)), row.names = c(NA, -10L), class = "data.frame")
#The regression works without adjusting for clustered SE
logit<-logitmfx(HYPERTEN~scale(AGE)+IMMIGRANT+scale(FAMSIZE)+HLTH_INS+
SMOKE,data=sample,
atmean=TRUE,robust=T)
#However, when I add in the code to cluster SE I receive the error: "Error in scale(AGE) : object 'AGE' not found"
logit<-logitmfx(HYPERTEN~scale(AGE)+IMMIGRANT+scale(FAMSIZE)+HLTH_INS+
SMOKE,data=sample,
atmean=TRUE,robust=T,clustervar1="PSU", clustervar2=NULL,!is.null("PSU"))