Skip to contents

panglm fits regression models for panel data (pooled, fixed effects, random effects and the estimators built on them) for the outcomes and designs of applied health econometrics, from one formula interface and one set of post-estimation tools (robust and cluster covariances, partial effects, specification tests, prediction and tidy output).

Installation

# release from CRAN
install.packages("panglm")

# development version from GitHub
# install.packages("remotes")
remotes::install_github("ielbadisy/panglm")

What it fits

Task Function
Continuous, binary, count, ordered, positive, bounded and censored outcomes (pooled, within, between, random effects) panglm()
Random slopes panglm(model = "random", random = ~ x)
Costs with zeros (two-part model) twopart()
Counts with structural zeros panhurdle()
Difference-in-differences and event studies did(), eventstudy()
Staggered adoption attgt(), etwfe()
Instrumental variables and Hausman-Taylor paniv()
Dynamic panels (difference and system GMM) pangmm()
Sample selection panselect()
Quantile regression panqr()
Latent classes panfmm(), panfmmselect()
Specification tests panhausman(), pandispersiontest(), jointtest(), lineartest()

Numerical accuracy is documented in the validation article.

Example

Exacerbation counts of 60 COPD patients over five visits, with a random-effects Poisson model, cluster-robust standard errors, a Hausman test against fixed effects and average partial effects:

library(panglm)
data(copd)

re <- panglm(exacerbations ~ crp + treatment + age, data = copd,
             index = c("id", "visit"), model = "random",
             family = "poisson", vcov = "cluster")
summary(re)
#> 
#> Call:
#> panglm(formula = exacerbations ~ crp + treatment + age, data = copd, 
#>     index = c("id", "visit"), model = "random", family = "poisson", 
#>     vcov = "cluster")
#> 
#> Family: poisson  Link: log  Model: random  Effect: individual 
#> N = 300  groups = 60  vcov: cluster 
#> 
#> Coefficients:
#>              Estimate Std. Error z value Pr(>|z|)    
#> (Intercept) -1.840104   0.525745  -3.500 0.000465 ***
#> crp          0.040731   0.020385   1.998 0.045711 *  
#> treatment   -0.309009   0.168576  -1.833 0.066795 .  
#> age          0.037769   0.007959   4.745 2.08e-06 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Log-likelihood: -517.8 
#> Dispersion parameter: 4.215 
#> Residual df: 295  Iterations: 4

fe <- panglm(exacerbations ~ crp, data = copd,
             index = c("id", "visit"), model = "within", family = "poisson")
panhausman(fe, re)
#> 
#>  Hausman specification test (fixed vs. random effects)
#> 
#> chisq = 3.211 , df = 1 , p-value = 0.07312 
#> alternative hypothesis: one model is inconsistent

partialeffects(re)
#> 
#> Average partial effects
#> Delta-method standard errors, vcov: cluster 
#> 
#>       term contrast estimate std.error statistic   p.value  conf.low conf.high
#>        crp    dY/dX  0.08660   0.04280     2.023 0.0430500  0.002708   0.17050
#>  treatment    1 - 0 -0.63650   0.34350    -1.853 0.0638500 -1.310000   0.03667
#>        age    dY/dX  0.08031   0.01837     4.372 0.0000123  0.044310   0.11630