<p>I want to estimate an SUR (Seemingly Unrelated Regressions) model.</p>
<p>I tried using <code>systemfit</code> and its wrapper <code>Zelig</code>. But I am not able to understand how to specify factors to be projected out (i.e., add fixed effects) and cluster the standard errors, like we do in <code>felm()</code>.</p>
<p>What I have tried :</p>
<p>I am adding a data sample from my data:</p>
<pre><code>Y_var1 &lt;- 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 &lt;- 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 &lt;- c(0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0)
X_var2 &lt;- c(0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0)
X_var3 &lt;- c(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1)
X_var4 &lt;- 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 &lt;- 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 &lt;- 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 &lt;- c(1000, 1000, 1000, 1500, 1500, 1500, 2000, 2000, 2000, 2500, 2500, 2500)
X_var8 &lt;- c('ABC', 'ABC', 'ABC', 'MNO', 'MNO', 'MNO', 'DEF', 'DEF', 'DEF', 'XYZ', 'XYZ', 'XYZ')
X_var9 &lt;- c(2000, 2010, 2020, 2000, 2010, 2020, 2000, 2010, 2020, 2000, 2010, 2020)

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

sample_data<span class="math-container">$X_var8_Num &lt;- as.numeric(as.factor(sample_data$</span>X_var8))

library(systemfit)
formula &lt;- 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 &lt;- systemfit(formula = formula, data=sample_data, method = &quot;SUR&quot;)
fitols &lt;- systemfit(formula = formula, data=sample_data, method = &quot;OLS&quot;)
</code></pre>
<p>However, what I am interested in is estimating the above formula using SUR, with <code>X_var8</code> and <code>X_var9</code> fixed effects and standard errors clustered at <code>X_var8</code> level.</p>
<p>Using the below to estimate fixed effects results in an error in the actual data.</p>
<pre><code>formula1 &lt;- list(mu1 = Y_var1 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7) + factor(X_var8_Num) + factor(X_var9), 
                mu2 = Y_var2 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7) + factor(X_var8_Num) + factor(X_var9))

fitsur &lt;- systemfit(formula = formula1, data=sample_data, method = &quot;SUR&quot;)
fitols &lt;- systemfit(formula = formula1, data=sample_data, method = &quot;OLS&quot;)
</code></pre>
<pre><code>Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)
</code></pre>
<p>If we use <code>felm()</code>, the specification is</p>
<pre><code>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)
</code></pre>
<p>However, as my standard errors are correlated across equations as my Y variables are related, I need to use this felm specification in SUR.</p>
<p>Any help would be much appreciated. If this is something that can be done with Stata, then I am happy to switch (facing the same issue with sureg()). Thank You!</p>

CC BY-SA 4.0
2022-10-22T02:32:20.493Z
Have you solved this problem?
Jason Goal
CC BY-SA 4.0
2022-10-23T13:03:00.203Z
For my case, all the regressors were same across equations, so SUR and OLS give same results.
Anisha Garg
CC BY-SA 4.0
2022-10-23T22:47:14.490Z
Good for you. Equations in my case also share the same regressors, but the dependent variables are count data. I read from King (1989) that when the dependent variables are count data, there are still efficiency gains to using SUR even when the regressors are the same. But I have not figured out how to estimate a SUR with count data as dependent variables plus two-way fixed-effects and clustered standard error. Would appreciate it if you happen to know a way of doing it correctly.
Jason Goal
<econometrics><regression><stata><r>
How to estimate an SUR model in R with fixed effects and clustered standard errors?
Anisha Garg
# How to estimate an SUR model in R with fixed effects and clustered standard errors?

(Asked by: username_0 on 2021-07-28)

I want to estimate an SUR (Seemingly Unrelated Regressions) model.
I tried using systemfit and its wrapper Zelig. But I am not able to understand how to specify factors to be projected out (i.e., add fixed effects) and cluster the standard errors, like we do in felm().
What I have tried :
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, 1, 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)

sample_data$X_var8_Num <- as.numeric(as.factor(sample_data$X_var8))

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")

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.
Using the below to estimate fixed effects results in an error in the actual data.
formula1 <- list(mu1 = Y_var1 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7) + factor(X_var8_Num) + factor(X_var9), 
                mu2 = Y_var2 ~ X_var1*X_var3 + X_var2*X_var3 + X_var4 + X_var5 + X_var6 + log(X_var7) + factor(X_var8_Num) + factor(X_var9))

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

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

If we use felm(), the specification is
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 as my Y variables are related, I need to use this felm specification in SUR.
Any help would be much appreciated. If this is something that can be done with Stata, then I am happy to switch (facing the same issue with sureg()). Thank You!

**Tags:** econometrics, regression, stata, r
> **Comments:**
> **username_1**: Have you solved this problem?  
> **username_0**: For my case, all the regressors were same across equations, so SUR and OLS give same results.  
> **username_1**: Good for you. Equations in my case also share the same regressors, but the dependent variables are count data. I read from King (1989) that when the dependent variables are count data, there are still efficiency gains to using SUR even when the regressors are the same. But I have not figured out how to estimate a SUR with count data as dependent variables plus two-way fixed-effects and clustered standard error. Would appreciate it if you happen to know a way of doing it correctly.  

---

## 0 answers

