Counterfactual reasoning: an analysis of in-context emergence