Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btscs() sometimes fails when event data are followed by years without observations #1

Open
svmiller opened this issue Jun 4, 2021 · 1 comment

Comments

@svmiller
Copy link

svmiller commented Jun 4, 2021

Hi Dave,

I hope you don't mind me reaching out via Github issue regarding your btscs() function. I use it quite a lot in my {stevemisc} package and figuring out how to disentangle this function got me into the R package development world. I thank you for it.

I wanted to reach out with an inquiry regarding your btscs() function since it (and my wrapper for it) are running into the same problem. I don't know how best to describe it, but simply: if I have a state-year data frame from 1946 to 2020, but only conflict data from 1946 to 2019, this function will fail to calculate the peace years/spells altogether.

Here is a proof of concept using the aclp data. The data end in 1990. If we were to calculate the spells, this function does just fine. If we were to add another year (1991) for those states still active in 1990, the function fails with the message "missing value where TRUE/FALSE needed". If, say, the spells were needed for adjusting temporal dependence for the outcome (as is usually the case), the data (in this case and in the trouble I'm encountering in my data) should be subset to just the relevant event years and it would be fine. But, I'm wondering if there's a way to make this function more flexible so that it might see the all-NAs after the last year of events and still work.

library(DAMisc)
library(tidyverse)

data(aclp)
# convert to tibble for convenience
aclp <- as_tibble(aclp)

# Add 1991, but no event "democ" observations
aclp %>%
  filter(year == 1990) %>%
  distinct(cname,country) %>%
  mutate(year = 1991) %>%
  bind_rows(., aclp) %>%
  arrange(country, year) -> aclp2

succeeds <- btscs(aclp, "democ", "year", "country")
fails <- btscs(aclp2, "democ", "year", "country")

Any input appreciated, and thank you again.

@svmiller
Copy link
Author

svmiller commented Jun 4, 2021

Writing with a follow-up since I realize I'm not that smart and should have checked this before submitting the issue, but the pad.ts = TRUE argument would nominally fix this. Maybe I had just misunderstood what that argument was doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant