[R] System GMM fails due to computationally singular system. Why?

Richard Hardy bruk@||n|@ @end|ng |rom gm@||@com
Tue Apr 23 11:05:49 CEST 2024

A copy of this question can be found on Cross Validated:

I am estimating a system of seemingly unrelated regressions (SUR) with
`gmm::sysGmm` in R. Each of the equations has one unique regressor and one
common regressor. The common regressor is a dummy variable indicating the
last observation (n-1 zeros followed by 1). I impose a restriction that the
coefficients on the common regressor are equal across equations. See a
reproducible example below.

The fitting routine yields the following error:
"Error in solve.default(w, t(hm)) :
  system is computationally singular: reciprocal condition number =
This happens only for certain types of the covariance matrix estimator:
`MDS` and `HAC`. It does not happen for `CondHom`. Also, I am able to
estimate the model without a problem using restricted OLS estimation via
`systemfit::systemfit` (code not provided). I think the latter estimator is
algebraically the same as `gmm::sysGmm` with identity weighting matrix and
the `CondHom` option for the error covariance matrix. This suggests the
problem is with estimating the error covariance matrix when allowing for
heteroskedasticity of errors. What exactly is this problem?

I can understand there would be an issue if I did not impose the
cross-equation restrictions of equality of the coefficients on the common
regressor. Then the last error of each equation would be estimated as
exactly zero, and that would upset the estimation routines under
heteroskedasticity of errors. Also, if such an estimator were used in the
first stage of the GMM, it would cause trouble there. However, with the
identity weighting matrix in GMM, I do not expect it to be used in the
first stage.

**Question:** Why does system GMM fail with an error of a computationally
singular system in my setup? What could I do to fix this?

------------------------------ R code for a reproducible example


# Generate and prepare the data
n <- 100 # sample size
m <- 1   # length of the "second part" of the sample
N <- 3   # number of equations
set.seed(321); x <- matrix(rnorm(n*N),ncol=N); colnames(x) <-
paste0("x",1:N) # generate regressors
dummy <- c( rep(0,n-m), rep(1,m) ) # generate a common regressor
x <- cbind(x,dummy)                # include the common regressor with the
rest of the regressors
set.seed(123); y <- matrix(rnorm(n*N),ncol=N); colnames(y) <-
paste0("y",1:N) # a placeholder for dependent variables
for(i in 1:N){
 y[,i] <- i + sqrt(i)*x[,i] - i*dummy + y[,i]*15*sqrt(i)
 # y[,i] is a linear function of x[,i] and dummy,
 # plus an error term with equation-specific variance
data1 <- as.data.frame(cbind(y,x)) # create a data frame of all data (y and

# Create the model equations and moment conditions
ES_g = eqSystem_h <- list()
for(i in 1:N){
 ES_g[[i]] <- as.formula(assign(paste0("eq",i), value=paste0("y",i," ~
x",i," + dummy"))) # define linear equations of SUR
 ES_h[[i]] <- as.formula(assign(paste0("eq",i), value=paste0(       "~
x",i," + dummy"))) # define the moment conditions for GMM

# Estimate the model with `sysGmm` using different weighting matrices:
identity, "optimal" and manually specified
m1 <- sysGmm(g=ES_g, h=ES_h, wmatrix="ident", vcov="MDS"    ,
crossEquConst=3, data=data1) # Error: system is computationally singular
m1 <- sysGmm(g=ES_g, h=ES_h, wmatrix="ident", vcov="HAC"    ,
crossEquConst=3, data=data1) # Error: system is computationally singular
m1 <- sysGmm(g=ES_g, h=ES_h, wmatrix="ident", vcov="CondHom",
crossEquConst=3, data=data1) # Just fine

------------------------------ R session info:

R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C

[5] LC_TIME=English_United States.utf8

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] gmm_1.8        sandwich_3.0-2

loaded via a namespace (and not attached):
[1] zoo_1.8-12        compiler_4.3.3    tools_4.3.3       rstudioapi_0.15.0
grid_4.3.3        lattice_0.22-5


Kind regards,

	[[alternative HTML version deleted]]

More information about the R-help mailing list