Solution (source code)

= Solution

Use one row per consecutive at-risk episode, retaining a patient identifier for dependence and an episode number for event order. In calendar time, the intervals are $(\text{start},\text{stop}]$; status is one if the row ends in a headache and zero if it ends in censoring. Patient 001 contributes
|| Patient
|| Next-event episode
|| Start
|| Stop
|| Event
|| $z$

| 001
| 1
| 0
| 24.8
| 1
| 0

| 001
| 2
| 24.8
| 33.1
| 1
| 0

| 001
| 3
| 33.1
| 40.2
| 1
| 0

| 001
| 4
| 40.2
| 51.9
| 1
| 0

| 001
| 5
| 51.9
| 60.0
| 0
| 0

The fifth episode is censored, not a fifth observed headache. All rows retain $z=0$. This <start-stop recurrent-event data layout> corresponds to the <counting-process intensity in survival analysis>
$$
\lambda_i(t\mid\mathcal H_{t-})=Y_i(t)h_0(t)e^{\beta z_i},
$$
where $Y_i(t)$ indicates that the patient is currently observed and eligible for a headache. Fit the <regression coefficient> by <Cox partial likelihood> using the resulting <risk sets>, and estimate the baseline cumulative hazard nonparametrically, for example by the <Breslow estimator>. Patient rows are portions of one history, not new independent patients.