Learn R Programming

BMisc (version 1.4.6)

subsample: Subsample of Observations from Panel Data

Description

returns a subsample of a panel data set; in particular drops all observations that are not in keepids. If it is not set, randomly keeps nkeep observations.

Usage

subsample(dta, idname, tname, keepids = NULL, nkeep = NULL)

Value

a data.frame that contains a subsample of dta

Arguments

dta

a data.frame which is a balanced panel

idname

the name of the id variable

tname

the name of the time variable

keepids

which ids to keep

nkeep

how many ids to keep (only used if keepids is not set); the default is the number of unique ids

Examples

Run this code
 if(!requireNamespace("plm")) {
  if(interactive() || is.na(Sys.getenv("_R_CHECK_PACKAGE_NAME_", NA))) {
    stop("package 'plm' is required for this example")
  } else q() }
data("LaborSupply", package="plm")
nrow(LaborSupply)
unique(LaborSupply$year)
ss <- subsample(LaborSupply, "id", "year", nkeep=100)
nrow(ss)

Run the code above in your browser using DataLab