Production function estimation with micro-data shows that a persistent unobserved variable varies within firm or plant over time but resists treatment and may cause biases. This paper presents an estimation model of the firm under endogenous productivity change. The model implies that (i) the so-far untreated effect stems from firms' planned efficiency responses to the competitive environment and that (ii) a suit-able proxy to productivity is investment interacted with a sector-level competition variable. An application to Brazilian manufacturing firm data shows that this proxy and multivariate extensions yield coefficient estimates with considerably less noise in bootstraps than alternative proxies, while reducing the difference to fixed-effects estimation and remedying commonly suspected biases. Whereas productivity change is measured consistently, scale economies are not identified when productivity and price are endogenous.