ps_spells: Create "spells" by cross-sectional unit, even more generally

ps_spellsR Documentation

Create "spells" by cross-sectional unit, even more generally


ps_spells() allows you to create spells ("peace years" in the international conflict context) between observations of some event. This will allow the researcher to better model temporal dependence in binary time-series cross-section ("BTSCS") models. The function is one of three in this package, and the contents of this function are partly ported from the add_duration() function in the spduration package. That function, unlike the other two I offer here, works much better where panels are decidedly imbalanced.


ps_spells(data, event, tvar, csunit, time_type = "year", ongoing = FALSE)



the data set with which you are working


some event (0, 1) for which you want spells


the time variable (e.g. a year)


the cross-sectional unit (e.g. a dyad or leader)


what type of time-unit are the data? Right now, this will only work with years but support for months and days are forthcoming. Don't do anything with this argument just yet.


If TRUE, successive 1s are considered ongoing events and treated as NA after the first 1. If FALSE, successive 1s are all treated as failures. Defaults to FALSE.


This function is derived from add_duration() in the spduration package. See documentation there for more information. I thank Andreas Beger for the blessing to port parts of it here.


ps_spells() takes a data frame and returns the data frame with a new variable named spell.


Andreas Beger, Steven V. Miller


Beger, Andreas, Daina Chiba, Daniel W. Hill, Jr, Nils W. Metternich, Shahryar Minhas and Michael D. Ward. 2018. “spduration: Split-Population and Duration (Cure) Regression.” R package version 0.17.1.


One <- ps_btscs(usa_mids, midongoing, year, dyad)
Two <- ps_spells(usa_mids, midongoing, year, dyad)
identical(One, Two)

stevemisc documentation built on April 12, 2022, 5:06 p.m.