Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Syntax help - events in intervals

    Hi,
    I am attempting to count admissions that have occurred for an ID variable (IDV) that occur (ADate) between two dates ; DDate and M.
    M is a date that is created as occurring 365 days before DDate. I have used the following syntax after reading Stata tip 51 but continue to receive error - invalid syntax r(198) -- please help

    gen n_admit_12m = .
    local N =_N
    quietly forval i = 1/‘N’ {
    count if IDV == IDV[‘i’]& ///
    inrange(ADate[‘i’] – M, 1, DDate)
    replace n_admit_12m = r(N) in 'i'
    }
    Sample data is:

    IDV ADATE DDATE M
    2 5/6/2017 7/6/2017 5/6/2016
    2 8/8/2016 12/8/2016 8/8/2015
    2 10/10/2016 24/10/2016 10/10/2015
    3 24/12/2018 05/01/2019 24/12/2017
    With thanks
Working...
X