R/calcFittedRegMat.R

Defines functions calcFittedRegMat

calcFittedRegMat<- function( xMatAll, zMatEq, nEq, nObsEq, useMatrix, solvetol ) {
   # fitted values of regressors for IV estimations
      xMatHatEq <- list()
      for(i in 1:nEq) {
         # rows that belong to the ith equation
         rowsEq <- c( (1+sum(nObsEq[1:i])-nObsEq[i]):(sum(nObsEq[1:i])) )
         # extract instrument matrix
         xMatAllThisEq <- xMatAll[ rowsEq, ]
         if( useMatrix ){
            xMatAllThisEq <- as( xMatAllThisEq, "denseMatrix")
         }
         xMatHatEq[[ i ]] <- zMatEq[[i]] %*%
            solve( crossprod( zMatEq[[i]] ),
            crossprod( zMatEq[[i]], xMatAllThisEq ), tol = solvetol )
      }
      # fitted values of all regressors
      xMatHatAll <- .stackMatList( xMatHatEq, way = "below",
         useMatrix = useMatrix )

      return( xMatHatAll )
}

Try the systemfit package in your browser

Any scripts or data that you put into this service are public.

systemfit documentation built on March 31, 2023, 9:26 p.m.