AI Agents and Prompt Engineering in Econometric Coding

We measure how often two language models write econometric code whose estimates match a reference output.

Software Prompt Agency

Sebastian Galiani Tulane and NBER · Federico A. López UdeSA · Raul A. Sosa UdeSA

Updated version of NBER Working Paper 35588 · runs · tasks ·

Models can write and run econometric code

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

A script that runs and returns numbers can still be wrong.

The design varies three dimensions

Software

Python

The same task, answered with Python code.

Stata

The same task, answered with a Stata do-file.

R

The same task, answered with R code.

Prompt

Zero-shot

The task statement.

One-shot

The task statement and one example on other data.

Agency condition

Chatbot

Writes one script. We run it once and return nothing to the model.

Self-repair

We run the script. If it fails or lacks a value, the model may revise it up to three times.

Constrained agent

Runs and revises its own code in a shell as often as it chooses.

An example

Each run combines one task, software, prompt, agency condition, and model. We score the output of the final script against the reference output.

Task

Estimate a regression with robust standard errors and report the coefficients. Python and R write result.json.

Software

Stata in this example. The same task is also asked in Python and R.

Agency condition

Self-repair. We run the script and return a failed run for up to three revisions.

task      OLS with robust standard errors
software  Stata
agency    Self-repair
flow      script -> run -> output -> revision -> score

The analysis sample has runs built like this one

What counts as a task success

Scored estimates

Within 1 percent or 0.005 of the reference output, whichever is larger

Scored standard errors

Also scored in the nine tasks whose main decision is the standard error

Loud failure

The script does not run or returns no complete output

Silent failure

The script returns every scored value, but at least one of them is wrong

Scored on runs

Result 1: task success by agency condition

Chatbot
Self-repair
Constrained agent

· both prompt conditions pooled · bars from 0 to 100 percent

Result 2: task success by software

Python
R
Stata

· · bars from 0 to 100 percent

Task success by software and agency condition

Each cluster is one software environment, and each bar is one agency condition, with its value under the bar. In each software environment, task success is highest under the constrained agent.

· Software × agency condition

Result 3: the agent removes loud failures

Under the constrained agent, no run fails loudly. Every failure that remains is silent, so the script runs and returns every scored value, but at least one of them is wrong.

Highest task success

Lowest task success

· Task-level comparison

Cost and task success: Claude Sonnet 4.6

Each row is one agency condition. The last column gives the change in task success and in mean cost per run from the row above.

Mean cost per run at API list prices · bars from 0 to 100 percent

Cost and task success: GPT-5.6 Luna

Each row is one agency condition. The last column gives the change in task success and in mean cost per run from the row above.

Mean cost per run at API list prices · bars from 0 to 100 percent

Results by model

The same design runs on .

Held fixed

Tasks

The same tasks and datasets.

Scoring

The same reference outputs and tolerances.

Conditions

The same software environments, prompts, and agency conditions.

Compared between the two models

Task success

Whether the effects of software, prompt, and agency differ between the models.

Cost per run

The model cost of each condition, at API list prices.

Cost per success

The cost of one successful run.

Explore the paper

Sebastian Galiani, Federico A. López, and Raul A. Sosa · runs · tasks ·

01 / 00

Results and runs