AI Agents and Prompt Engineering in Econometric Coding
Sebastian Galiani,
Federico Ariel López and
Raul A. Sosa
No 35588, NBER Working Papers from National Bureau of Economic Research, Inc
Abstract:
We study how large language models write the code for statistical and econometric analysis. We assign six major models 40 different tasks in Stata, R, and Python, with different prompts and different degrees of agency. The prompt is either only the statement of the task or a prompt that has a related code example. The least agentic version, the chatbot, just writes the code, and a more agentic version can run and revise its code and decide when to stop. We find that more agency raises success from 84 to 97 percent. Letting the chatbot revise its script achieves most of this gain. The example and the language matter more for the chatbot than for the agent, which also narrows the differences between models. An agent’s runs cost 3.4 times as much as chatbot runs, and the cost of an additional correct answer ranges from $0.02 to $1.13, depending on the model. The agent removes almost all loud failures, which occur when the script does not run or does not return every result. On the other hand, it removes only about half of the silent failures, those in which the script runs but returns a wrong value. As a result, most of the failures that remain are silent, so researchers who use AI agents still need to check the code, even when it seems to work.
JEL-codes: C18 C87 (search for similar items in EconPapers)
Date: 2026-08
New Economics Papers: this item is included in nep-ain and nep-cmp
Note: DEV
References: Add references at CitEc
Citations:
Downloads: (external link)
http://www.nber.org/papers/w35588.pdf (application/pdf)
Access to the full text is generally limited to series subscribers, however if the top level domain of the client browser is in a developing country or transition economy free access is provided. More information about subscriptions and free access is available at http://www.nber.org/wwphelp.html. Free access is also available to older working papers.
Related works:
This item may be available elsewhere in EconPapers: Search for items with the same title.
Export reference: BibTeX
RIS (EndNote, ProCite, RefMan)
HTML/Text
Persistent link: https://EconPapers.repec.org/RePEc:nbr:nberwo:35588
Ordering information: This working paper can be ordered from
http://www.nber.org/papers/w35588
The price is Paper copy available by mail.
Access Statistics for this paper
More papers in NBER Working Papers from National Bureau of Economic Research, Inc National Bureau of Economic Research, 1050 Massachusetts Avenue Cambridge, MA 02138, U.S.A.. Contact information at EDIRC.
Bibliographic data for series maintained by ().