This function checks for each individual if its associated time periods are consecutive (no "gaps" in time dimension per individual)
is.pconsecutive(x, ...) ## Default S3 method: is.pconsecutive(x, id, time, na.rm.tindex = FALSE, ...) ## S3 method for class 'data.frame' is.pconsecutive(x, index = NULL, na.rm.tindex = FALSE, ...) ## S3 method for class 'pseries' is.pconsecutive(x, na.rm.tindex = FALSE, ...) ## S3 method for class 'pdata.frame' is.pconsecutive(x, na.rm.tindex = FALSE, ...) ## S3 method for class 'panelmodel' is.pconsecutive(x, na.rm.tindex = FALSE, ...)
usually, an object of class
only relevant for default method: vectors specifying the id and time dimensions, i. e., a sequence of individual and time identifiers, each as stacked time series,
logical indicating whether any
only relevant for
(p)data.frame, pseries and estimated panelmodel objects can be tested if
their time periods are consecutive per individual. For evaluation of
consecutiveness, the time dimension is interpreted to be numeric, and the
data are tested for being a regularly spaced sequence with distance 1
between the time periods for each individual (for each individual the time
dimension can be interpreted as sequence t, t+1, t+2, ... where t is an
integer). As such, the "numerical content" of the time index variable is
considered for consecutiveness, not the "physical position" of the various
observations for an individuals in the (p)data.frame/pseries (it is not
about "neighbouring" rows). If the object to be evaluated is a pseries or a
pdata.frame, the time index is coerced from factor via as.character to
numeric, i.e., the series
evaluated for gaps.
The default method also works for argument
x being an arbitrary
vector (see Examples), provided one can supply arguments
time, which need to ordered as stacked time series. As only
time are really necessary for the default method to
evaluate the consecutiveness,
x = NULL is also possible. However, if
x is also supplied, additional input checking for equality
of the lengths of
time is performed, which is
For the data.frame interface, the data is ordered in the appropriate way (stacked time series) before the consecutiveness is evaluated. For the pdata.frame and pseries interface, ordering is not performed because both data types are already ordered in the appropriate way when created.
Note: Only the presence of the time period itself in the object is tested,
not if there are any other variables.
NA values in individual index
are not examined but silently dropped - In this case, it is not clear which
individual is meant by id value
NA, thus no statement about
consecutiveness of time periods for those "
logical vector (names are those of the
individuals). The i-th element of the returned vector
corresponds to the i-th individual. The values of the i-th
element can be:
if the i-th individual has consecutive time periods,
if the i-th individual has non-consecutive time periods,
if there are any NA values in time index of
the i-th the individual; see also argument
make.pconsecutive() to make data consecutive
(and, as an option, balanced at the same time) and
make.pbalanced() to make data balanced.
pdim() to check the dimensions of a 'pdata.frame'
(and other objects),
pvar() to check for individual
and time variation of a 'pdata.frame' (and other objects),
lag() for lagged (and leading) values of a
for class 'panelmodel' see
data("Grunfeld", package = "plm") is.pconsecutive(Grunfeld) is.pconsecutive(Grunfeld, index=c("firm", "year")) # delete 2nd row (2nd time period for first individual) # -> non consecutive Grunfeld_missing_period <- Grunfeld[-2, ] is.pconsecutive(Grunfeld_missing_period) all(is.pconsecutive(Grunfeld_missing_period)) # FALSE # delete rows 1 and 2 (1st and 2nd time period for first individual) # -> consecutive Grunfeld_missing_period_other <- Grunfeld[-c(1,2), ] is.pconsecutive(Grunfeld_missing_period_other) # all TRUE # delete year 1937 (3rd period) for _all_ individuals Grunfeld_wo_1937 <- Grunfeld[Grunfeld$year != 1937, ] is.pconsecutive(Grunfeld_wo_1937) # all FALSE # pdata.frame interface pGrunfeld <- pdata.frame(Grunfeld) pGrunfeld_missing_period <- pdata.frame(Grunfeld_missing_period) is.pconsecutive(pGrunfeld) # all TRUE is.pconsecutive(pGrunfeld_missing_period) # first FALSE, others TRUE # panelmodel interface (first, estimate some models) mod_pGrunfeld <- plm(inv ~ value + capital, data = Grunfeld) mod_pGrunfeld_missing_period <- plm(inv ~ value + capital, data = Grunfeld_missing_period) is.pconsecutive(mod_pGrunfeld) is.pconsecutive(mod_pGrunfeld_missing_period) nobs(mod_pGrunfeld) # 200 nobs(mod_pGrunfeld_missing_period) # 199 # pseries interface pinv <- pGrunfeld$inv pinv_missing_period <- pGrunfeld_missing_period$inv is.pconsecutive(pinv) is.pconsecutive(pinv_missing_period) # default method for arbitrary vectors or NULL inv <- Grunfeld$inv inv_missing_period <- Grunfeld_missing_period$inv is.pconsecutive(inv, id = Grunfeld$firm, time = Grunfeld$year) is.pconsecutive(inv_missing_period, id = Grunfeld_missing_period$firm, time = Grunfeld_missing_period$year) # (not run) demonstrate mismatch lengths of x, id, time # is.pconsecutive(x = inv_missing_period, id = Grunfeld$firm, time = Grunfeld$year) # only id and time are needed for evaluation is.pconsecutive(NULL, id = Grunfeld$firm, time = Grunfeld$year)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.