0

I was trying to estimate a causal effect using inverse probability weighting from the causalweightspackage. However, I keep running into the following error message:

Error in model.frame.default(formula = d ~ x, drop.unused.levels = TRUE) : 
variable lengths differ (found for 'x')

I want to estimate the causal effect taking into consideration a matrix including multiple control variables. When using a single control from the data-set, R manages to generate an estimate, but when I try to use the matrix including all my control variables, I receive the above-mentioned error message.

My code is as follows and appears to generate estimates when using a single control instead of my predefined matrix of multiple controls as observable in the following code:

attach(data_clean2)
controls <- cbind(marits_1, nationality1, mother_tongue1, educ1,
                  lastj_fct1, child_subsidies, contr_2y,
                  unempl_r, gdp_gr, insured_earn)


ipw_atet <- treatweight(y = duration_ue2, # take initial data
                        d = treatment,
                        x = controls,
                        ATET = TRUE, # if = FALSE, estimates ATE (default)
                        trim = (1-pscore_max0),
                        boot = 2)

Has anyone encountered similar problems and found a solution?

Thanks in advance

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a table or screenshot for example). One way of doing is by using the `dput` function on the data or a subset of the data you are using, then pasting the output into your question. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Jan 26 '23 at 16:07

0 Answers0