magics

IPython magics for nbstata

source


source

StataMagics

def StataMagics(
    *args, **kwargs
):

Class for handling magics

test_instance = StataMagics()
test_eq(test_instance._unabbrev_magic_name("*%non_name"), "*%non_name")
test_eq(test_instance._unabbrev_magic_name("%%se"), "%%se")
test_eq(test_instance._unabbrev_magic_name("%br"), "%browse")

source

StataMagics._parse_code_for_magic

def _parse_code_for_magic(
    code
):
test_instance = StataMagics()
test_eq(test_instance._parse_code_for_magic("%browse"), ('%browse', ""))
test_eq(test_instance._parse_code_for_magic("*%browse"), ('%browse', ""))
test_eq(test_instance._parse_code_for_magic("*%br"), ('%browse', ""))
test_eq(test_instance._parse_code_for_magic("*%browse,"), ('%browse', ","))
test_fail(test_instance._parse_code_for_magic, args=("*%blah\nreg var1"))
test_fail(test_instance._parse_code_for_magic, args=("*%se echo=True"))
test_instance._parse_code_for_magic("*%browse in 1/10")
('%browse', 'in 1/10')

source

StataMagics.magic

def magic(
    code, kernel, cell
):

source

StataMagics.magic_locals

def magic_locals(
    code, kernel, cell
):
_get_new_settings("echo = True")
{'echo': 'True'}
_get_new_settings("""
/*
missing = NOTHING
echo = False
*/""")
{'missing': 'NOTHING', 'echo': 'False'}

source

StataMagics.magic_set

def magic_set(
    code, kernel, cell
):

Browse magic


source

StataMagics.magic_browse

def magic_browse(
    code, kernel, cell
):

Display data interactively.


source

Frame

def Frame(
    framename
):

Context manager class akin to Stata’s frame prefix


source

StataMagics.magic_frbrowse

def magic_frbrowse(
    code, kernel, cell
):

Display frame interactively.

https://github.com/bloomberg/ipydatagrid

Head/tail magics

Modeled after pandas.


source

StataMagics.magic_head

def magic_head(
    code, kernel, cell
):

Display data in a nicely-formatted table.


source

StataMagics.magic_frhead

def magic_frhead(
    code, kernel, cell
):

Display data in a nicely-formatted table.


source

StataMagics.magic_tail

def magic_tail(
    code, kernel, cell
):

Display data in a nicely-formatted table.


source

StataMagics.magic_frtail

def magic_frtail(
    code, kernel, cell
):

Display data in a nicely-formatted table.

Help magic

Note that permission was obtained from Stata Corp. for using the request headers below to evade a check intended to block web scrapers. (In a 10/28/2024 email, Stata Technical Support stated: “You are correct this change was made to block web scrapers and not normal users. This API usage is permitted, you can change the headers so that it continues to work.”)

from IPython.core.display import HTML
HTML(_get_help_html("graph set"))
StataNow 19 help for graph_set


[G-2] graph set -- Set graphics options
Syntax
    Manage graph print settings
        graph set print [setopt setval]
    Manage graph export settings
        graph set [exporttype] [setopt setval]
    where exporttype is the export file type and may be one of 
        ps | eps | svg | pdf
    and setopt is the option to set with the setting setval.
    Manage Graph window font settings
        graph set window fontface       { fontname | default }
        graph set window fontfacemono   { fontname | default }
        graph set window fontfacesans   { fontname | default }
        graph set window fontfaceserif  { fontname | default }
        graph set window fontfacesymbol { fontname | default }
Description
    graph set without options lists the current graphics font, print, and
    export settings for all exporttypes. graph set with window, print, or
    exporttype lists the current settings for the Graph window, for printing,
    or for the specified exporttype, respectively.
    graph set print allows you to change the print settings for graphics.
    graph set exporttype allows you to change the graphics export settings
    for export file type exporttype.
    graph set window fontface* allows you to change the Graph window font
    settings.  (To change font settings for graphs exported to PostScript,
    Encapsulated PostScript, Scalable Vector Graphic, or Portable Document
    Format files, use graph set {ps|eps|svg|pdf} fontface*; see [G-3]
    ps_options, [G-3] eps_options, [G-3] svg_options, or [G-3] pdf_options.)
    If fontname contains spaces, enclose it in double quotes.  If you specify
    default for any of the fontface* settings, the default setting will be
    restored.
Remarks
    Remarks are presented under the following headings:
            Overview
            Setting defaults
Overview
    graph set allows you to permanently set the primary font face used in the
    Graph window as well as the font faces to be used for the four Stata
    "font faces" supported by the graph SMCL tags {stMono}, {stSans},
    {stSerif}, and {stSymbol}.  See [G-4] text for more details on these SMCL
    tags.
    graph set also allows you to permanently set any of the options supported
    by graph print (see [G-2] graph print) or by the specific export file
    types provided by graph export (see [G-2] graph export).
    To find out more about the graph set print setopt options and their
    associated values (setval), see [G-3] pr_options.
    Some graphics file types supported by graph export have options that can
    be set.  The file types that allow option settings and their associated
    exporttypes are
        exporttype  Description                  Available settings
        ------------------------------------------------------------
        ps          PostScript                   [G-3] ps_options
        eps         Encapsulated PostScript      [G-3] eps_options
        svg         Scalable Vector Graphics     [G-3] svg_options
        pdf         Portable Document Format     [G-3] pdf_options
        ------------------------------------------------------------
Setting defaults
    If you always want the Graph window to use Times New Roman as its default
    font, you could type
        . graph set window fontface "Times New Roman"
    Later, you could type
        . graph set window fontface default
    to restore the factory setting.
    To change the font used by {stMono} in the Graph window, you could type
        . graph set window fontfacemono "Lucida Console"
    and to reset it, you could type
        . graph set window fontfacemono default
    You can list the current graph settings by typing
        . graph set


source

StataMagics.magic_help

def magic_help(
    code, kernel, cell
):

Show help file from stata.com/help.cgi?{}