AI Agents and Prompt Engineering in Econometric Coding

How reliably do large language models implement econometric specifications?

Software Prompting Agent interface

Sebastian Galiani Tulane / NBER · Federico A. López UdeSA · Raúl A. Sosa UdeSA

runs · tasks ·

Models can produce executable econometric code

An LLM can write code for an econometric specification in Python, Stata, or R. A coding agent can also run and revise the script, with additional model cost.

Execution alone leaves specification and target errors undetected.

The experiment varies three dimensions

Econometric software

Python

Same task contract, answered with Python code.

Stata

Same task contract, answered with a Stata do-file.

R

Same task contract, answered with R code.

Agent interface

Chatbot

Writes the code once. It does not run the script.

Self-repair

Writes the code, sees run reports, and revises before it submits. Each harness caps the revisions.

Constrained agent

Controls a shell-execution loop for up to twelve model turns and decides when to submit.

An example

Each run is one cell in the design: a task, a software platform, and an agent interface. The model receives the task instructions and must leave behind a result file that the scorer can check.

What it was asked for

Estimate a regression and report the coefficient, standard error, and sample size in result.json.

Software

Stata for this cell; the same task is also asked in Python and R cells.

Agent interface

Self-repair: draft code, observe run reports, then submit the repaired script.

task      robust-SE regression
software  Stata
interface Self-repair
flow      draft -> report -> repair -> score

The analysis sample contains runs built from cells like this

What counts as a task success

Right numbers

Output matches the reference within the declared tolerances

Valid submission

The run solves the task from the declared inputs

It runs

Diagnostic. The script executes without error

Right method

Diagnostic. It set up the correct approach and target

Scored on runs

Result 1: task success by agent interface

Chatbot
Self-repair
Constrained agent

· both prompt conditions pooled

Result 2: task success by software platform

Python
R
Stata

·

Task success by software and agent interface

Each cluster is one software platform, and each bar is one agent interface. Task success is highest for Constrained agent within Python, R, and Stata.

· Software × agency condition

Result 3: execution leaves specification errors

The lower-scoring tasks require the exact estimator, estimand, variance rule, or output terms.

Highest task success

More modeling discretion

· Task-level comparison

Cost and quality, together

Each row is one agency condition. The bar reports task success, mean cost reports price, and the incremental column compares adjacent displayed conditions.

· Mean cost per run · success bars start at 50%

Robustness across models and providers

The same design runs on .

Held fixed

Tasks

The same task contracts and fixed datasets.

Scoring

The same reference outputs, tolerances, and integrity checks.

Conditions

The same software platforms, prompts, and agent interfaces.

Compared across models and providers

Task success

Whether conclusions about software, prompting, and interface depend on the model.

Cost per run

The model expenditure associated with each condition.

Cost per success

The expenditure required to obtain a correct result.

Explore the paper

runs · tasks ·

01 / 00

Menu