AI Agents & Econometric Coding

Poisson and count models

Poisson regression

An exposure offset converts event counts into comparable conditional rates.

The task

Task statement

Estimate a Poisson regression of y_count on x1 and x2 with an intercept and an offset equal to the natural log of exposure. Report rows const, x1, and x2 with asymptotic model-based standard errors.

Data

Columns include id, x1, x2, y_iv, x1_iv, z, cluster, y_panel, exposure, and y_count.

Files
input.csv

Required output

Scored estimates: const, x1, x2.

Reference output

TermReference estimateSample size
const0.292612382,000
x10.419604922,000
x2-0.188567042,000

A run succeeds when every scored estimate lies within 1 percent or 0.005 of its reference value, whichever is larger. Sample sizes are not scored.

Task success

Agency conditionClaude Sonnet 4.6GPT-5.6 Luna
Chatbot100.0%91.7%
Self-repair100.0%100.0%
Constrained agent100.0%100.0%
All runs
98.6% of 360 runs
By prompt condition
Zero-shot 97.8%, One-shot 99.4%
By software
Python 100.0%, R 100.0%, Stata 95.8%

Counts observed over unequal exposure

A count observed for ten person-years is not directly comparable with one observed for a single person-year. A Poisson offset fixes the coefficient on log exposure at one (Cameron and Trivedi, 2013).

$$ \log E[y_i\mid x_i,e_i]=x_i'\beta+\log e_i. $$

Equivalently, $E[y_i\mid x_i,e_i]/e_i=\exp(x_i'\beta)$.

A rate example

Suppose $\exp(x_i'\beta)=0.4$ events per unit of exposure.

Exposure $e_i$Expected countExpected rate
10.40.4
52.00.4
104.00.4

The offset scales the count while preserving the modeled rate.

Assumptions and implementation

The Poisson conditional mean must be specified correctly for consistent quasi-maximum-likelihood coefficients. The equality of conditional mean and variance is needed for model-based standard errors. Robust covariance can relax that variance restriction.

Exposure must be positive. Logging the exposure and estimating its coefficient changes the model. Some software accepts offset(log_e) and other software accepts exposure=e.

Three observation windows with proportional expected counts illustrate the offset restriction.

Interpretation and reporting

A slope coefficient in this model is a log rate ratio. Exponentiating $\beta_j$ gives the factor change in the expected event rate for one additional unit of $x_j$. The exposure coefficient is fixed at one, so changing exposure scales the expected count proportionally.

For the table, exposure rises from one to ten while the expected rate stays $0.4$. The expected count therefore rises from $0.4$ to $4.0$. This change describes a longer observation window, not a regressor effect.

Report rate ratios with uncertainty on the same multiplicative scale. State the exposure unit, such as person-years or machine-hours. Also identify the covariance estimator. Model-based covariance relies on Poisson variance, while robust covariance permits other conditional variance patterns.

Reproducible implementation

Verify that every retained exposure value is positive and measured in a common unit. Create $\log e_i$ once, then pass it as an offset with coefficient fixed at one. Do not include the same variable as an estimated regressor.

Check predictions in two forms. The count prediction is $\widehat\mu_i$, while the rate prediction is $\widehat\mu_i/e_i$. Multiply an exposure by a known factor and confirm that the predicted count changes by that factor.

Inspect residual patterns and the relation between conditional means and variances. Excess zeros or large overdispersion can motivate another count model. Save software syntax, the estimation sample, and the covariance option with the coefficient table (Cameron and Trivedi, 2013).

Further reading

Cameron and Trivedi develop count models, exposure, and robust inference (Cameron and Trivedi, 2013). McCullagh and Nelder place the model in the generalized-linear-model framework (McCullagh and Nelder, 1989).

Sources and further reading

  1. A. Colin Cameron, Pravin K. Trivedi. 2013. Regression Analysis of Count Data. Cambridge University Press. doi:10.1017/CBO9781139013567.
  2. Peter McCullagh, John A. Nelder. 1989. Generalized Linear Models. Chapman and Hall. Source.

About this benchmark task

Method group
Poisson and count models
Software
Stata, R, and Python
Runs
360 runs, ten in each combination of model, software, prompt, and agency condition

Open every recorded run for this task.