Learn R Programming

eventstudies (version 1.2.2)

phys2eventtime: Convert data from physical to event time

Description

‘phys2eventtime’ is used to convert data from physical to event time using information on events identified by the user.

Usage

phys2eventtime(z, events, width = 10)

Arguments

z

an object of class zoo or xts containing data to be converted into event time.

events

‘data.frame’ containing event identifiers. See ‘Details’.

width

an ‘integer’ specifying the event window within which data should be available to consider the outcome a 'success'. See ‘Details’.

Value

Returns a ‘list’ of two elements:

z.e

a zoo object containing data of successful events indexed with event time; “NULL” if there are no “success” in “outcomes”. ‘colnames’ of z.e are event numbers: row numbers of “events”.

outcomes

a character vector with outcome definition for each event.

success: the successful use of an event. wdatamissing: when there are NAs within the event window. wrongspan: when event time cannot be mapped to physical time in “z” because event window is outside ‘index(z)’. unitmissing: when the unit (a column) is missing in “z”.

Details

“events” object contains two columns: “name” consists of names of the event, and “when” is the respective event time. ‘class’ of ‘index’ of “z” and “when” should be same and one of the ‘date-time’ or ‘Date’ classes.

If an event date does not lie within the index of “z”, the function approximates to the nearest previous time using findInterval. Note that ‘findInterval’ assumes the index of ‘z’ is non-decreasing.

The argument “width” provides the user with an option to define successful events as those that have data within a window around the event. Window is defined as (-width, +width]. If “width” is 10 periods, those events with ‘NA’ within 10 periods before and after the event will be classified as “wdatamissing”, otherwise, the event “outcome” will be classified as “success”.

Currently this function requires “z” to have at least one column. It relies on ‘colnames’ of “z” for the series names, and matches it with the “events” object. One can use drop = FALSE with ‘[’ to achieve a single-column object.

See Also

findInterval

Examples

Run this code
# NOT RUN {
data(StockPriceReturns)
data(SplitDates)

result <- phys2eventtime(z = StockPriceReturns,
			 events = SplitDates,
			 width = 5)
print(result$z.e[as.character(-4:5)])
print(SplitDates[result$outcomes == "success", ])
# }

Run the code above in your browser using DataLab