Can AI write your code? A case study of chatgpt’s statistical coding capabilities for quantitative research
摘要
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.
MethodsThis 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.
ResultsChatGPT 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.
ConclusionsChatGPT 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.