Inference on Factor Structures in Heterogeneous Panels