dbf2stata
dbf2stata converts every .dbf file in a folder to a Stata .dta file.
It is designed for research and legacy-data workflows where DBF files contain
mixed date, numeric, logical, character, memo, or FoxPro-style fields.
Behaviour
- Converts all DBF files in one folder.
- Saves
.dtafiles in the DBF folder by default. - Lets the user choose a different output folder.
- Converts Stata variable names to lowercase by default.
--keep-caseretains the DBF field-name case.- Converts DBF date fields to Stata daily dates and datetime fields to Stata datetimes.
- Handles Decimal, numeric, logical, character, memo, and binary-like fields.
- Reports per-file and overall conversion results.
Install for Python users
When published to PyPI:
pip install dbf2stata
For isolated command-line installation, pipx is also suitable:
pipx install dbf2stata
For local development from this repository:
python -m pip install -e .
Run interactively
dbf2stata
The program asks:
Folder containing DBF files: C:\data\dbfs
Output folder [press Enter to use C:\data\dbfs]:
Press Enter at the second prompt to save the .dta files beside the DBFs.
Run with command-line arguments
Save output beside the DBFs:
dbf2stata "C:\data\dbfs"
Use another output folder:
dbf2stata "C:\data\dbfs" --output "C:\data\stata"
Overwrite existing .dta files:
dbf2stata "C:\data\dbfs" --replace
Keep the field-name case stored in the DBF instead of lowercasing names:
dbf2stata "C:\data\dbfs" --keep-case
You can also run the package as a module:
python -m dbf2stata
Stata command
The stata/ directory contains:
dbf2stata.adodbf2stata.sthlp
The Stata command uses the same Python conversion engine, so Python and Stata users receive the same type handling and output behaviour.
Stata requirements
- Stata 16 or newer with Python configured.
- The
dbf2stataPython package installed in the Python environment used by Stata.
Check Stata's Python configuration with:
python query
Once the ado package is installed, run:
dbf2stata
With no options, Stata asks you to select any DBF file in the folder. It then
converts every DBF in that folder and saves the .dta files in the same folder.
Specify the input folder directly:
dbf2stata, inputdir("C:\data\dbfs")
Specify another output folder:
dbf2stata, inputdir("C:\data\dbfs") outputdir("C:\data\stata")
Overwrite existing .dta files:
dbf2stata, inputdir("C:\data\dbfs") replace
Retain DBF field-name case:
dbf2stata, inputdir("C:\data\dbfs") keepcase
Native Stata note
Stata itself includes import dbase for dBase III/IV DBF files. This project is
intended for batch conversion and for DBF collections that benefit from the
additional type handling provided by the Python conversion engine.
Suggested repository layout
dbf2stata/
├── pyproject.toml
├── README.md
├── LICENSE
├── src/
│ └── dbf2stata/
│ ├── __init__.py
│ ├── __main__.py
│ ├── cli.py
│ └── core.py
└── stata/
├── dbf2stata.ado
└── dbf2stata.sthlp
Testing
The conversion engine is covered by automated tests for:
- DBF discovery using
.dbfand.DBFextensions - lowercase variable names by default
- preservation of DBF field-name case with
--keep-case - numeric, logical and date conversion
- default same-folder output
- custom output directories
- overwrite protection
- explicit replacement of existing output files
- missing input-file handling
Run the test suite with:
python -m pytest
The initial development version was additionally validated on a legacy DBF collection containing 81 files and 382,566 records.
Author
William Dormechele
Citation
If you use dbf2stata in research, please cite the software using the citation metadata provided in CITATION.cff.
License
MIT. See LICENSE.
Metadata
Release files for dbf2stata 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| dbf2stata-0.1.0.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dbf2stata-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.6 kB
Release files / dbf2stata-0.1.0.tar.gz
| Download URL | dbf2stata-0.1.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab8b98e44442cecb5b53fff9462b28ab8aba703450ac83a8be347d650ffdb3d2
|
|
BLAKE2b-256 checksum How to use checksums |
7f79ed06b2e8b5dec5200d23ac2d4415c3ee6101c0a809fab650fc2c9c58d60e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|
Release files / dbf2stata-0.1.0-py3-none-any.whl
| Download URL | dbf2stata-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bcb99a26aceb54f465556b3b7fe4622f03c644a6902666bea2486c3ab9231296
|
|
BLAKE2b-256 checksum How to use checksums |
ae4bea9ec5e2dbd7ad0ea6c9a0bc61894a6abaeab2fa16344648530610c3e861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.4
|