Hi, I have a set of matrix data named “invest” consists of 450 observations (75 countries, 6 years) with 7 variables (set as I, pop, inv, gov, c, life, d; which each is “numeric[450]”). The procedure is modify from code provided by B.E. Hansen at http://www.ssc.wisc.edu/~bhansen/progs/ecnmt_00.html. *Then the variable is being transformed to* y <- lag_v(i,0) cf <- lag_v(c,0) lpop <- lag_v(pop,0) linv <- lag_v(inv,0) lgov <- lag_v(gov,0) d1 <- lag_v(d,0) llife <- lag_v(life,0) yt <- tr(y) ct <- tr(cf) y, cf, lpop, linv, lgov, d1, llife each is in “375x1 double matrix” yt and ct each is “300x1 double matrix” (I use R Studio so these characteristics are stated). *The lag_v() and tr() process is as below:* max_lag <- 1 tt <- t-max_lag ty <- n*(t-max_lag-1) lag_v <- function(x,lagn){ yl <- matrix(c(0),nrow=n,ncol=t) for (i in 1:n) { yl[i,]<-x[(1+(i-1)*t):(t*i)] } yl <- yl[,(1+max_lag-lagn):(t-lagn)] out <- matrix(t(yl),nrow=nrow(yl)*ncol(yl),ncol=1) out } tr <- function(y){ yf <- matrix(c(0),nrow=n,ncol=tt) for (i in 1:n) { yf[i,]<-y[(1+(i-1)*tt):(tt*i)] } yfm <- yf- colMeans(t(yf)) yfm <- yfm[,1:(tt-1)] out <- matrix(t(yfm),nrow=nrow(yfm)*ncol(yfm),ncol=1) out } *Then before the computation, something is being setup* x <- cbind(lpop, linv, lgov, llife, cf) … (skip as I think is unrelated with the problem encounter) *And, in the early stage of computation:* sse_calc <- function(y,x){ e <- y-x%*%qr.solve(x,y) out <- t(e)%*%e out } … *It comes out with* Error in qr.solve(x, y) : singular matrix 'a' in solve I thought only square matrix would have this kind of problem. Would qr() help in this case? Or is there any other possible solution for this problem? Thanks. [[alternative HTML version deleted]]