ycroissant / plm

Panel Data Econometrics with R
GNU General Public License v2.0
49 stars 13 forks source link

Error: "Lapack routine dgesv: system is exactly singular" with random.method = "swar" #32

Open briatte opened 1 year ago

briatte commented 1 year ago

I have posted a StackOverflow example of an error that occurs with method = "random" and random.method = "swar") (but not other random.method arguments):

# data provided at end of post

library(plm)
plm(y ~ x + factor(year), index = "panel", model = "random", random.method = "swar", data = df)

# Error in solve.default(crossprod(ZBeta)) : 
#  Lapack routine dgesv: system is exactly singular: U[15,15] = 0

The above fails with the data frame copied at the end of this issue. The issue seems to be that a singular matrix is being sent to Lapack for solving, although I do not understand why that is the case.

Changing the random.method to anything but "swar" solves the issue, so the problem seems to be located there.

Trying the same thing in Stata, using the same (Swamy-Arora) estimator, does not return an error.

df <- structure(list(y = c(0.32, 0.51, 0.26, 0.99, 0.59, 0.43, 0.6, 
0.86, 1, 0.97, 0.89, 0.63, 0.55, 0.58, 0.26, 0.69, 0.87, 0.17, 
0.09, 0, 0.87, 0.39, 0.36, 0.73, 0.13, 0.61, 0.36, 0.64, 0.72, 
0.95, 0.8, 0.96, 0.32, 0.91, 0.77, 0.14, 0.37, 0.57, 0.81, 0.98, 
0.5, 0.23, 0.8, 0.04, 0.84, 0.12, 0.56, 0.22, 0.49, 0.65, 0.59, 
0.98, 0.71, 0.58, 0.75, 0.77, 0.49, 0.72, 0.29, 0.2, 0.67, 0.06, 
0.36, 0.44, 0.65, 0.29, 0.85, 0.75, 0.2, 0.44, 0.7, 0.54, 0.19, 
0.47, 0.83, 0.47, 0.23, 0.43, 0.6, 0.48, 0.63, 0.95, 1, 0.46, 
0.28, 0.88, 0.82, 0.71, 0.57, 0.25, 0.78, 0.07, 0.45, 0.7, 0.08, 
0.2, 0.5, 0.13, 0.56, 0.12, 0.08, 0.29, 0.89, 0.37, 0.96, 0.83, 
0.81, 0.02, 0.96, 0.83, 0.51, 0.04, 0.04, 0.06, 0.44, 0.61, 0.99, 
0.83, 0.31, 0.82, 0.12, 0.18, 0.89, 0.23, 0.46, 0.73, 0.76, 0.49, 
0.32, 0.87, 0.11, 0.01, 0.96, 0.86, 0.91, 0.68, 0.8, 0.63, 0.94, 
1, 0.59, 0.5, 0.01, 0.48, 0.86, 0.92, 0.07, 0.15, 0.07, 0.33, 
0.6, 0.52, 0.12, 0.59, 0.56, 0.56, 0.55, 0.18, 0.11, 0.16, 0.27, 
0.06, 0.62, 0.34, 0.69, 0.87, 0.32, 0.31, 0.1, 0.44, 0.99, 0.96, 
0.72, 0.19, 0.81), x = c(0.25, 0.41, 0.55, 0.77, 0.95, 0.2, 0.36, 
0.58, 0.27, 0.56, 0.53, 0.88, 0.55, 0.43, 0.19, 0.54, 0.2, 0.37, 
0.18, 0.09, 0.26, 0.15, 0.75, 0.08, 0.55, 0.06, 0.23, 0.9, 0.12, 
0.51, 0.58, 0.54, 0.88, 0.24, 0.9, 0.85, 0.32, 0.43, 0.66, 0.12, 
0.09, 0.75, 0.5, 0.11, 0.07, 0.04, 0.6, 0.96, 0.39, 0.61, 0.23, 
0.28, 0.45, 0.55, 0.52, 0.99, 0.96, 0.64, 0.31, 0.47, 0.01, 0.56, 
0.7, 0.88, 0.13, 0.87, 0.2, 0.62, 0.42, 0.85, 0.5, 0.22, 0.52, 
0.15, 0.31, 0.23, 0.09, 0.76, 0.56, 0.29, 0.42, 0.87, 0.75, 0.78, 
0.67, 0.94, 0.69, 0.74, 0.07, 0.22, 0.47, 0.52, 0.85, 0.28, 0.47, 
0.39, 0.34, 0.94, 0.14, 0.5, 0.16, 0.2, 0.22, 0.71, 0.66, 0.68, 
0.54, 0.24, 0.04, 0.1, 0.44, 0.54, 0.23, 0.53, 0.24, 0.14, 0.99, 
0.18, 0.93, 0.99, 0.49, 0.39, 0.78, 0.41, 0.31, 0.11, 0.75, 0.59, 
0.85, 0.31, 0.8, 0.21, 0.67, 0.31, 0.21, 0.88, 0.84, 0.32, 0.36, 
0.89, 0.4, 0.82, 0.54, 0.18, 0.4, 0.71, 0.28, 0.83, 0.78, 0.07, 
0.93, 0.47, 0.44, 0.49, 0.71, 0.69, 0, 0.47, 0.72, 0.06, 0.13, 
0.65, 0.12, 0.26, 0.67, 0.8, 0.4, 0.82, 0.22, 0.16, 0.32, 0.01, 
0.53, 0.26, 0.99), panel = c("p1", "p1", "p1", "p1", "p1", "p1", 
"p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p2", "p3", "p3", 
"p3", "p3", "p4", "p4", "p4", "p4", "p5", "p5", "p5", "p5", "p6", 
"p6", "p6", "p6", "p6", "p6", "p6", "p6", "p6", "p7", "p7", "p7", 
"p7", "p7", "p7", "p7", "p7", "p7", "p8", "p8", "p8", "p8", "p8", 
"p8", "p8", "p8", "p9", "p9", "p9", "p9", "p10", "p10", "p10", 
"p10", "p10", "p10", "p11", "p11", "p11", "p11", "p11", "p11", 
"p11", "p11", "p11", "p12", "p12", "p12", "p12", "p12", "p12", 
"p12", "p12", "p12", "p13", "p13", "p13", "p13", "p13", "p13", 
"p13", "p13", "p13", "p14", "p14", "p14", "p15", "p15", "p15", 
"p15", "p16", "p16", "p16", "p16", "p16", "p16", "p16", "p16", 
"p16", "p17", "p17", "p17", "p17", "p17", "p17", "p17", "p17", 
"p17", "p18", "p18", "p18", "p18", "p19", "p19", "p19", "p19", 
"p19", "p19", "p19", "p19", "p19", "p20", "p20", "p20", "p20", 
"p21", "p21", "p21", "p21", "p22", "p22", "p22", "p22", "p22", 
"p22", "p22", "p22", "p22", "p23", "p23", "p23", "p23", "p24", 
"p24", "p24", "p24", "p24", "p24", "p24", "p24", "p25", "p25", 
"p25", "p25", "p26", "p26", "p26", "p26", "p27", "p27", "p27", 
"p27", "p28", "p28", "p28", "p28", "p28", "p28"), year = c(8, 
9, 10, 12, 14, 15, 1, 3, 5, 6, 9, 10, 12, 14, 15, 11, 12, 14, 
15, 10, 12, 14, 15, 10, 12, 14, 15, 1, 3, 5, 6, 9, 10, 12, 14, 
15, 1, 3, 5, 6, 9, 10, 12, 14, 15, 4, 5, 6, 9, 10, 12, 14, 15, 
10, 12, 14, 15, 8, 9, 10, 12, 14, 15, 1, 3, 5, 6, 9, 10, 12, 
14, 15, 1, 3, 5, 6, 9, 10, 12, 14, 15, 2, 3, 5, 6, 9, 10, 12, 
14, 15, 13, 14, 15, 10, 12, 14, 15, 1, 3, 5, 6, 9, 10, 12, 14, 
15, 1, 3, 5, 6, 9, 10, 12, 14, 15, 10, 12, 14, 15, 1, 3, 5, 6, 
9, 10, 12, 14, 15, 10, 12, 14, 15, 10, 12, 14, 15, 1, 3, 5, 6, 
9, 10, 12, 14, 15, 10, 12, 14, 15, 4, 5, 6, 9, 10, 12, 14, 15, 
11, 12, 14, 15, 10, 12, 14, 15, 10, 12, 14, 15, 7, 9, 10, 12, 
14, 15)), row.names = c(NA, -175L), class = "data.frame")