Marginal structural models are a multi-step estimation procedure designed to control for the effect of confounding variables that change over time, and are affected by previous treatment. When a time-varying confounder is affected by prior treatment standard methods for confounding control are inappropriate, because over time the covariate plays both the role of confounder and mediator of the effect of treatment on outcome. Marginal structural models first calculate a weight to assign to each observation. These weights reflect the extent to which observations with certain characteristics (covariate values) are under-represented or over-represented in the sample with the respect to a target population in which these characteristics are balanced across treatment groups. Then, marginal structural models estimate the outcome of interest taking into account these weights. Marginal structural models are a powerful method for confounding control in longitudinal study designs that collect time-varying information on exposure, outcome and other covariates.