We study a new model where the potential outcomes, corresponding to the values of a (possibly continuous) treatment, are linked through common factors. The factors can be estimated using a panel of regressors. We propose a procedure to estimate time-specific and unit-specific average marginal effects in this context. Our approach can be used either with high-dimensional time series or with large panels. It allows for treatment effects heterogenous across time and units and is straightforward to implement since it only relies on principal components analysis and elementary computations. We derive the asymptotic distribution of our estimator of the average marginal effect and highlight its solid finite sample performance through a simulation exercise. The approach can also be used to estimate average counterfactuals or adapted to an instrumental variables setting and we discuss these extensions. Finally, we illustrate our novel methodology through an empirical application on income inequality.