Export & data

Long format

The tall-and-narrow companion files that ship alongside the wide export. CBC and MaxDiff produce them by default (one row per task or task × concept); any loop can opt into long format at export time with `?long=<loopId>`. Trades column-count blow-up for row-count and a join back to the wide file on `respondentId`.

Why long

The wide export is one row per respondent, one column per variable. That’s optimal for cross-tabs and most survey analysis — but two shapes break it:

  • CBC / MaxDiff. A 12-task × 3-concept CBC produces 36 answer cells per respondent, each with its own attribute levels. Wide-ifying that either explodes columns (Q1t1c1attr1, Q1t1c1attr2, …) or discards the design context. Neither reads well.
  • Loops with high iteration counts. A shopper diary looping over trips can hit 30 iterations for some respondents and 3 for others. The wide file allocates the full authored domain of columns regardless, so most cells are null.

For both, the alternative is a long companion file — one row per (respondent, task) or (respondent, iteration) — joined back to the wide file on respondentId.

CBC — the standard companion pair

Every CBC question produces two long files automatically:

cbc_long — one row per (respondent, task, concept).

ColumnContents
respondentIdJoin key to the wide file.
qidThe CBC question id (e.g. QChoice).
taskTask number, 1-based.
conceptConcept letter within the task (A, B, C, None).
chosen1 if this concept was the choice, else 0. Only meaningful in choice mode.
ratingRating scale code, only populated in rating mode.
rank1-based rank position, only populated in rank mode.
<followUpQid>One column per in-task follow-up question — its answer, per task.

cbc_design — the version × task × concept legend (one row per design cell).

ColumnContents
qidThe CBC question id.
versionVersion number the respondent was assigned (join with the wide file’s <qid>Version column).
taskTask number.
conceptConcept letter.
One column per attributeThe level the design shipped for that (version, task, concept).

Joining them. For each respondent, take their <qid>Version from the wide file, then join cbc_long × cbc_design on (qid, version, task, concept) to get attribute levels attached to every answer row. That’s the shape a utility-recovery regression eats.

Both files ship in every export format — the design legend is included so an analyst opening the bundle has everything needed to run analytics, without a second request.

MaxDiff — maxdiff_long

MaxDiff produces one long file:

ColumnContents
respondentIdJoin key.
qidThe MaxDiff question id.
taskTask number.
itemItem code shown in this task.
best1 if this item was picked as best in this task, else 0.
worst1 if picked as worst in this task, else 0.

Per task, each item that appeared has one row — with best and worst marked accordingly. Items that didn’t appear in the task have no row (there’s nothing to say about them).

Loop stacking — the on-demand variant (#79 / #82)

Since v3.13.0, any loop can be exported long — as a per-export choice, not something the author declares. Pass ?long=<loopId> on the export endpoint:

GET /api/surveys/:sid/export?format=csv&long=brand_loop

That loop’s answers are removed from the wide file and shipped as a companion:

loop_long_<id> — one row per (respondent, iteration).

ColumnContents
respondentIdJoin key.
Loop_<id>The iteration code (e.g. Loop_brand_loop=3).
Each loop-member questionRendered as its normal wide column, but scoped to this iteration — no _N suffix (the suffix moves into the Loop_<id> column).

You can also fetch a single loop’s long file directly:

GET /api/surveys/:sid/export/loop-long.csv?loop=<id>
Wide XOR long — never both. A loop that you request long is not also in the wide file for that export. The rule prevents double-counting when a downstream tool joins on respondentId. If different analysts want the same loop wide and long at different times, generate two exports.

You can stack multiple loops in the same export by passing them together: ?long=brand_loop,market_loop. Each becomes its own companion, and both drop out of the wide.

The /api/surveys/:sid/export/summary endpoint reports stackableLoops (which loops the survey has), and — for the export you just requested — stackedLong (which ones you chose). See Data Hub → Endpoints.

When to reach for long over wide

SituationWide is fineReach for long
Standard survey with hidden helpers and a few loops of 5 iterations✓
CBC / MaxDiff✓ Always (shipped automatically)
Loop that could hit 20+ iterations for some respondents✓ Pass ?long= at export
Loop where every iteration has 5+ questions and iteration count varies a lot✓ Column-count relief
Downstream tool expects tall data (Python pandas.melt, R tidyr::pivot_longer)✓ Skip the reshape
Analyst pipeline consumes wide-only✓

Format availability

Long companions ship in every output format — CSV, SPSS pair, .sav, XLSX, ASCII. In XLSX and the ZIP-bundled formats (SPSS pair, ASCII), the companions are separate sheets / files inside the bundle. In CSV mode, the export endpoint returns a ZIP if long= was passed (a single wide CSV alone can’t hold the companion).

See also

  • Formats — how each output engine packages the wide + long together
  • Data Hub — the UI and endpoints for generating exports with loop stacking
  • Loop suffixes — the wide-file counterpart
  • CBC and MaxDiff — where the design-file legend originates