Back to Help
Export

Survey Codebook in R and Pre-Analysis Files

Build a survey codebook from variable names, recodes, and a pilot export before analysis in R or Stata.

Plan Analysis Before Data Collection

A pre-analysis plan and survey codebook connect the instrument to analysis in R or Stata. Name variables before launch, export a pilot, and keep assigned conditions and randomization order in the same files you will open in haven or Stata.

Block Builder: Variable Name

Use Domandata While Writing The Codebook

  1. Step 1: Draft the instrument map. Before building, list constructs, outcomes, condition arms, and planned exclusions; use Design an Academic Survey Instrument for the planning pass.

    Step 1: Draft the instrument map

  2. Step 2: Name variables in Block Builder. Add short question names and recodes for analysis-critical fields before pilot testing.

    Step 2: Name variables in Block Builder

  3. Step 3: Confirm assignment in Flow. Open Flow condition sets and record each condition set, arm label, assignment mode, and route.

    Step 3: Confirm assignment in Flow

  4. Step 4: Submit pilot responses. Use Preview to create test data for every major path.

    Step 4: Submit pilot responses

  5. Step 5: Open Export. Download the pilot export and use its headers to finish the codebook.

    Step 5: Open Export

  6. Step 6: Update after changes. When a live survey changes, document what changed, when it changed, and how analysis should treat the affected responses before you publish again.

    Step 6: Update after changes

What To Document

  • Research questions and hypotheses.
  • Primary and secondary outcomes.
  • Experimental condition arms and assignment percentages.
  • Variable names, answer labels, and recodes.
  • Attention checks, manipulation checks, and exclusion rules.
  • Quota targets and sample allocation assumptions.
  • Any randomization or display-order fields needed for analysis.

Flow: Conditions and Routing

Use Domandata Exports

Submit pilot responses and export the data before launch. Use the export headers to confirm planned variable names, recodes, condition assignments, and randomized order fields. Adjust the codebook before collecting live responses.

Export: Data Output

Keep Changes Traceable

If you revise a live survey, document what changed and when. Avoid changing labels, recodes, condition arms, or quota logic unless the change is necessary and accounted for in analysis.

Flow: Conditions and Routing

Survey Codebook In R

After a pilot, download Codebook.csv from Export or the replication package. In R, read it alongside the response file (CSV or haven::read_dta("Responses.dta")) so labels, recodes, and condition arms match the analysis plan. If you pull data with the API, dd_codebook() returns the same dictionary. See Export Survey Data to Stata, R, and Python.

Export: Codebook with the response file

Related Help

Frequently Asked Questions

How do I build a survey codebook in R?

Name variables and recodes in Block Builder, submit a pilot, then download Codebook.csv or pull the codebook API. Use those labels with the response file before you recode in R or open Responses.dta in haven.

When should the codebook be reviewed?

After a pilot: confirm labels, assigned conditions, randomization-order fields, and quota-relevant columns match the analysis plan before launching the full sample.