Hello,

I am using Stata 16.1 MP.

I wish to create a monthly exposure variable. This would capture the number of days included within each month (i.e. April = 30, May = 31, June =30, etc.).

Two points I am having difficulty with.

1. How can this be calculated across different years (i.e. to reflect differences in days for February dependent on whether or not it is a leap year)?

2. To allow provision for left and right censoring for each individual. I.e. the days within a month may be less if the individual either commenced or withdrew participation at a date other than the first or last day of the month. These dates are reflected by the date_start and date_end variables below.

The rationale is to allow a monthly incidence rate to be reported that is reflective of the variable days included in each month as a result of censoring and month length. This could be reported at an individual level, then collapsed across different categories (e.g. gender, cat1, cat2) or for the whole sample.

A small subset of the data are provided below:


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(id date_start date_end age) long(sex cat1 cat2) float injury
 1 21761 22127      20.5 1 1 3  5
 2 21761 22127      23.7 1 1 3  1
 3 21639 22005      28.2 1 2 1  1
 4 21710 21945      26.1 1 1 2  7
 5 21639 22005        18 1 2 1  1
 6 21639 22005 18.400002 1 1 1  1
 7 21761 22127      34.4 1 1 3  9
 8 21580 21945        20 1 2 2  2
 9 21639 22005 18.800001 1 1 1  0
10 21639 22005      19.8 1 2 1  4
11 21639 22005      16.4 1 2 1  8
12 21761 22127      17.9 1 1 3  8
13 21639 22005      24.7 1 2 1  4
14 21639 22005      17.1 1 1 1  4
15 21761 22127      30.3 1 1 3  3
16 21639 22005      20.2 1 2 1  7
17 21639 22005        18 1 2 1  7
18 21639 22005      19.3 1 2 1  6
19 21580 21945      21.8 1 1 2  2
20 21639 22005        20 1 1 1  1
21 21639 22005      20.3 1 2 1  6
22 21580 21945      25.2 1 1 2  6
23 21639 22005      18.6 1 1 1  6
24 21580 21945      19.4 1 2 2 10
25 21761 22127      23.2 2 1 3  7
26 21761 22127      30.3 2 1 3  2
27 21761 22127      35.3 2 1 3  6
28 21761 22127      25.5 2 1 3  6
29 21761 22127      27.4 2 1 3  4
30 21580 21945      23.8 2 1 2  3
31 21761 22127        20 2 2 3  0
32 21761 22127      32.4 2 1 3  7
33 21580 21945      19.7 2 2 2  4
34 21580 21945      21.4 2 2 2 10
35 21761 22127      25.5 2 1 3  1
36 21761 22127      33.1 2 1 3  9
37 21580 21945      22.4 2 1 2  6
38 21761 22127      16.5 2 1 3  4
39 21580 21945      23.8 2 1 2  7
40 21580 21945      22.6 2 1 2  4
41 21580 21945      20.2 2 2 2  7
end
format %td date_start
format %td date_end
label values sex Sex
label def Sex 1 "Female", modify
label def Sex 2 "Male", modify
label values cat1 Category
label values cat2 cat2

I am aware that there are likely to be multiple methods to achieve this, but any insight would be much appreciated.

Thanks,
Liam