• causal inference;
  • time-dependent confounding;
  • marginal structural models;
  • survival analysis;
  • longitudinal data;
  • simulation;
  • inverse probability weights

We discuss why it is not always obvious how to simulate longitudinal data from a general marginal structural model (MSM) for a survival outcome while ensuring that the data exhibit complications due to time-dependent confounding. On the basis of the relation between a directed acyclic graph and an MSM, we suggest a data-generating process that satisfies both these requirements, the general validity of which we prove. Our approach is instructive regarding the interpretation of MSMs and useful in that it allows one to examine the finite sample performance of methods that claim to adjust for time-dependent confounding. We apply our methodology to design a simulation study that emulates typical longitudinal studies such as the Swiss HIV Cohort Study so that competing methods of adjusting for time-dependent covariates can be compared. Copyright © 2012 John Wiley & Sons, Ltd.