2

I'm trying to convert the output of some regression to latex with xtable or stargazer. I never had issues before, and the results of multiple regressions are organized neatly in a latex table. I'm using Fixed Effects FGLS. Therefore, I'm using the command pggls instead of plm (from package plm). Apparently, the use of that command is creating an object of this type, c("pggls", "panelmodel")

summary(fgls_fixed4)
 Within model

Call:
pggls(formula = YNCI ~ ST_CUM_NCI + ST_PUBS - ST_CLOSENESS + 
    ST_DEGREE + ST_BETWEENNESS + ST_EIGEN_CENTRALITY - ST_STRUC_HOLE - 
    ST_TRANSITIVITY + ST_BETWEENNESS:ST_TRANSITIVITY + ST_N_INST + 
    ST_E_INST + ST_N_DISC + ST_E_DISC - ST_INT_RATIO + GEN + 
    ST_AGE + ST_P_CUM + ST_P_LAG, data = pdata, model = "within")

Unbalanced Panel: n=15631, T=1-11, N=58585

Residuals
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-15.15481  -0.20764  -0.01673   0.00000   0.14333  21.63646 

Coefficients
                                 Estimate Std. Error   z-value  Pr(>|z|)    
ST_CUM_NCI                     -0.7775398  0.0050180 -154.9512 < 2.2e-16 ***
ST_PUBS                         0.1503133  0.0029285   51.3279 < 2.2e-16 ***
ST_DEGREE                      -0.0926861  0.0025087  -36.9451 < 2.2e-16 ***
ST_BETWEENNESS                  0.0316749  0.0027807   11.3909 < 2.2e-16 ***
ST_EIGEN_CENTRALITY             0.0230166  0.0025138    9.1560 < 2.2e-16 ***
ST_N_INST                       0.1784619  0.0040321   44.2605 < 2.2e-16 ***
ST_E_INST                      -0.0426594  0.0036798  -11.5927 < 2.2e-16 ***
ST_N_DISC                      -0.1026538  0.0057513  -17.8489 < 2.2e-16 ***
ST_E_DISC                       0.0810644  0.0060749   13.3441 < 2.2e-16 ***
ST_AGE                         -0.2246429  0.0246820   -9.1015 < 2.2e-16 ***
ST_P_CUM                        0.3234620  0.0129471   24.9834 < 2.2e-16 ***
ST_P_LAG                        0.0102976  0.0037214    2.7672  0.005655 ** 
ST_BETWEENNESS:ST_TRANSITIVITY  0.0396359  0.0040663    9.7475 < 2.2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 53634
Residual Sum of Squares: 23619
Multiple R-squared: 0.55962
> stargazer(fgls_fixed4)

% Error: Unrecognized object type.
> class(fgls_fixed4)
[1] "pggls"      "panelmodel"
Helix123
  • 3,502
  • 2
  • 16
  • 36
Mario GS
  • 859
  • 8
  • 22
  • Try with `?"stargazer models"` and look for `pggls` – Marco Sandri May 04 '17 at 11:36
  • 1
    Obviously, that type of models is not supported by `stargazer`. – Helix123 May 04 '17 at 11:56
  • Because of that, I'm writing the question. Is there another way to turn it into latex? – Mario GS May 04 '17 at 12:03
  • It is fairly easy to create custom models for `texreg` by adjusting an existing method for a relatively similar model. I would imagine `stargazer` has similar functionality? – coffeinjunky May 04 '17 at 12:11
  • I'm not aware of texreg or the process of making custom models, I will read more about it. If you can point me to an example of how to do it, I will appreciate it. – Mario GS May 04 '17 at 13:17
  • Well, for `texreg`, have a look at the vignette. It is quite well-explained how to define a custom model-class there. See https://cran.r-project.org/web/packages/texreg/vignettes/texreg.pdf – coffeinjunky May 04 '17 at 19:08

1 Answers1

1

I found a solution here: http://tarohmaru.web.fc2.com/R/ExerciseDiagnostics.html You need to run this code below before running texreg. It works on my end. Use texreg after running the code below.


    extract.pggls <- function (model, include.rsquared = TRUE, include.adjrs = TRUE, 
        include.nobs = TRUE, ...) 
    {
s <- summary(model, ...)
coefficient.names <- rownames(s$CoefTable)
coefficients <- s$CoefTable[, 1]
standard.errors <- s$CoefTable[, 2]
significance <- s$CoefTable[, 4]
rs <- s$rsqr
n <- length(s$resid)
gof <- numeric()
gof.names <- character()
gof.decimal <- logical()
if (include.rsquared == TRUE) {
    gof <- c(gof, rs)
    gof.names <- c(gof.names, "R$^2$")
    gof.decimal <- c(gof.decimal, TRUE)
}
if (include.nobs == TRUE) {
    gof <- c(gof, n)
    gof.names <- c(gof.names, "Num. obs.")
    gof.decimal <- c(gof.decimal, FALSE)
}
tr <- createTexreg(coef.names = coefficient.names, coef = coefficients, 
    se = standard.errors, pvalues = significance, gof.names = gof.names, 
    gof = gof, gof.decimal = gof.decimal)
return(tr)
    }

    setMethod("extract", signature = className("pggls", "plm"),
      definition = extract.pggls)
Haeyong
  • 19
  • 1
  • texreg(extract.pggls(fgls_fixed4) would provide the summary in editable latex format. Since stargazer does not support pggls object, we can use above function to extract the output – chris jude Apr 05 '23 at 13:27