Panel Data Models with plm

stargazer2 supports plm model objects natively. It auto-detects the estimator type (FE, RE, Pooled OLS, FD, Between), displays fixed-effect and random-effect indicator rows, and reports the appropriate fit statistics from summary.plm.

Dataset and models

The Grunfeld dataset (10 US manufacturing firms, 1935–1954, balanced panel) is included with plm. We estimate four specifications of an investment equation:

library(plm)
data("Grunfeld", package = "plm")

m_pool <- plm(inv ~ value + capital, Grunfeld,
              index = c("firm", "year"), model = "pooling")

m_fe   <- plm(inv ~ value + capital, Grunfeld,
              index = c("firm", "year"), model = "within")

m_twfe <- plm(inv ~ value + capital, Grunfeld,
              index = c("firm", "year"), model = "within", effect = "twoways")

m_re   <- plm(inv ~ value + capital, Grunfeld,
              index = c("firm", "year"), model = "random")

Default output

A bare call produces a complete table. stargazer2 reads the model type from each plm object and builds indicator rows for the fixed and random effects present across all columns:

stargazer(m_pool, m_fe, m_twfe, m_re, type = "text")
================================================================================================================
                                                        Dependent variable:                                     
                    --------------------------------------------------------------------------------------------
                                                                inv                                             
                           Pooled OLS                   FE                       FE                   RE        
                              (1)                      (2)                      (3)                   (4)       
----------------------------------------------------------------------------------------------------------------
value                       0.116***                 0.110***                 0.118***             0.110***     
                            (0.006)                  (0.012)                  (0.014)               (0.010)     
                                                                                                                
capital                     0.231***                 0.310***                 0.358***             0.308***     
                            (0.025)                  (0.017)                  (0.023)               (0.017)     
                                                                                                                
Constant                   -42.714***                                                              -57.834**    
                            (9.512)                                                                (28.899)     
                                                                                                                
----------------------------------------------------------------------------------------------------------------
Firm FE                        No                      Yes                      Yes                   No        
Year FE                        No                       No                      Yes                   No        
Firm RE                        No                       No                       No                   Yes       
----------------------------------------------------------------------------------------------------------------
Observations                  200                      200                      200                   200       
R2                           0.812                    0.767                    0.720                 0.770      
Adjusted R2                  0.811                    0.753                    0.670                 0.767      
Residual Std. Error    94.408 (df = 197)        52.768 (df = 188)        51.725 (df = 169)     52.786 (df = 197)
F Statistic         426.576*** (df = 2; 197) 309.014*** (df = 2; 188) 217.442*** (df = 2; 169)    657.674***    
================================================================================================================
Note:               OLS standard errors; *p<0.1; **p<0.05; ***p<0.01 

Things to notice:

Robust standard errors

plm ships its own vcov functions. Pass them inline through the vcov argument. vcovHC(..., method = "arellano") gives standard errors clustered by the individual unit, the most common choice for FE models:

stargazer(m_fe, m_twfe,
          type = "text",
          vcov = list(vcovHC(m_fe,   method = "arellano"),
                      vcovHC(m_twfe, method = "arellano")))
=====================================================================
                                   Dependent variable:               
                    -------------------------------------------------
                                           inv                       
                              (1)                      (2)           
---------------------------------------------------------------------
value                       0.110***                 0.118***        
                            (0.014)                  (0.010)         
                                                                     
capital                     0.310***                 0.358***        
                            (0.050)                  (0.043)         
                                                                     
---------------------------------------------------------------------
Firm FE                       Yes                      Yes           
Year FE                        No                      Yes           
---------------------------------------------------------------------
Observations                  200                      200           
R2                           0.767                    0.720          
Adjusted R2                  0.753                    0.670          
Residual Std. Error    52.768 (df = 188)        51.725 (df = 169)    
F Statistic         309.014*** (df = 2; 188) 217.442*** (df = 2; 169)
=====================================================================
Note:               Arellano cluster-robust standard errors; *p<0.1;
                     **p<0.05; ***p<0.01 

stargazer2 auto-detects the SE type from the inline call and labels the table note accordingly. For replication of Stata’s vce(cluster id) results, sandwich::vcovCL is preferable as it applies the G/(G−1) small-sample correction that Stata uses; plm::vcovHC applies a heteroskedasticity-style n/(n−k) correction instead.

