melff / memisc

Tools for Managing Survey Data, Creating Tables of Estimates and Data Summaries
https://melff.github.io/memisc
45 stars 8 forks source link

mtable() summary.stats not showing R-squared #54

Closed mamun4105 closed 3 years ago

mamun4105 commented 3 years ago

Hello,

I am using felm from lfe package. I wrote a getSummary.felm function as follow:

getSummary.felm <- function (obj, alpha = 0.05, ...) {
  smry <- summary(obj)
  coef <- smry$coef

  numdf <- unname(smry$F.fstat[2])
  dendf <- unname(smry$F.fstat[3])

  lower <- coef[, 1] + coef[, 2] * qt(p = alpha/2, df = dendf)
  upper <- coef[, 1] + coef[, 2] * qt(p = 1 - alpha/2, df = dendf)
  coef <- cbind(coef, lower, upper)
  dn <- list(rownames(coef), c("est", "se", "stat", 
                               "p", "lwr", "upr"), all.vars(obj$formula)[1])
  dim(coef) <- c(dim(coef)[1], dim(coef)[2], 1)
  dimnames(coef) <- dn
  sigma <- smry$sigma
  r.squared <- smry$r.squared
  adj.r.squared <- smry$adj.r.squared
  F <- unname(smry$F.fstat[1])
  p <- pf(F, numdf, dendf, lower.tail = FALSE)
  N <- length(smry$residuals)
  ll <- logLik(obj)
  deviance <- deviance(obj)
  AIC <- AIC(obj)
  BIC <- AIC(obj, k = log(N))
  sumstat <- c(sigma = sigma, r.squared = r.squared, adj.r.squared = adj.r.squared, 
               F = F, numdf = numdf, dendf = dendf, p = p, logLik = ll, 
               deviance = deviance, AIC = AIC, BIC = BIC, N = N)
  list(coef = coef, sumstat = sumstat, contrasts = obj$contrasts, 
       xlevels = obj$xlevels, call = obj$call)
}

NOW, I would like to produce a table using the following command:

impair_table <- mtable("impair_quality" = did_impair_quality,
                           "impair" = did_impair,

                           summary.stats = c("N", "R-squared","Log-likelihood", "BIC", "AIC"),
                           signif.symbols = c("***" = .01, "**" = .05, "*" = .1),
                           digits = 4)

It is showing all summary.stats but R-squared. I also tried it as "r.squared" or "adj.r.squared" but nothing works. It just ignored the request.

Thanks, Saleh

melff commented 3 years ago

You may want to add

setSummaryTemplate("felm" = c(
  "R-squared" = "($r.squared:f#)",
  "adj. R-squared" = "($adj.r.squared:f#)",
  F = "($F:f#)",
  AIC = "($AIC:f#)",
  BIC = "($BIC:f#)",
  "Log-likelihood"="($logLik,f#)",
  p = "($p:f#)",
  N = "($N:d)"
))