may differ from the counterfactual value that is of interest at that time. Note that the notation $\lfloor t \rfloor$ here is slightly different from its standard definition, to take into account the fact that if a patient experiences an event or leaves the study at time $t=t_k$ of visit $k$, no measurement of $M_k$ and $L_k$ is possible at that time. More precisely, $$\lfloor t \rfloor= \begin{cases}
t_{k-1}~~~\mathrm{if}~~~ t=t_k\\
t_k~~~~~~~\mathrm{if}~~~ t_k < t < t_{k+1}
\end{cases}$$ where $ k =1,\ldots,K$. From this, the fitting procedure is described as follows:

**Step 1–** Postulate and fit a suitable model for the exposure $A$ conditional on the baseline confounders ($L_0$) based on the original data set. For instance, a multinomial logistic model can be used for a categorical exposure with $P$ possible values: $$\begin{aligned}
\log \frac{{\text{Pr}}(A = a|L_0 = l_0)}{{\text{Pr}}(A = 0|L_0 = l_0)} = \beta_{0,a} + \beta_{1,a}\,l_0,\end{aligned}$$ where $a = 1, \ldots, P - 1$ and ${\text{Pr}}(A = 0|L_0 = l_0) = 1/(1 + \sum_{a = 1}^{P - 1} e^{\beta_{0,a} + \beta_{1,a}\,l_0})$.

**Step 2–** Convert the original dataset to a long or counting-process format, in which the observation period $[0, t_i]$ of subject $i$ is broken into $\lfloor t_i \rfloor + 