This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| decay <- function(yvar, d) { | |
| # yvar: a binary variable | |
| # d: number of periods | |
| # returns: the cumulative sum of yvar at each point | |
| # where each addition to the count decays away after d periods | |
| yvar[is.na(yvar)] <- 0 | |
| run <- cumsum(yvar) | |
| tvar <- seq_along(yvar) | |
| run <- 0 | |
| sum <- 0 |
NewerOlder