Driscoll-Kraay standard errors

For panels with cross-sectional dependence or long time dimensions, Driscoll-Kraay (spatial HAC) standard errors are a common alternative. plm::vcovSCC implements this estimator:

stargazer(m_fe, m_twfe,
          type = "text",
          vcov = list(vcovSCC(m_fe),
                      vcovSCC(m_twfe)))
=====================================================================
                                   Dependent variable:               
                    -------------------------------------------------
                                           inv                       
                              (1)                      (2)           
---------------------------------------------------------------------
value                       0.110***                 0.118***        
                            (0.018)                  (0.020)         
                                                                     
capital                     0.310***                 0.358***        
                            (0.035)                  (0.056)         
                                                                     
---------------------------------------------------------------------
Firm FE                       Yes                      Yes           
Year FE                        No                      Yes           
---------------------------------------------------------------------
Observations                  200                      200           
R2                           0.767                    0.720          
Adjusted R2                  0.753                    0.670          
Residual Std. Error    52.768 (df = 188)        51.725 (df = 169)    
F Statistic         309.014*** (df = 2; 188) 217.442*** (df = 2; 169)
=====================================================================
Note:               Driscoll-Kraay standard errors; *p<0.1; **p<0.05;
                     ***p<0.01 

Adding formatting options

Once the defaults look right, labels can be added. The LaTeX source below sets a title and cross-reference label, renames the dependent variable and covariates, and assigns custom column headers:

stargazer(m_pool, m_fe, m_twfe, m_re,
          type             = "latex",
          title            = "Investment Equations: Grunfeld Panel Data",
          label            = "tab:grunfeld",
          dep.var.labels   = "Investment",
          covariate.labels = c("Market Value", "Capital Stock"),
          column.labels    = c("Pooled OLS", "FE", "Two-way FE", "RE"))
% Table produced by stargazer2 v.0.1.0 by Tom Zylkin, University of Richmond (tzylkin@richmond.edu)
% Original stargazer package by: Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
%   R package version 5.2.3. https://CRAN.R-project.org/package=stargazer

\begin{table}[!htbp] \centering 
  \caption{Investment Equations: Grunfeld Panel Data} 
  \label{tab:grunfeld} 
\begin{tabular}{@{\extracolsep{5pt}}lcccc} 
\hline 
 & \multicolumn{4}{c}{\textit{Dependent variable:}} \\ 
 & \multicolumn{4}{c}{Investment} \\ 
 & Pooled OLS & FE & Two-way FE & RE \\ 
 & (1) & (2) & (3) & (4)\\ 
\hline 
 Market Value & 0.116$^{***}$ & 0.110$^{***}$ & 0.118$^{***}$ & 0.110$^{***}$ \\ 
  & (0.006) & (0.012) & (0.014) & (0.010) \\ 
 Capital Stock & 0.231$^{***}$ & 0.310$^{***}$ & 0.358$^{***}$ & 0.308$^{***}$ \\ 
  & (0.025) & (0.017) & (0.023) & (0.017) \\ 
 Constant & $-$42.714$^{***}$ &  &  & $-$57.834$^{**}$ \\ 
  & (9.512) &  &  & (28.899) \\ 
\hline 
Firm FE & No & Yes & Yes & No \\ 
Year FE & No & No & Yes & No \\ 
Firm RE & No & No & No & Yes \\ 
\hline 
Observations & 200 & 200 & 200 & 200 \\ 
R$^{2}$ & 0.812 & 0.767 & 0.720 & 0.770 \\ 
Adjusted R$^{2}$ & 0.811 & 0.753 & 0.670 & 0.767 \\ 
Residual Std. Error & 94.408 (df = 197) & 52.768 (df = 188) & 51.725 (df = 169) & 52.786 (df = 197) \\ 
F Statistic & 426.576$^{***}$ (df = 2; 197) & 309.014$^{***}$ (df = 2; 188) & 217.442$^{***}$ (df = 2; 169) & 657.674$^{***}$ \\ 
\hline 
\hline 
\multicolumn{5}{p{\linewidth}}{\textit{Note:} OLS standard errors; $^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01.} \\ 
\end{tabular} 
\end{table}