julia - 如何在 Julia 中提取面板数据后的平均边际效应(或预测值)?

标签 julia marginal-effects

我正在使用这个有用的包 https://github.com/FixedEffects/FixedEffectModels.jl在 Julia 中,它有助于运行固定效应模型。

但我有一个问题,我不确定如何在使用该包后提取交互变量的平均边际效应或预测值。例如,下面两行显示了如何在 Stata 中提取平均边际效应。

xtreg chronic_illness age country_birth social_class#macro_unemployment, fe
margins crisis, dydx(social_class)

以下是如何在 R 中提取它们: How to run the predicted probabilities (or average marginal effects) for individuals fixed effects in panel data using R?

Julia 中是否有类似的版本?

这是我在 Julia 中运行的模型:

m= reg(df1, @formula(chronic_illness ~ status+ age + social_class*crisis + fe(id) + fe(year) + fe(country)), contrasts=contr,save=true)
 

慢性病是一个二元变量(0=没有慢性病),危机是一个二元变量(0=没有金融危机)。这个想法是看看在没有危机时与有危机时相比,不同社会阶层在慢性病上的得分是多少。这里的模型只是向我展示了交互作用,但我对基线值很感兴趣。

这是输出:

                                         Fixed Effect Model                                           
========================================================================================================
Number of obs:                              1468882  Degrees of freedom:                          459252
R2:                                           0.703  R2 Adjusted:                                  0.567
F-Stat:                                     62.8378  p-value:                                      0.000
R2 within:                                    0.001  Iterations:                                      18
========================================================================================================
cillness                           |    Estimate  Std.Error     t value Pr(>|t|)   Lower 95%   Upper 95%
-------------------------------------------------------------------------------------------------------
status: Unemployed                 |   0.0145335 0.00157535     9.22556    0.000   0.0114459   0.0176212
status: missing                    | -0.00702545  0.0136504    -0.51467    0.607  -0.0337797   0.0197288
age                                |  0.00178437    2.79058 0.000639427    0.999    -5.46766     5.47123
class: Lower-middle class          |  0.00458331    250.251  1.83149e-5    1.000    -490.478     490.487
class: Working class               |   0.0286466    163.324 0.000175398    1.000    -320.081     320.138
crisis                             | -0.00600744 0.00156138    -3.84753    0.000 -0.00906768 -0.00294719
class: Lower-middle class & crisis | -0.00189866 0.00192896   -0.984289    0.325 -0.00567936  0.00188205
class: Working class & crisis      | -0.00332881 0.00170221    -1.95558    0.051  -0.0066651  7.46994e-6

最佳答案

我不知道 Julia 中 emmeans 的精确匹配,但您可能对 Effects.jl 感兴趣包裹。来自文档:

Regression models are useful but they can be tricky to interpret. Variable centering and contrast coding can obscure the meaning of main effects. Interaction terms, especially higher order ones, only increase the difficulty of interpretation. Here, we introduce Effects.jl which translates the fitted model, including estimated uncertainty, back into data space. Using Effects.jl, it is possible to generate effects plots that enable rapid visualization and interpretation of regression models.

顺便说一句,您的模型中似乎有一个二元响应,因此您可能不应该拟合线性模型,而是适合您的数据的模型,这样您就可以将系数解释为概率/对数几率的变化,例如逻辑或概率模型。 (请注意,虽然 FixedEffectsModels 不支持这些,但如果您的数据不是太大或 GLFixedEffectModels ,您必须回到 GLM.jl)。

关于julia - 如何在 Julia 中提取面板数据后的平均边际效应(或预测值)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72990931/

相关文章:

dataframe - julia 数据框更改一个单元格会更改整行

r - 如何在 lm() 之后在 R 中复制 Stata 的 "margins at"

r - 调查加权和多重估算数据的汇总平均边际效应

r - R中mlogit的边际效应

hadoop - 为 julia 安装 HDFS 接口(interface)包

json - Julia lang - 如何从 HTTP URL 读取 JSON

arrays - Julia:三维数组(性能)

dataframe - 在 Julia 中将一维数组转换为 DataFrame