【问题标题】:error when using causalweights package in R在 R 中使用 causalweights 包时出错
【发布时间】:2023-01-27 00:00:19
【问题描述】:

我试图使用 causalweightspackage 中的逆概率加权来估计因果效应。但是,我不断遇到以下错误消息:

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

我想在考虑包含多个控制变量的矩阵的情况下估计因果效应。当使用数据集中的单个控件时,R 设法生成估计值,但是当我尝试使用包含所有控制变量的矩阵时,我收到上述错误消息。

我的代码如下所示,当使用单个控件而不是我预定义的多个控件矩阵时,它似乎会生成估计值,如下面的代码所示:

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)

有没有人遇到过类似的问题并找到了解决方案?

提前致谢

【问题讨论】:

    标签: r bootstrap-4 variable-length propensity-score-matching


    【解决方案1】:

    此外,这是我的控件当前的外观: head from controls matrix

    【讨论】:

    • 您的答案可以通过其他支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以在in the help center找到更多关于如何写出好的答案的信息。
    猜你喜欢
    • 2012-06-12
    • 2017-06-10
    • 2016-06-20
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多