Awesome
nbstata: a new Stata kernel
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
nbstata is a Jupyter kernel for Stata built on top of pystata.
For the User Guide, click here.
What is Jupyter?
A Jupyter notebook allows you to combine interactive code and results with Markdown in a single document. Though it is named after the three core programming languages it supports (Julia, Python, and R), it can be used with with a wide variety of languages.
nbstata allows you to create Stata notebooks (as opposed to using Stata within a Python notebook, which is needlessly clunky if you are working primarily with Stata).
Key nbstata features
- Easy setup
- Works with Stata 17+ (only).
- Displays Stata output without the redundant ‘echo’ of (multi-line) commands
- Autocompletion for variables, macros, matrices, and file paths
- DataGrid widget with
browse
-like capabilities (e.g., interactive filtering) - Variable and data properties available in a ‘contextual help’ side panel
- Interactive/richtext help files accessible within notebook
-
#delimit ;
interactive support (along with all types of comments) - Quarto inline code support
The video below demonstrates using Stata in a Jupyter notebook. In addition to the NBClassic application shown there, nbstata can also be used with JupyterLab, VS Code, or Quarto.
<img align="center" width="650" src="https://github.com/kylebarron/stata_kernel/raw/master/docs/src/img/jupyter_notebook_example.gif" alt="Animated GIF demoing major Stata kernel features">What can you do with Stata notebooks…
…that you can’t do with the official Stata interface?
- Exploratory analysis that is both:
- interactive
- preserved for future reference/editing
- Present results in a way that interweaves:1
- code
- results (including graphs)
- rich text:
- lists
- Headings
- <img align="left" width="54" height="18.6" src="https://raw.githubusercontent.com/hugetim/nbstata/master/index_files/figure-commonmark/226326ec-1-image-2.png" alt="WordArt of the word 'images'">
- links
- math: $y_{it}=\beta_0+\varepsilon_{it}$
Contributing
nbstata is being developed using
nbdev.
The /nbs
directory is where edits to the source code should be made.
(The python code is then exported to the /nbdev
library folder.)
For more, see CONTRIBUTING.md.
Acknowledgements
Kyle Barron authored the original stata_kernel, which works for older versions of Stata. Vinci Chow created a Stata kernel that instead uses pystata, which first became available with Stata 17. nbstata was originally derived from his pystata-kernel, but much of the docs and newer features are derived from stata_kernel.
Footnotes
-
Stata dynamic documents can do this part, though with a less interactive workflow. (See also: markstat, stmd, and Statamarkdown) Using nbstata with Quarto instead gives you a similar workflow, with greater flexibility of output. ↩