# Interpreting plm output in R - number of observations used with very unbalanced panel

I'm running a fixed effects model with the plm function, and I'm looking for help interpreting an aspect of the output. If the output reads:

Call:
plm(formula = dependentvariable ~ independentvars, data = data, model = "within",
type="time")

Unbalanced Panel: n=176, T=1-2, N=211

Residuals :
Min. 1st Qu.  Median 3rd Qu.    Max.
-0.0654  0.0000  0.0000  0.0000  0.0654

Coefficients :
Estimate Std. Error t-value Pr(>|t|)
x1  -0.4219101  0.1662230 -2.5382 0.020054 *
x2  -0.0072536  0.0069678 -1.0410 0.310933
x3  -0.2221514  0.0574869 -3.8644 0.001044 **
x4   0.1118861  0.1247960  0.8966 0.381177

---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    0.18087
Residual Sum of Squares: 0.045841
R-Squared      :  0.74656
Adj. R-Squared :  0.067226
F-statistic: 5.08807 on 11 and 19 DF, p-value: 0.00099507


How do I know how many observations were used here, since my panel is extremely unbalanced? With both a small n and large N provided in the output, I'm confused about how to find how many observations were included.

## 1 Answer

Capital N gives you the total number of rows in your data which corresponds to the number of observations in the pooled model (option model="pooling" in the plm function).

Lowercase n gives you the unique number of observations (let's say groups or individuals). This corresponds to the number of dummies you add if you use the least square dummy variable estimator rather than the within estimator which is equivalent.

Capital $T$ shows how often an observation or an individual is observed (referring to the time dimension). $T=1-2$ means that there are both individuals which you observe only ones but also others are who are observed twice.

Since you have at most two periods, you can easily calculate that there are 35 individuals (211-176) who appear twice while information for 141 individuals is only available for one period. In general, you cannot cannot make this calculation if T>2 and you need further information.

Here is a dataset of soccer matches for three seasons in the German Bundesliga. In Germany, 18 teams play in a season 34 matches each. Each game appears here twice from the view of each team, "Home" refers to the home team. We use the fixed-effects within model to estimate the home advantage over time (relative to the first season in our sample) controlling for possible time/season effects.

rm(list=ls(all=TRUE))
library(plm)
bundesliga<-read.csv("https://drive.google.com/uc?export=download&id=0B70aDwYo0zuGRGxVV1p2MTlqaUk")
head(bundesliga)

> head(bundesliga)
Season Round                Team             Opponent Home Goals_Diff
1 2013/14     1      Bayern München Bor. Mönchengladbach    H          2
2 2013/14     1     1899 Hoffenheim       1. FC Nürnberg    H          0
3 2013/14     1 Bayer 04 Leverkusen          SC Freiburg    H          2
4 2013/14     1         Hannover 96        VfL Wolfsburg    H          2
5 2013/14     1         FC Augsburg    Borussia Dortmund    H         -4
6 2013/14     1          Hertha BSC  Eintracht Frankfurt    H          5

# Create time index
bundesliga$Index<-as.numeric(as.factor(bundesliga$Season))*100+bundesliga$Round # Declare panel data bl_panel<-pdata.frame(bundesliga,c("Team","Index")) # Run regression summary(plm(Goals_Diff~Home*Season,data=bl_panel,model = "within"))  Here are the results. Home advantage is strong and corresponds to a goal difference of 0.67 goals in the first season, no statistical differences in home advantage in the subsequent two seasons relative to the first season (and no discernible season effects):  > summary(plm(Goals_Diff~Home*Season,data=bl_panel,model = "within")) Oneway (individual) effect Within Model Call: plm(formula = Goals_Diff ~ Home * Season, data = bl_panel, model = "within") Unbalanced Panel: n=22, T=34-102, N=1836 Residuals : Min. 1st Qu. Median 3rd Qu. Max. -7.0400 -1.1700 -0.0185 1.1300 5.8300 Coefficients : Estimate Std. Error t-value Pr(>|t|) HomeH 0.673203 0.143947 4.6768 3.131e-06 *** Season2014/15 -0.132377 0.147800 -0.8957 0.3706 Season2015/16 -0.057980 0.149638 -0.3875 0.6985 HomeH:Season2014/15 0.169935 0.203571 0.8348 0.4040 HomeH:Season2015/16 -0.071895 0.203571 -0.3532 0.7240 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Total Sum of Squares: 5970.7 Residual Sum of Squares: 5735 R-Squared : 0.039484 Adj. R-Squared : 0.038904 F-statistic: 14.8726 on 5 and 1809 DF, p-value: 2.5075e-14  There are in total n=1,836 observations, 612 observations for each of the three seasons. We observe n=22 unique teams. T=34-102 means that there are teams which we observe only for one seasons or 34 matches while others appear in all three seasons (or 102 games). To assess how balanced your sample is, you can look at the number of seasons per team which shows you that most teams are observed for all three seasons. You can calculate$N=1836=(15*3+2*2+5*1)*34$and$n=15+2+5$. > table(table(bl_panel$Team)/34)
1  2  3
5  2 15

• As for a measure of (un)balancedness of the data, there is also the function punbalancedness() in the plm package which gives a single number. pdim gives more information about the number of time periods for each individual etc. Commented Aug 27, 2017 at 22:42