Skip to content

About

Automatic codebook generator for survey datasets (.dta / .xlsx) - generates Excel codebook with variable metadata

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Codebook Generator

Author: Mehedy Hasan
Organisation: ARCED Foundation
Position: Research Assistant

A lightweight Python tool that automatically generates a codebook (Excel file) from survey datasets. Supports both Stata .dta files and Excel .xlsx/.xls files.

Output

The generated codebook contains five columns:

Column Description
Variable The variable name in the dataset
Obs Number of non-missing observations
Miss obs Number of missing observations
Ques. The survey question text (variable label)
Label The variable label/description

Features

  • Works on Google Colab — upload and run, no installation needed.
  • Also works on local Jupyter notebooks.
  • Handles Stata files with variable labels via pyreadstat.
  • Handles Excel files via pandas.
  • Auto-downloads the output Excel file on Colab.

Quick Start (Google Colab)

  1. Open the notebook in Colab: click Open in Colab badge below or upload the .ipynb file manually.
  2. Click Runtime > Run all (or press Ctrl+F9).
  3. In the Upload cell, click Choose Files and select your .dta or .xlsx file.
  4. The codebook is generated and downloaded automatically as codebook.xlsx.

Open In Colab

Quick Start (Local Jupyter)

  1. Clone this repository:

    git clone https://github.com/mehedy0905/codebook-generator.git
    cd codebook-generator
  2. Install dependencies:

    pip install pandas openpyxl pyreadstat
  3. Launch Jupyter:

    jupyter notebook codebook_generator.ipynb
  4. Run all cells (Kernel > Restart & Run All). The upload cell will prompt you to select a file.

Configuration

In Step 4 of the notebook, you can customise:

Parameter Default Options Description
OUTPUT_NAME "codebook.xlsx" any string Name of the output Excel file
QUES_SOURCE "label" "label" or "none" Controls the Ques. column content
  • "label" — Uses the variable label as the question text (recommended for surveys).
  • "none" — Leaves the Ques. column blank.

Project Structure

codebook-generator/
├── codebook_generator.ipynb   # Main notebook
├── README.md                  # This file
├── .gitignore                 # Git ignore rules
└── LICENSE                    # MIT License

Requirements

  • Python 3.8+
  • pandas
  • openpyxl
  • pyreadstat

All dependencies are auto-installed by the notebook if missing.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Mehedy Hasan
Research Assistant, ARCED Foundation

About

Automatic codebook generator for survey datasets (.dta / .xlsx) - generates Excel codebook with variable metadata

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages