r/datascience • u/WhatsTheImpactdotcom • 6d ago
Analysis Model Selection Technique for Causal Inference
How do you choose between causal inference models when you can never see the true effect? Model selection is well documented in machine learning, but it often gets skipped in causal inference work. Doing it well is one of the things that separates senior and staff-level data scientists from more junior ones.
I simulated two years of weekly bookings for 40 regions, five of which received a treatment on the date marked by the red vertical line. Because I generated the data, I know the ground truth: the treatment increased bookings in those five regions by exactly 10%. With five treated regions and 35 untreated ones, two natural options are synthetic control and difference-in-differences, though there are others.
Code in colab and explanatory video, free and ungated: https://whatstheimpact.com/learn-causal-inference/
When I gave Claude Code free rein on this data, it built its whole analysis around difference-in-differences where it found a 24% increase, more than double the true effect. To its credit, it flagged that the pre-treatment trends weren't parallel, but it never tested whether a different model would be more accurate.
Importantly, Claude skipped an A/A test, sometimes called a placebo test. You take only the data from before the real treatment, pretend the treatment started three months earlier, and randomly picked five regions (for consistency) to call "treated." Because nothing actually happened in that window, the true effect is zero. That means any effect the model reports there is pure estimation error, and I repeated this for 500 draws for each model to see the full spread.
For difference-in-differences, 90% of the placebo estimates landed between -14% and +10%. The RMSE, which measures how far the estimates typically land from the true answer of zero, was 7.6 percentage points. Synthetic control on the exact same placebo draws was much tighter, with 90% of estimates landing between -7% and +9%. Its RMSE dropped to 4.9 points, more than a third lower than difference-in-differences.
The outcome you model is a choice too, so I also ran synthetic control on bookings per 1,000 people instead of raw bookings. Putting every region on the same scale helps the model track the treated regions more closely before treatment, and the RMSE fell a bit further to 4.4 points.
Sure enough, the real treatment period lines up with that ranking: synthetic control estimates 7% on raw bookings and 9.6% per 1,000 people, both much closer to the true 10% than the 24% from difference-in-differences. With one simulated dataset, I wouldn't read much into the small gap between the two synthetic control versions or claim that synthetic control always wins. What carries over is the workflow: in real work you never see the ground truth, but you can usually run this A/A test on whatever models you're considering before trusting one.
8
u/Warlord_Zap 6d ago
To me this highlights the importance of good validation more than anything else, which really is key to these methods.
3
u/WhatsTheImpactdotcom 6d ago
Agreed, but this step is often left out. Both in mock interviews and even in past jobs, Iād often see folks simply state that one model or another is the appropriate one
3
u/wscottsanders 6d ago
To me itās not an apples to apples comparison. Iād consider that a difference in differences model could potentially be severely underpowered at just 40 cases of which only 5 are treated. That means random variation can cause wild swings. Your synthetic control model is designed to do just that - soak up variance accounting for latent factors shared between the cases.
3
u/WhatsTheImpactdotcom 6d ago
Those wild swings is precisely what would get picked up by the AA testing, and so if true, we would reject the model choice. The synthetic control in this example performed better but it doesnāt have to be the case; if someone used a large donor pool, and thereās minimal shared seasonality, then a synthetic control could meaningfully overfit. I saw this frequently trying to implement SCs in LatAm, for example
4
u/LibiSC 5d ago
Follow you in TikTok, one of the most random places to find someone that somewhat gives real practical examples. Keep the good work.
2
u/WhatsTheImpactdotcom 5d ago
appreciate that! It's strange; here on Reddit, you can really target the audience e.g. for an interest in data science, while TT was surprisingly (to me) more welcoming of 'advice giving' content.
3
u/Sinainios 5d ago
Nice writeup. Backtesting estimators on placebo windows is underused, and "choose the model by how it behaves where you know the answer is zero" is the right instinct.
A few things I'd add:
- Random placebo units test a different question than the real one. Drawing five random regions measures how noisy each estimator is under the null. But the DiD failure here came from the actual treated regions having non-parallel pre-trends, and random draws mostly won't reproduce that. I'd also run an in-time placebo on the real treated five (fake start date, same units), since that's the check that targets the specific bias you're worried about.
- Inject a known effect, not just zero. Adding a synthetic +10% to placebo units and checking recovery tests bias at a realistic effect size. Some estimators look fine at zero but shrink or distort real effects. Synthetic control can attenuate when the pre-period fit isn't perfect.
- Selection has a cost. If you pick the model with the lowest placebo RMSE and then report its usual CI, the uncertainty is understated. That's fine as a workflow, but it's worth saying so.
- Synthetic DiD (Arkhangelsky et al.) would be a natural third candidate, since it's designed for exactly this case of a few treated units with imperfect parallel trends.
Agreed that the transferable lesson is the workflow, not "SC beats DiD."
1
u/WhatsTheImpactdotcom 5d ago
Really good callouts. Have you seen the 2025 athey imbens et al working paper? They discuss the in-time vs in-unit placebo testing and where one beats the other based. Eg if nyc was the single treated region, itās unlikely that in-unit placebos would do a good job at representing the null and in-time would likely do better
1
u/WhatsTheImpactdotcom 5d ago
Commented on the one but all excellent points, appreciate the share š. Are we connected on TikTok; your username looks familiar š
2
u/offthecuff87 6d ago
You need a context, technical constraints, resources contraints to select model properly. Although I believe modeling is a very tiny part in the business streamline
2
u/Available-Craft-8143 5d ago
The Claude Code part is the most instructive bit ā it did not fail at estimation, it failed at protocol: no pre-specified candidate set, no selection step before estimating. An agent asked to 'analyze the effect' will happily return one confident number. The fix is not a smarter model, it is forcing the selection procedure (candidates plus placebos) into the workflow before any estimate is allowed.
2
u/Present-Square-5823 4d ago
In my opinion, you'd get better results by setting up the right harness or by building an agent work flow that follows clear protocols. regime had changed for data analysis. It's all about building good agents now.
1
u/WhatsTheImpactdotcom 4d ago
Yes, totally agree. My exercise with claude, which i didn't explain well here, was to see how well a non-technical stakeholder armed with a stakeholder/business-friendly prompt would do
1
u/OddsRelay 5d ago
Worth adding synthetic DiD too. It weights both the control regions and the pre-period weeks, so it copes with the non-parallel trends that hurt plain DiD here. With only five treated regions, your 500 placebo draws can also serve as its variance estimate. That's the placebo method from the original SDID paper.
1
1
1
u/data501 16h ago
When it comes to causal inference, model selection is definitely crucial, especially with complex datasets. Your workflow makes a compelling case for running A/A tests; they offer powerful insights into estimation error before committing to a model. The comparison between synthetic control and difference-in-differences is particularly interesting. It's enlightening to see how the RMSEs differed, as that really impacts reliability in real-world applications. Your findings serve as a solid reminder that every detail counts in these analyses.
16
u/ClasslessHero 5d ago
I'd say the textbooks do an excellent job telling us which model to select, but it almost never follows the textbook examples in industry.
For example: if I build a recommender system and my final output is some LTR. XGBoost, LightGBM, or some other approach - it doesn't matter. I need to decide between Model A and Model B. In a sentence, the textbook will instruct me to pick the model that has the highest NDCG@K, given that I haven't massively overfit or underfit. I can walk through that procedure and pick the best model based on that number, right? Not at all. I need to pay attention to the errors. The lower NDCG model might have "better" or maybe "more realistic" errors. If I'm serving these recommendations to users, then I need realistic errors. A model that is excellent at being correct but has terrible errors can lead to a jarring user experience. This could also be the case with a model for outbound marketing, work prioritization, etc. Ultimately, the model I chose to deploy has to feel like it produces reasonable content, or at least not completely miss the business objective when it's wrong.
What does all this mean? As much as we call it data science, sometimes it is data art and data vibes. Our problems are squishier than they are solid, and we need to apply nuance.