简体   繁体   English

如何使用要投影的因子和聚类标准误差来估计 R 中的 SUR 模型?

[英]How to estimate an SUR model in R with factors to be projected out and clustered standard errors?

I want to estimate an SUR (Seemingly Unrelated Regressions) model.我想估计一个 SUR(看似无关的回归)模型。

I tried using systemfit and its wrapper Zelig .我尝试使用systemfit及其包装器Zelig But I am not able to understand how to specify factors to be projected out (ie, add fixed effects) and cluster the standard errors, like we do in felm() .但我无法理解如何指定要投影的因子(即添加固定效应)并像我们在felm()所做的那样对标准误差进行聚类。

Also, if I simply add the fixed effect variables to my regression equations, then I get the following error:此外,如果我只是将固定效应变量添加到我的回归方程中,则会出现以下错误:

Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)

Thank you so much for your help!非常感谢你的帮助!

I am adding a data sample from my data:我正在从我的数据中添加一个数据样本:

Y_var1 <- c(0.45, 0.40, 0.30, 0.40, 0.15, 0.35, 0.50, 0.55, 0.10, 0.15, 0.30, 0.10)
Y_var2 <- c(0.40, 0.25, 0.45, 0.30, 0.35, 0.25, 0.15, 0.25, 0.35, 0.30, 0.20, 0.15)
X_var1 <- c(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
X_var2 <- c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0)
X_var3 <- c(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1)
X_var4 <- c(0.18, 0.18, 0.18, 0.20, 0.20, 0.20, 0.22, 0.22, 0.22, 0.24, 0.24, 0.24)
X_var5 <- c(0.08, 0.08, 0.08, 0.06, 0.06, 0.06, 0.04, 0.04, 0.04, 0.02, 0.02, 0.02)
X_var6 <- c(-0.25, -0.25, -0.25, 1.30, 1.30, 1.30, 1.80, 1.80, 1.80, 2.25, 2.25, 2.25)
X_var7 <- c(1000, 1000, 1000, 1500, 1500, 1500, 2000, 2000, 2000, 2500, 2500, 2500)
X_var8 <- c('ABC', 'ABC', 'ABC', 'MNO', 'MNO', 'MNO', 'DEF', 'DEF', 'DEF', 'XYZ', 'XYZ', 'XYZ')
X_var9 <- c(2000, 2010, 2020, 2000, 2010, 2020, 2000, 2010, 2020, 2000, 2010, 2020)

sample_data <- data.frame(Y_var1, Y_var2, X_var1, X_var2, X_var3, X_var4, X_var5, X_var6, X_var7, X_var8, X_var9)

library(systemfit)
formula <- list(mu1 = Y_var1 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7), 
                mu2 = Y_var2 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7))

fitsur <- systemfit(formula = formula, data=sample_data, method = "SUR")
fitols <- systemfit(formula = formula, data=sample_data, method = "OLS")

(Since this is a sample dataset, thus, the above two regressions will give an error I have mentioned above, but are working fine on my actual data.) (由于这是一个示例数据集,因此,上述两个回归将给出我上面提到的错误,但在我的实际数据上运行良好。)

However, what I am interested in is estimating the above formula using SUR, with X_var8 and X_var9 fixed effects and standard errors clustered at X_var8 level.但是,我感兴趣的是使用 SUR 估计上述公式,其中X_var8X_var9固定效应和标准误差聚集在X_var8级别。

If we use felm() , the specification is如果我们使用felm() ,则规范是

felm(mu1 = Y_var1 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7) | X_var8 + X_var9 | 0 | X_var8)

However, as my standard errors are correlated across equations, I need to use SUR.但是,由于我的标准误差与方程相关,因此我需要使用 SUR。

Any help would be much appreciated.任何帮助将非常感激。 Thank You!谢谢!

I think now I get it how to implement Fixed Effect correctly to SUR Model,我想现在我明白了如何正确地对 SUR 模型实施固定效果,

  1. we need to transform the X_var8 to numeric first with one hot encoding , and also I make new variable based by your interaction formula above我们需要首先使用一个热编码X_var8转换为数字,并且我还根据您上面的交互公式创建了新变量

    library(mltools)

    sample_data2 <- as.data.frame(one_hot(as.data.table(sample_data)))

    sample_data2$X_var13 <- sample_data2$X_var1 * sample_data2$X_var3

    sample_data2$X_var23 <- sample_data2$X_var2 * sample_data2$X_var3

  2. Check Closely the value of sample_data2$X_var13, and sample_data2$X_var23仔细检查sample_data2$X_var13和sample_data2$X_var23的值

    sample_data2$X_var13

    [1] 0 0 0 0 0 0 0 0 0 0 0 0 [1] 0 0 0 0 0 0 0 0 0 0 0 0

    sample_data2$X_var23

    [1] 0 0 0 0 0 1 0 0 0 0 0 0 [1] 0 0 0 0 0 1 0 0 0 0 0 0

Since for the desired sample data all sample_data2$X_var13 is 0, it will also effecting an error of Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory) since it doesn't have any meaningful value, we can discard it, but feel free to use it to real data由于对于所需的样本数据,所有sample_data2$X_var13都是 0,因此它还会影响Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)因为它没有有任何有意义的价值,我们可以丢弃它,但可以随意将其用于真实数据

  1. Make Formula with added fixed effects:使用添加的固定效果制作公式:

    formula <- list(mu1 = Y_var1 ~ X_var23 + X_var4 + X_var5 + X_var6 + log(X_var7) + X_var8_ABC + X_var8_DEF + X_var8_MNO + X_var8_XYZ + X_var9, mu2 = Y_var2 ~ X_var23 + X_var4 + X_var5 + X_var6 + log(X_var7) + X_var8_ABC + X_var8_DEF + X_var8_MNO + X_var8_XYZ + X_var9)

  2. Fit the SUR Model and make summary:拟合 SUR 模型并进行总结:

    fitsur <- systemfit(formula = formula, data=sample_data2, method = "SUR")

    summary(fitsur)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用因子的标准误差绘制系数点估计 - plot coefficient point estimate with standard errors for factors 如何在R中运行带有聚类标准误差和测量权重的固定效应logit模型? - How to run fixed-effects logit model with clustered standard errors and survey weights in R? 如何在 R 中创建具有聚类(按公司)标准误差的线性模型输出 - How to create an linear model output with clustered (by firms) standard error in R R中的稳健的聚类标准误差和回归权重 - Robust Clustered Standard Errors and Regression Weights in R R中具有稳健聚类标准误差的逻辑回归 - Logistic regression with robust clustered standard errors in R 具有标准误差的单个随机效应模型聚集在R(R项目)中的不同变量上 - individual random effects model with standard errors clustered on a different variable in R (R-project) 如何在 SJplot package 中生成聚集标准误差? - How to generate clustered standard errors in SJplot package? 用texreg聚集标准错误? - Clustered standard errors with texreg? R Sandwich package 是否不会产生预期的聚集稳健标准误差? - Is R Sandwich package not generating the expected clustered robust standard errors? R jupyter笔记本中具有聚类标准错误的回归表? - Regression table with clustered standard errors in R jupyter notebook?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM