Learn R Programming

plm (version 1.5-12)

pdata.frame: data.frame for panel data

Description

An object of this class is a data.frame with an attribute that describes its time and individual dimensions.

Usage

pdata.frame(x, index = NULL, drop.index = FALSE, row.names = TRUE) "["(x, i, j, drop = TRUE) "[["(x, y) "$"(x, y) "print"(x, ...) "as.data.frame"(x, row.names = NULL, optional = FALSE, ...)

Arguments

x
a data.frame for the pdata.frame function and a pdata.frame for the methods,
i
see Extract,
j
see Extract,
y
one of the columns of the data.frame,
index
this argument indicates the individual and time indexes. See details,
drop
see Extract,
drop.index
logical, indicates whether the indexes are to be excluded from the resulting pdata.frame,
optional
see as.data.frame,
row.names
NULL or logical, indicates whether ``fancy'' row names (a combination of individual index and time index) are to be added to the returned (p)data.frame (NULL and FALSE have the same meaning),
...
further arguments

Value

a pdata.frame object: this is a data.frame with an index attribute which is a data.frame with two variables, the individual and the time indexes.

Details

The index argument indicates the dimensions of the panel. It can be:
  • a character string which is the name of the individual index variable, in this case a new variable called ``time'' which contains the time index is added,
  • an integer, the number of individuals in case of balanced panel, in this case two new variables ``time'' and ``id'' which contain the individual and the time indexes are added,
  • a vector of two character strings which contains the names of the individual and of the time indexes.

The index attribute is a data.frame which contains the individual and the time indexes. The "[[" and "$" extract a series from the pdata.frame. The "index" attribute is then added to the series and a class attribute "pseries" is added. The "[" method behaves as for data.frame, except that the extraction is also applied to the index attribute. as.data.frame removes the index from the pdata.frame and adds it to every series.

Examples

Run this code
data("Wages", package = "plm")
Wag <- pdata.frame(Wages, 595)

# Gasoline contains two variables which are individual and time indexes
data("Gasoline", package = "plm")
Gas <- pdata.frame(Gasoline, c("country","year"), drop = TRUE)

# Hedonic is an unbalanced panel, townid is the individual index
data("Hedonic", package="plm")
Hed <- pdata.frame(Hedonic, "townid", row.names = FALSE)

Run the code above in your browser using DataLab