collapse: collapses a data set by variables using arbitrary aggregation...

Description Usage Arguments Value Examples

View source: R/collapse.r

Description

collapse a data set to produce summary statistics possibly by a set of variables as in the Stata code: collapse (fun1) var1 (fun2) var2, by(byvar1 byvar2). But this function is more flexible than the Stata version because any arbitrary function can be used in collapse not just traditional aggregation functions.

Usage

1
collapse(values, byvar)

Arguments

values

an argument with the form "fun1(var1) fun2(var2) fun3(var3,var4)" describe the aggregations to be performed where fun1, fun2, fun3 are most likely aggregation functions like "sum", "mean", "max", "median", etc. But the function could be anything that returns a scalar.

byvar

a variable list giving the variables to collapse by. The resulting dataset will have as many rows as there are unique levels of the byvar variable list.

Value

returns NULL, invisibly

Examples

1
2
3
4
5
6
library(plm)
data(Produc)
use(Produc, clear=TRUE)
listif()
collapse("sum(emp)","year")
listif()

genvar documentation built on Jan. 21, 2020, 9:07 a.m.