Can AI write your code? | Towards Data Science
The AI Coding Paradox: Trusting the Machine in Quantitative Research

The question is no longer whether Artificial Intelligence can write code. Anyone who has spent time with ChatGPT or Claude knows it can spin up a Python script or debug an R function in seconds. The real question—the one that keeps researchers and data scientists up at night—is whether we can actually trust the output. As LLMs become embedded in our daily workflows, we are seeing a shift from simple automation to the delegation of complex methodological tasks. A recent study, “Can AI write your code? A case study of ChatGPT’s statistical coding capabilities for quantitative research,” published in the Health Economics Review, puts this tension under the microscope.
Beyond Syntax: The Challenge of Causal Inference

Most early AI coding benchmarks focused on “toy” problems: cleaning a CSV, calculating a mean, or writing a basic loop. But quantitative research is different. When you are performing a Difference-in-Differences (DiD) analysis or implementing Inverse Probability Treatment Weighting (IPTW), the code isn’t just about syntax—it’s about the underlying statistical logic. The Winberg et al. Study tested ChatGPT-4.0 Pro against standardized econometric benchmarks from the industry-standard text, Causal Inference: The Mixtape. By evaluating how the model handled Python, R, and Stata, the authors moved the conversation from “Does it work?” to “Is it methodologically sound?”
Why Stata Lags Behind Python and R
The findings offer a sobering lesson in how LLMs learn. The study found that ChatGPT performed with higher reliability in Python and R than in Stata. This isn’t necessarily a failure of the model’s “intelligence,” but a reflection of its training data. Because Python and R are open-source and ubiquitous in data science, the volume of high-quality, public-facing code examples is massive. Stata, while a powerhouse in economics and public policy, has a smaller, more closed ecosystem. For the modern researcher, this creates an infrastructure mandate: if your workflow relies on AI assistance, the language you choose to code in may determine the quality of the support you receive from your LLM.
The Evolution of the Researcher’s Toolkit
My own workflow has undergone a radical transformation. A few years ago, the exploratory phase of a research project—identifying papers, setting up the initial model architecture, and hunting for data—was a manual grind. Today, LLMs act as high-speed research assistants. They don’t replace the expert, but they condense days of labour into hours of validation. However, this speed introduces a new risk: the “illusion of competence.” When code runs without errors, it is easy to assume the results are correct. As the EY Canada incident—where a firm had to retract a study due to hallucinated data—demonstrates, the cost of “trusting but not verifying” is professional catastrophe.
The Future: Expertise as the Ultimate Filter
We are moving toward a future where AI handles the “heavy lifting” of coding and data formatting, while the human researcher focuses exclusively on high-level interpretation, and validation. This shifts the value of human expertise. You don’t need to be a coding wizard to be a great analyst, but you must be a rigorous validator. The ability to spot a subtle bias in a model or a logical flaw in an automated script is becoming more valuable than the ability to write that script from scratch.
Frequently Asked Questions
1. Is AI-generated code safe for professional econometric research? It is a powerful tool for acceleration, but it is not a replacement for human oversight. Every line of code generated by an LLM should be audited against your data and theoretical benchmarks. 2. Why does ChatGPT struggle more with Stata than Python? LLMs are trained on massive datasets of public code. Python and R have significantly more open-source documentation and public repositories, allowing the model to “learn” these languages more effectively than the proprietary Stata environment. 3. How can I reduce the risk of hallucinations in my research? Use a “human-in-the-loop” approach. Treat the AI as a junior assistant: provide clear, structured prompts, require the model to cite its methods, and always run the code against a known, small-scale test dataset before applying it to your full research project. 4. Will AI eventually replace data scientists? No. AI will replace the repetitive tasks that data scientists perform. The role of the scientist will evolve toward higher-level strategy, ethics, and the final validation of AI-driven insights. *** How has your workflow changed since integrating AI? Are you finding it easier to switch between languages, or are you finding more “hidden” errors in your output? Join the conversation in the comments below or subscribe to our newsletter for more deep dives into the future of data science.