-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Continuing the discussion from #16:
Preface
Using nbstata for my normal work a few times has turned up a few further quirks of pystata.stata.run.
By the way, nbstata's getting pretty complicated due to my stubborn insistence on the "noecho" mode, so it's really nice that pystata_kernel also exists, as a simpler kernel that passes each code cell pretty directly to pystata.stata.run. (Actually, if I were you, I would remove the echo=None config option to better keep things simple.) That way, if something unexpected happens, the user can at least trace the issue directly back to the behavior of pystata.stata.run.
Single- vs. multi-line code cells
Single-line input (to pystata.stata.run, and thus to pystata_kernel) is processed like Stata's interactive mode, whereas multi-line code is processed via running a do-file. This has a number of implications (beyond echo) that may be surprising to the unsuspecting user of pystata_kernel unless they read the fine print in the pystata docs linked above:
- Inline comments (
//or/* ... */) work in multi-line code but trigger an error in single-line code. #delimit ;works in a multi-line code cell (only for that one cell--and I'd now suggest keeping it that way forpystata_kernel) but placing `#delimit ;' in a single-line cell will cause an error.- More than one graph command in a cell will only result in one graph being displayed unless you give the additional graphs unique names. (This is only noted in the
pystatadocs for the %stata magic.)
edit: Contrary to my original assertions, there are no single- vs. multi-line issues with locals or the version command (and maybe no issues not already flagged somewhere in the pystata docs). The issues I was having with those turned out to only apply to the "noecho" mode which runs multi-line code as a program. (If you maintain that mode in pystata-kernel (contrary to my recommendation above), you may want to address those issues, though, perhaps just by acknowledging them in the README, for starters.)