Skip to content

Commit

Permalink
Rtfd (#58)
Browse files Browse the repository at this point in the history
* Init RTFD (closes #56)
  • Loading branch information
LSYS authored Apr 4, 2024
1 parent 814e759 commit 7148f3d
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 19 deletions.
20 changes: 20 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
tools:
python: "3.9"

sphinx:
configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats:
- pdf
- epub

python:
install:
- requirements: docs/doc_requirements.txt
72 changes: 53 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# wbStata
# rbStata

`wbStata` is a CLI utility to easily convert between (or, go way back to) versions of Stata's `.dta`, which are not forward compatible.
`rbStata` is a CLI utility to easily convert between (or, go way back to) versions of Stata's `.dta`, which are not forward compatible.
* Cross-platform CLI utility: Windows, Mac, Linux.
* No knowledge of Python required (but requires a Python installation).
* ? Takes care of Unicode to ASCII transliteration (older versions of Stata do not support Unicode)
* Handles Unicode to ASCII transliteration (older versions of Stata do not support Unicode).
* Works with Python 3.6+.
* ?Takes care of variable label transferring
* ?Takes care of data label transferring
* ?Takes care of value labels
* Handles transferring (where available and possible) of:
- Variable labels
- Data labels
- Value labels

## Statement of Need

Expand All @@ -16,30 +17,30 @@ This means you cannot use older versions (e.g., `Stata 13`) to read a `.dta` fil

So what is one to do when you try to open a `dta` file in Stata and get a rude `dta too modern r(601)` error:
<details open><summary><em>...</em></summary>
<p align="center"><img width="100%" src="./assets/gfy-error.png"></p>
<p align="center"><img width="100%" src="https://raw.githubusercontent.com/LSYS/rbStata/main/assets/gfy-error.png"></p>
</details>

Find your way back to older versions of Stata `.dta` files with `wbStata`.
`wbStata` is a quick and dead simple CLI (command-line interface) to go way back with Stata data (`.dta`) files. You *do not need access to* newer `Stata` versions.
Roll back to older versions of Stata `.dta` files with `rbStata`.
`rbStata` is a quick and dead simple CLI (command-line interface) to go way back with Stata data (`.dta`) files. You *do not need access to* newer `Stata` versions.


## Quick usage

* **Simple single-line command-line usage:**
* Convert the `auto.dta` file so that you can open it in Stata 13
<pre>$ wbstata auto.dta --target-version 13 --verbose</pre>
<pre>$ rbstata auto.dta --target-version 13 --verbose</pre>

* Convert all `dta` files in the path so that you can open it in Stata 13
<pre>$ wbstata --all --target-version 13 --verbose</pre>
<pre>$ rbstata --all --target-version 13 --verbose</pre>


* **Let `wbStata` prompt you for relevant settings:** <br>
* **Let `rbStata` prompt you for relevant settings:** <br>

Type `wbstata` and enter settings (press enter to accept default settings in brackets):
<pre>$ wbstata</pre>
Type `rbstata` and enter settings (press enter to accept default settings in brackets):
<pre>$ rbstata</pre>
```console
-------------------------------------------------------------
Welcome to the wbStata quickstart command-line utility.
Welcome to the rbStata quickstart command-line utility.

You will be prompted for relevant settings.

Expand All @@ -52,12 +53,30 @@ Find your way back to older versions of Stata `.dta` files with `wbStata`.
Press Enter to include all .dta files in the current directory.)
> .dta file(s) [*]:
...

The Stata version to convert to.
> Target version [13]:
...
File suffix for saving the output file(s).
(For example, the suffix ''-old'' means that auto.dta will be converted and
saved as auto-old.dta. Default is to use ''-rbstata''.)
> File suffix for saving [-rbstata]:
...
Include all .dta files in current directory and its subdirectories.
(Default is to include only the .dta files in the current directory.)
> Include subdirectories (y/n) [n]:
...
> Print all messages (y/n) [y]:
...
```
<details><summary><em>Settings [defaults]</em></summary>

* `.dta file(s)` [*]: .dta files to convert [all .dta files in current directory]
* `Target version [13]`: version to convert to [Stata v13]
* `File suffix for saving [-wbstata]`: Suffix for saving [E.g. save auto.dta to auto-wbstata.dta]
* `File suffix for saving [-rbstata]`: Suffix for saving [E.g. save auto.dta to auto-rbstata.dta]
* `Include subdirectories (y/n) [n]`: Include subdirectories if * [no]
* `Print all messages (y/n) [y]`: Print all messages and errors [yes]
</details>
Expand All @@ -74,20 +93,35 @@ Find your way back to older versions of Stata `.dta` files with `wbStata`.
<!-- * [[6]](https://www.reddit.com/r/stata/comments/4ufos2/convert_stata_14_dta_file_t) Convert Stata 14 .dta file to Stata 13. -->
</details>

## Versions and string handling

One major jump in forward compatibility is from Stata 13 to Stata 14, where Stata 14 started adding Unicode compatibility. `rbStata` handles transferring of the data, value, and variable labels. If Unicode in labels exist and the backward target version is 13, `rbStata` will transliterate Unicode to ASCII *and* truncate labels to 80 characters.

<details open><summary><em>Assortment of enquires about the error</em></summary>

* [[1]](https://www.stata.com/support/faqs/data-management/save-for-previous-version/) Stata support FAQs: How can I save a Stata dataset so that it can be read by a previous version of Stata?
* [[2]](https://www.statalist.org/forums/forum/general-stata-discussion/general/1440296-how-to-read-a-stata-15-data-file-in-stata-13) how to read a stata 15 data file in stata 13.
* [[3]](https://www.statalist.org/forums/forum/general-stata-discussion/general/1326849-how-to-open-stata-14-files-in-stata-12-13) How to open stata 14 files in Stata 12-13.
* [[4]](https://www.statalist.org/forums/forum/general-stata-discussion/general/1373797-how-to-open-a-new-stata-dataset-version) How to open a new stata dataset version.
* [[5]](https://www.statalist.org/forums/forum/general-stata-discussion/general/1363089-how-to-open-a-file-that-is-more-from-a-more-recent-version-of-stata-into-stata13) How to open a file that is more from a more recent version of Stata into Stata13.
<!-- Deadlink -->
<!-- * [[6]](https://www.reddit.com/r/stata/comments/4ufos2/convert_stata_14_dta_file_t) Convert Stata 14 .dta file to Stata 13. -->
</details>

## Alternative solutions
Based on proposed solutions in [More about the problem](#more-about-the-problem).
* [[0]](https://www.stata.com/manuals/dsave.pdf) Use Stata's `saveold` (but for this you first need access to the new Stata version. Read in the `dta` file. Save it using `saveold`. Then use the converted `dta` file in your older Stata version).
* [[1]](https://stattransfer.com/) Stat/Transfer (proprietary).
* [[2]](https://cran.r-project.org/web/packages/haven/index.html) R's `Haven`.

## About this utility
`WbStata` is an open source utility that wraps around [`click`](https://click.palletsprojects.com/) and [`pandas`](https://github.com/pandas-dev/pandas)'s [`DataFrame.to_Stata`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_stata.html) utility. Using `wbStata`, easily convert new Stata `dta` files to older versions.
`rbStata` is an open source utility that wraps around [`click`](https://click.palletsprojects.com/) and [`pandas`](https://github.com/pandas-dev/pandas)'s [`DataFrame.to_Stata`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_stata.html) utility. Using `rbStata`, easily convert new Stata `dta` files to older versions.

<details><summary><em>Expose CLI help reference</em></summary>

```console
$ wbstata -h
Usage: wbstata [OPTIONS] <dta files>
$ rbstata -h
Usage: rbstata [OPTIONS] <dta files>

Find your way back to older versions of dta files.

Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
66 changes: 66 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""Config file for Sphinx."""
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'wbStata'
copyright = '2024, Lucas Shen'
author = 'Lucas Shen'

# The full version, including alpha/beta/rc tags
release = ''


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'myst_parser'
]
myst_heading_anchors = 2
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'furo'
html_sidebars = {
"**": [
"sidebar/scroll-start.html",
"sidebar/brand.html",
"sidebar/search.html",
"sidebar/navigation.html",
"sidebar/ethical-ads.html",
"sidebar/scroll-end.html",
]
}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
2 changes: 2 additions & 0 deletions docs/doc_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
furo
myst_parser
Binary file added docs/images/gfy-error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
% wbStata documentation master file, created by
% sphinx-quickstart on Tue Apr 2 12:43:21 2024.
% You can adapt this file completely to your liking, but it should at least
% contain the root `toctree` directive.

<!-- # Welcome to wbStata's documentation! -->

```{toctree}
:caption: 'Contents:'
:maxdepth: 2
```

```{include} ../README.md
```
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd

0 comments on commit 7148f3d

Please sign in to comment.