Authors: Hongyu Mou (UCLA); Licheng Liu (MIT); Yiqing Xu (Stanford)
Date: June 17, 2024
Repos: Github (1.1.18) CRAN (1.1.18)
Examples: R code used in the tutorial can be downloaded from here.
panelView visualizes panel data. It has four main functionalities:
- it plots treatment status and missing values in a panel dataset;
- it plots the temporal dynamics of an outcome variable (or any variable) in a panel dataset;
- it visualizes bivariate relationships of two variables by unit or in aggregate;
- NEW: it visualizes the network structure of panel data as a bipartite graph, identifying singletons and connected components (inspired by Correia 2016).
| Treatment Status | Outcome Dynamics |
|---|---|
![]() |
![]() |
U.S. voter registration policies (turnout data). Left: treatment adoption pattern across states. Right: turnout dynamics over time.
Visualize the bipartite graph structure of your panel's observation matrix. Units and time periods become differently shaped nodes (filled circles vs hollow squares); edges represent observations. Light blue hulls wrap connected components. Singletons (degree-1 nodes) appear as smaller peripheral nodes — these cannot contribute to fixed-effects identification (Correia 2016, Section 3.4).
CEO-Firm Network![]() |
Singletons & Components![]() |
Sparse Panel![]() |
k-partite (3-way FE)![]() |
Balanced Panel![]() |
Large Panel![]() |
library(panelView)
# Basic bipartite network (unit × time)
panelview(turnout ~ policy_edr, data = turnout,
index = c("abb", "year"), type = "network")
# k-partite (unit × time × region)
panelview(data = mydata, index = c("unit", "time"),
fe = "region", type = "network")
# Returns igraph object, singletons, and component info
result <- panelview(data = mydata, index = c("unit", "time"),
type = "network")
result$singletons # data.frame of degree-1 nodes
result$components # connected component sizes
result$graph # igraph object for further analysisRequires igraph (in Suggests — install with install.packages("igraph")).
You can install the up-to-date development version from GitHub:
# if not already installed
install.packages('devtools', repos = 'http://cran.us.r-project.org')
# note: "V" is capitalized
devtools::install_github('xuyiqing/panelView') You can also install the panelView package from CRAN:
install.packages('panelView') If you encounter an installation/execution error, please remove the old package and reinstall panelView.
remove.packages('panelView')
# or
remove.packages('panelview') # package name "panelview" no longer in useFor example, plot treatment status in a panel dataset:
library(panelView)
data(panelView)
panelview(turnout ~ policy_edr + policy_mail_in + policy_motor,
data = turnout, index = c("abb","year"),
xlab = "Year", ylab = "State")Note that “V” in the package name is capitalized while “v” in the function name is not—to be consistent with the Stata version.
See the tutorial page for more details.
For a paper version of the tutorial, see Mou, Liu & Xu (2023): “Panel Data Visualization in R (panelView) and Stata (panelview).”
Please report bugs to yiqingxu [at] stanford.edu with your sample code and data file. Much appreciated!







