This function checks for each variable of a panel if it varies cross-sectionally and over time.
pvar(x, ...)
# S3 method for class 'matrix'
pvar(x, index = NULL, ...)
# S3 method for class 'data.frame'
pvar(x, index = NULL, ...)
# S3 method for class 'pdata.frame'
pvar(x, ...)
# S3 method for class 'pseries'
pvar(x, ...)
# S3 method for class 'pvar'
print(x, ...)a (p)data.frame or a matrix,
further arguments.
see pdata.frame(),
An object of class pvar containing the following
elements:
a logical vector with TRUE values if the
variable has individual variation, FALSE if not,
a logical vector with TRUE values if the
variable has time variation, FALSE if not,
a logical vector with TRUE values if
the variable has at least one individual-time combination with all
NA values in the individual dimension for at least one time period,
FALSE if not,
a logical vector with TRUE values if
the variable has at least one individual-time combination with all
NA values in the time dimension for at least one individual,
FALSE if not.
For (p)data.frame and matrix interface: All-NA columns are removed
prior to calculation of variation due to coercing to pdata.frame
first.
pvar can be time consuming for “big” panels. As a fast alternative
collapse::varying() from package collapse could be used.
pdim() to check the dimensions of a 'pdata.frame' (and
other objects),
# Gasoline contains two variables which are individual and time
# indexes and are the first two variables
data("Gasoline", package = "plm")
pvar(Gasoline)
#> no time variation: country
#> no individual variation: year
# Hedonic is an unbalanced panel, townid is the individual index;
# the drop.index argument is passed to pdata.frame
data("Hedonic", package = "plm")
pvar(Hedonic, "townid", drop.index = TRUE)
#> no time variation: zn indus rad tax ptratio
# same using pdata.frame
Hed <- pdata.frame(Hedonic, "townid", drop.index = TRUE)
pvar(Hed)
#> no time variation: zn indus rad tax ptratio
# Gasoline with pvar's matrix interface
Gasoline_mat <- as.matrix(Gasoline)
pvar(Gasoline_mat)
#> no time variation: country
#> no individual variation: year
pvar(Gasoline_mat, index=c("country", "year"))
#> no time variation: country
#> no individual variation: year