2          0     0.9      2       0       0           0          0           0       $l_{02}$
       3          0      1       0       1       0           0          0           0       $l_{03}$
       3          1      2       0       1    $m_{13}$       0       $l_{13}$       0       $l_{03}$
       3          2      3       0       1    $m_{23}$   $m_{13}$    $l_{23}$   $l_{13}$    $l_{03}$

  : The counting-process format of the dataset in table 1[]{data-label="tab:ma"}

**Step 3–** Postulate and fit a suitable model for the mediator at a time point $t$, conditional on the exposure, the longitudinal confounder $\overline{L}_t$ and previous measurements of the mediator (i.e. $\overline{M}_{t - 1}$), by using the long data set. For instance, one may assume multinomial logistic models for a categorical mediator $M_k$ with possible values $0, \ldots, Q$. The model for $M_k$ is thus: $$\begin{aligned}
\log \frac{{\text{Pr}}(M_k = q|A = a, \overline{M}_{k - 1} = \overline{m}_{k - 1}, \overline{L}_k = \bar{l}_k, T\ge t_k)}{{\text{Pr}}(M_k = 0|A = a, \overline{M}_{k - 1} = \overline{m}_{k - 1}, \overline{L}_k =\overline{l}_k, T\ge t_k)} = \gamma_{0q} + \gamma_{1q} a + \gamma_{2q}'\overline{m}_{k - 1} + \gamma_{3q}'\overline{l}_t\end{aligned}$$ where $q = 1, \ldots, Q$.

**Step 4–** A new data set is then constructed by copying the original data set (in long format) $P$ times and including an additional variable $A^*$ to capture the $P$ possible values of the 