Can AI write your code? A case study of chatgpt’s statistical coding capabilities for quantitative research
Abstract Background Recent advancements in Artificial Intelligence (AI), particularly in large language models (LLMs) like OpenAI’s ChatGPT, have extended its applications well beyond simple dialogue generation. ChatGPT has shown potential in supporting data-driven decision-making. ChatGPT has gained traction in academia for its ability to generate code for data analysis, providing robust support for programming languages. This study aims to evaluate ChatGPT’s ability to generate code for causal inference and data analysis. Methods This study evaluates ChatGPT4.0 Pro’s performance in coding Difference-in-Differences (Diff-in-Diff ), Inverse Probability Treatment Weighting (IPTW), and Regression Discontinuity (RD) using problem sets and reference code from “Causal Inference: The Mixtape”. The evaluation was conducted in Python, Stata, and R. Researchers provided structured prompts and feedback, and a fourth researcher replicated all tasks to assess consistency. Primary outcomes included accuracy, efficiency, error output, editing needs, and inter-user consistency. Results ChatGPT generated accurate code and results in R and Python for most tasks. However, it struggled with IPTW and performed less reliably in Stata. Errors were often related to data management or figure generation. Although ChatGPT could replicate correct results, the structure and syntax of its code varied across users and sessions. Conclusions ChatGPT shows strong potential as a supportive tool for econometric coding tasks in health economics, especially in Python and R. However, its output still requires human interpretation and validation. As generative AI continues to evolve, these tools hold promise for streamlining research tasks but remain supplementary to skilled human researchers in quantitative research.
Authors
- Debra Winberg (ORCID: https://orcid.org/0000-0003-2909-1455)
- Nicolas Marchi
- Tiange Tang
- Dennis Xuan
- Ethan Tsai
- Lizheng Shi
Institutions
- Tulane University (US)
- Georgetown University (US)
- University Hospitals Plymouth NHS Trust (GB)
Publication Details
- Journal
- Health Economics Review
- Published
- 2026-01-22
- DOI
- https://doi.org/10.1186/s13561-025-00714-8
- Primary Topic
- Data Analysis with R
- Type
- article
- Field-Weighted Citation Impact
- 0.00