Skip to content

statsclaw/example-panelView

Repository files navigation

panelView

Lifecycle: stable License: MIT downloads: CRAN

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.


Description

panelView visualizes panel data. It has four main functionalities:

  1. it plots treatment status and missing values in a panel dataset;
  2. it plots the temporal dynamics of an outcome variable (or any variable) in a panel dataset;
  3. it visualizes bivariate relationships of two variables by unit or in aggregate;
  4. NEW: it visualizes the network structure of panel data as a bipartite graph, identifying singletons and connected components (inspired by Correia 2016).

Example Output

Treatment Status Outcome Dynamics
Treatment Outcome

U.S. voter registration policies (turnout data). Left: treatment adoption pattern across states. Right: turnout dynamics over time.

Network Visualization (NEW)

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 analysis

Requires igraph (in Suggests — install with install.packages("igraph")).

Installation

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 use

Tutorial & Paper

For 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).”

Report bugs

Please report bugs to yiqingxu [at] stanford.edu with your sample code and data file. Much appreciated!

About

StatsClaw example: reproducing panelView network visualization from Correia (2016)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors