Learn R Programming

plm (version 1.2-0)

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)
## S3 method for class 'pdata.frame':
[(x, i, j, drop = TRUE)
## S3 method for class 'pdata.frame':
[[(x, y)
## S3 method for class 'pdata.frame':
$(x, y)
## S3 method for class 'pdata.frame':
print(x, ...)
## S3 method for class 'pdata.frame':
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
should the indexes be removed from the data.frame ?
optional
see as.data.frame
row.names
should ``fancy'' row names be computed ?
...
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 serie from the pdata.frame. The "index" attribute is then added to the serie and a class attribute "pserie" is added. The "[" method behaves as for data.frame, except that the extraction is also applied to the index attribute. The as.data.frame remove the index from the pdata.frame and add 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