DeclareDesign Community

How to specify survey design for estimatr

I am conducting survey data analysis and using R survey package. The options that I am using to specify survey design are:
ids=~CPSUM, strata = ~CSTRATM, weights = ~PATWT, data=all_vars_ready, nest = TRUE

Does the estimatr support such kind of survey designs? If yes, how to specify similar design for estimatr ?

estimatr doesn’t support strata directly, AFAIR

One thing you can try is to take the probabilities out of the svydesign object, and plug them in as IPW for lm_robust - that’s essentially all svyglm is doing for you anyway. However, the degrees of freedom will probably not match svyglm.

Yes, I think that’s right – if I follow @nfultz’s advice, I get the same point estimate, but the variance estimates aren’t the same, in part because of the Robust SEs that are being estimated, but also because lm_robust doesn’t know about the strata directly.

library(DeclareDesign)
library(survey)

set.seed(343)
design <-
  declare_population(
    N = 1000,
    X = rbinom(N, 1, 0.3),
    Y = rnorm(N, mean = 3 + 0.5 * X, sd = 1 + 0.2 *
                X)
  ) +
  declare_sampling(strata = X, strata_prob = c(0.2, 0.4))


dat <- draw_data(design)

survey_design <-
  svydesign(
    id = ~ ID,
    strata =  ~ X,
    probs = ~ S_inclusion_prob,
    data = dat
  )

svy_fit <- svyglm(Y ~ 1, design = survey_design)
tidy(svy_fit, conf.int = TRUE)

lm_robust_fit <- lm_robust(Y ~ 1, weights = 1/S_inclusion_prob, data = dat)
tidy(lm_robust_fit)