# Willingness to pay from stated choices

What is each feature of a contract worth, how much do people differ, and how do you measure it from the choices they
make instead of asking them for a price? This study answers that on real public data: 4,308 stated choices by 361 US
households among electricity supplier contracts (the Electricity data shipped with the R package mlogit).

- A conditional logit (everyone alike) and a panel mixed logit (each feature's weight varies across people, normal
  spread, fixed price weight, 1,000 scrambled Halton draws), with willingness to pay as minus the attribute's weight
  over the price weight, in US cents per kWh on the fixed price.
- Intervals by the delta method and by simulation from the estimates' joint distribution.
- A known answer first: the package's own Exercise 3 fits the same mixed logit; this code reproduces it at the
  published 100 draws.
- Stability across draw counts, draw seeds and starting values; a log-normal run beside the normal one.
- A holdout of whole respondents (five folds) and an independent fit with a second library (xlogit).

The page is `index.html`; every number on it comes from `results/results.json`.

## Reproduce

Needs Python 3.12 and [uv](https://docs.astral.sh/uv/). The data is downloaded from CRAN into `data/raw/` and checked
against the sha256 in `DATA_SOURCES.md`; it is not shipped here.

```
uv sync
uv run python -I wtp/run.py main
uv run python -I wtp/run.py known
uv run python -I wtp/run.py stability-draws
uv run python -I wtp/run.py stability-seeds
uv run python -I wtp/run.py stability-starts
uv run python -I wtp/run.py sensitivity
for f in 0 1 2 3 4; do uv run python -I wtp/run.py holdout --fold $f; done
uv run python -I wtp/run.py crosscheck
uv run python -I wtp/run.py assemble
uv run python -I wtp/report.py
uv run python -I -m pytest tests
uv run python -I tools/check_numbers.py
```

Each stage writes `results/stage-<name>.json`; `assemble` merges them. Every seed is fixed in `wtp/run.py`. `-I`
keeps the downloaded files off Python's import path.

## Files

- `wtp/data.py`: download, verify and read the data; check its size.
- `wtp/models.py`: conditional logit and panel mixed logit (exact gradients, Halton draws).
- `wtp/estimates.py`: willingness to pay, delta-method and simulation intervals, the spread across people.
- `wtp/known_answer.py`: the published estimate and the pass bar.
- `wtp/run.py`, `wtp/assemble.py`, `wtp/report.py`: the stages, the results file and the page.
- `tests/`: data checks, the known answer, recovery of planted values, derivative checks, the holdout split.
- `tools/check_numbers.py`: maps every number on the page to the results.
- `DATA_SOURCES.md`: source, version, sha256, licence, citations, and why the data is not redistributed.

## Limits

Stated choices from one US survey more than two decades old, with a fixed price of only 7 or 9 cents. The numbers do
not carry over to software prices; the method does. See the page's "What carries over" and "Limits" sections.

Some files are packed in willingness-to-pay-data-1.zip; unzip it here to restore the full export, which the manifest lists file by file.
