The average treatment effect is defined as the difference in the expectation of an outcome of interest between treatment groups. It is a popular summary measure, but when the treatment assignment is not random, it may not be directly interpretable. This is because potentially relevant factors may be unequally distributed across the treatment groups, and any observed differences in the outcome may not be accounted for by the treatment alone. Inverse probability weighting is often used to adjust for this potential unbalance. This method, however, is known to yield erratic and inefficient inference when outlying weights are present. Different approaches have been proposed to alleviate this limitation. These frequently entail introducing simplifying assumptions in the model for estimating the probability of being treated. While these approaches generally reduce the variability in the weights, and the consequent sampling variability of the weighted estimators, they can also introduce substantial bias. We present optimal inverse probability weighting, which minimizes the bias of the weighted estimator of the average treatment effect for any specified level of its standard error. The optimal weights are defined as the solution to a nonlinear constrained optimization problem. The method is evaluated in a simulation study and applied in the assessment of the timing of treatment initiation in individuals infected by the human immunodeficiency virus. The simulation study suggests that optimal inverse probability weighting has some desirable properties, such as: (1) it provides an estimated ATE with minimum bias while controlling for precision; (2) it allows the researcher to search for a suitable balance between bias and variance directly; (3) it can be implemented with available R packages, such as
ipoptr'' andnloptr”; and (4) it maintains all its properties regardless of the chosen estimator for the ATE.