如何将stargazer / xtable与plm包中的pggls对象一起使用?

时间:2017-05-04 10:58:21

标签: r xtable stargazer plm

我正在尝试使用xtablestargazer将某些回归的输出转换为乳胶。我之前从未遇到过问题,多次回归的结果整齐地排列在乳胶表中。我正在使用Fixed Effects FGLS。因此,我使用命令pggls而不是plm(来自包plm)。显然,使用该命令创建了这种类型的对象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"

1 个答案:

答案 0 :(得分:1)

我在这里找到了解决方案:http://tarohmaru.web.fc2.com/R/ExerciseDiagnostics.html 在运行texreg之前,您需要在下面运行此代码。它对我有效。运行以下代码后,使用texreg。


    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)