pan_dummy_dates: Create dummy panel from start and end dates.

Description Usage Arguments Details Value Examples

View source: R/pan_dummy_dates.R

Description

Create a dummy panel over time from data on events with start and end dates. Codes any month, quarter, or year (depending on freq) during which an event takes place is dummy coded as 1.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
pan_dummy_dates(
  x,
  g,
  col_start,
  col_end,
  freq = c("m", "q", "y"),
  t_name,
  d_name,
  alt_end = NULL
)

Arguments

x

A data.frame with events' start and end dates per row.

g

An atomic character, name of the panel group variable in x.

col_start

Atomic character, name of the column of start dates in x. As of now, must be of type zoo::yearmon.

col_end

Atomic character, name of the column of end dates in x. As of now, must be of type zoo::yearmon.

freq

Atomic character, the frequency of the resulting panel. One of m (monthly), q (quarterly), y (yearly).

t_name

An atomic character, name of the panel time variable in the resulting data.frame.

d_name

An atomic character, name of the panel group variable in the resulting data.frame.

alt_end

Atomic numeric, alternative last period for resulting panel. If NULL, the resulting panel extends the last date supplied in col_end.

Details

Currently supported are yearly, quaterly, and monthly data.

Value

A data.frame or data.table depending on the input.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
x <- data.frame(
  grp = rep(c("A", "B"), each = 3),
  start_month = zoo::as.yearmon(
    c("2000-01-01", "2002-05-01", "2003-12-01", "2000-06-01", "2003-01-01",
      "2006-01-01")
    ),
  end_month = zoo::as.yearmon(
    c("2000-05-01", "2003-02-01", "2004-03-01", "2001-06-01", "2005-07-01",
      "2008-01-01")
    )
)

pdt <- pan_dummy_dates(
  x, "grp", "start_month", "end_month", "m", "yearm", "dummy",
  zoo::as.yearmon("2008-12-01")
)

thorepet/thoremisc documentation built on Oct. 8, 2021, 7:48 a.m.