{"id":19678856,"url":"https://github.com/adamrossnelson/stataquickreference","last_synced_at":"2026-03-05T10:02:08.713Z","repository":{"id":178200204,"uuid":"102305300","full_name":"adamrossnelson/StataQuickReference","owner":"adamrossnelson","description":"A place to keep Stata code on quick reference.","archived":false,"fork":false,"pushed_at":"2025-05-03T03:24:50.000Z","size":32468,"stargazers_count":17,"open_issues_count":3,"forks_count":10,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-03T04:26:44.611Z","etag":null,"topics":["beginner-friendly","graphic-schemes","graphics","stata","visualization","visualize-data"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adamrossnelson.png","metadata":{"files":{"readme":"ReadMe.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-09-04T01:13:58.000Z","updated_at":"2025-05-03T03:24:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"fae32fec-a36a-4f93-96b9-6991123c9baf","html_url":"https://github.com/adamrossnelson/StataQuickReference","commit_stats":null,"previous_names":["adamrossnelson/stataquickreference"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adamrossnelson/StataQuickReference","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamrossnelson%2FStataQuickReference","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamrossnelson%2FStataQuickReference/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamrossnelson%2FStataQuickReference/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamrossnelson%2FStataQuickReference/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adamrossnelson","download_url":"https://codeload.github.com/adamrossnelson/StataQuickReference/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adamrossnelson%2FStataQuickReference/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30118932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T09:35:22.236Z","status":"ssl_error","status_checked_at":"2026-03-05T09:35:20.028Z","response_time":93,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner-friendly","graphic-schemes","graphics","stata","visualization","visualize-data"],"created_at":"2024-11-11T17:39:45.566Z","updated_at":"2026-03-05T10:02:08.693Z","avatar_url":"https://github.com/adamrossnelson.png","language":"HTML","readme":"# 1. Table of Coneents\n\nFellow Stata enthusiast [Kyle Barron](https://kylebarron.github.io/) has developed and made available `stata_kernel` which makes Stata available in Jupyter Notebooks. Check [here](https://kylebarron.github.io/stata_kernel/getting_started/) for more information on setup and installation. Otherwise [here](https://github.com/adamrossnelson/StataQuickReference/blob/master/StataNotebookExample.ipynb) is a working example.\n\n\u003c!-- TOC --\u003e\n\n- [1. Table of Coneents](#1-table-of-coneents)\n- [2. Stata Quick Reference](#2-stata-quick-reference)\n    - [2.1. Fictional Grade Point Average Data](#21-fictional-grade-point-average-data)\n    - [2.2. Examples related to plotting images and figures](#22-examples-related-to-plotting-images-and-figures)\n        - [2.2.1. BasicPlotting.do](#221-basicplottingdo)\n        - [2.2.2. Stacked area chart StackArea.do](#222-stacked-area-chart-stackareado)\n        - [2.2.3. marginstrend.do](#223-marginstrenddo)\n        - [2.2.4. geoplotipeds.do](#224-geoplotipedsdo)\n        - [2.2.5. Facradar.do](#225-facradardo)\n        - [2.2.6. GetStataSchemes.do](#226-getstataschemesdo)\n        - [2.2.7. Lesser Known But Helpful](#227-lesserknownbuthelpful)\n    - [2.3. ProgArgs.do](#23-progargsdo)\n    - [2.4. renvarlabs.do](#24-renvarlabsdo)\n    - [2.5. md_demo.do](#25-md_demodo)\n    - [2.6. asciiadam.do](#26-asciiadamdo)\n- [3. Stata to Pandas Cross-Walk](#3-stata-to-pandas-cross-walk)\n- [4. Importing JSON to Stata](#4-importing-json-to-stata)\n- [5. License](#5-license)\n\n\u003c!-- /TOC --\u003e\n\n# 2. Stata Quick Reference\n\nThese examples are designed to run from the web. Where possible and where time has permitted these examples are both Mac and Windows compatible. But, no promises.\n\nFor a curated list of packages, their descriptions, and links to further documentation see: [list of useful packages](https://github.com/adamrossnelson/StataQuickReference/blob/master/usefulpackages.md)\n\nThe folks over [geocenter.github.io](https://geocenter.github.io/StataTraining/portfolio/01_resource/) have produced and provided a series of Stata quick references. I keep copies printed out on cardstock at all of my workstations. They're great as gifts! [Local copies here](https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/chtshts/AllCheatSheets.pdf). Also worth reviewing are similar [quick references for R and RStudio](https://www.rstudio.com/resources/cheatsheets/).\n\nSend comments or suggestions via GitHub or Twitter : @adamrossnelson\n\n## 2.1. Fictional Grade Point Average Data\n\n[Fictional GPA data](https://github.com/adamrossnelson/StataQuickReference/tree/master/exampledata). Demonstration of stata random number generators.\n\n## 2.2. Examples related to plotting images and figures\n\n### 2.2.1. BasicPlotting.do\n\nSimple graphics using IPEDS data `ExampleIPEDS.dta`\n\n```Stata\n// To run from command line:\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/plotting/BasicPlotting.do\n// To load example data:\nuse https://github.com/adamrossnelson/StataQuickReference/raw/master/exampledata/ExampleIPEDS.dta\n```\n\nWant to make your own schemes? Vince Wiggins of StataCorp provided a walk-through on this topic.\n\n- [Scheming your way to consistent graphs](https://econpapers.repec.org/paper/bocusug06/11.htm).\n- Vince's presentation materials [schemetalk.zip](http://repec.org/usug2006/schemetalk.zip).\n- Also worth noting, [clever use of SMCL as a slide deck](http://repec.org/usug2006/VW_README.txt).\n\n### 2.2.2. Stacked area chart StackArea.do\n\nDemonstrates production of a stacked area chart in Stata. Also shows dropping a standard legend in favor of explanatory text over stacked areas/regions.\n\n```Stata\n// To run from command line:\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/plotting/StackArea/StackArea.do\n```\n\n### 2.2.3. marginstrend.do\n\nThis do file shows using `margins` and `marginsplot` to visualize trends using Stata. Data is fictional.\n```Stata\n// To run from command line:\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/plotting/marginstrend.do\n```\n\n### 2.2.4. geoplotipeds.do\n\nUsing the longitude and latitude variables stored in IPEDS data, this routine builds a visualization of the institutions in North America.\n\n```Stata\n// To run from command line:\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/plotting/geoplotipeds.do\n```\n\n### 2.2.5. Facradar.do\n\nAnother plotting demonstration. Demonstrates generating a radar plot. Requires the `radar` package available at `http://fmwww.bc.edu/repec/bocode/r/radar.html`. The example given in `radar` documentation shows the package excels at plotting a categorical y (such as automobile make) and a continuous x (automobile weight).\n\nThis implementation plots a categorical y (such as a series of factor scores) and a continuous x (which would be each factor score's mean).\n\n**Help wanted note:** Seeking collaborator in converting `facradar.do` into Stata `.ado` package.\n\n### 2.2.6. GetStataSchemes.do\n\nThis file is a quick routine that will install a range of graphic schemes. Stata's graphic schemes are a useful way to improve the visual presentation of data.\n\nThis routine also sets the default scheme to `lean2wide` which is a modified version of lean1 and lean2. More information about development history in the do file.\n\nTo execute from command line:\n\n```Stata\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/plotting/GetStataSchemes.do\n\n// Additional related commands include ...\n// Show available schemes:\ngraph query, schemes\n\n// Change default scheme:\nset scheme [scheme name], perm\n```\n\n### 2.2.7. Lesser Known But Helpful\n\n`numlabel, add` Prefix numeric values to value labels. With the `, add` option and no other arguments this command will operate on all categorical variables. Helpful when displaying and inspecting data.\n\n`about` Displays information about your version of Stata. If you are running Stata for Windows, information about memory is also displayed.\n\n`sysdir` Query/list system directories. \n\n`macro list` Displays a list of the current set of macros (both local and global) in memory. Also displays information about your version and/or installation instance of Stata.\n\n`creturn list` Displays information about your version, your computer, your installation, and a variety of system variables. From the manual \" Stata's c-class, c(), contains the values of system parameters and settings, along with certain constants such as the value of pi. c() values may be referred to but may not be assigned.\"\n\n`set` Displays system settings. This collection of commands permits edits to system settings. A common example: `set more off` - which tells Stata to pause or not pause for the `--more--` messages. Thus, another common example soon after each installation is `set more off, perm`.\n\n`mvencode` and `mvdecode` Commands that quickly recategorize/recode missing values. `mvencode` Changes missing values to numeric values. `mvdecode` Changes numeric values to missing values.\n\n## 2.3. ProgArgs.do\n\nDemonstration of defining a program, passing arguments, referencing and displaying the arguments passed. Demonstrates material presented Stata 15 User Manual sections 18.1 \u0026 18.4.\n\nTo execute from command line:\n\n```Stata\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/ProgArgs.do\n```\n\n## 2.4. renvarlabs.do\n\nThis do file provides a method that adds text to all variable labels. Also provides an example code that can reference existing variable labels which is useful when automating output for graphs or putdoc/pdf, etc.\n\n```Stata\n// To run from command line:\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/renvarlabs.do\n```\n\n## 2.5. md_demo.do\n\nGenerates markdown from Stata using `qui` and `noi di...` Demonstrates and tests a method for Stata to automate output for display on GitHub or Markdown.\n\nCannot run from the command line without downloading a local copy.\n\n## 2.6. asciiadam.do\n\nExample of a vanity branding splash.\n\nTo execute from command line (or do file):\n\n```Stata\ndo https://raw.githubusercontent.com/adamrossnelson/StataQuickReference/master/asciiadam.do\n```\n\n# 3. Stata to Pandas Cross-Walk\n\nThis repo also provides a [Stata to Pandas Cross-Walk](https://github.com/adamrossnelson/StataQuickReference/blob/master/spcrosswlk.md)\n\n# 4. Importing JSON to Stata\n\nThis  task is not as straight forward as it should or could be. At least two excellent packages exist including [insheetjson](https://ideas.repec.org/c/boc/bocode/s457407.html) and [jsonio](https://wbuchanan.github.io/StataJSON/). The [discussion boards](https://www.statalist.org/forums/forum/general-stata-discussion/general/1357829-creating-a-stata-data-file-from-a-json-formatted-file) provide friendly advice, too.\n\nFor myself, I often find it less difficult and more reliable to use Python's Pandas library. Until recently, for some use cases, this roundabout (json \u003e pandas \u003e stata) approach was necessary. In version 0.23.0, Pandas released support for Stata's `strL` data type. Before `strL` support, if any text fields in the JSON data contained over 2045 characters, it was difficult to go directly from `JSON` to Stata `dta`. The issue documenation (https://github.com/pandas-dev/pandas/issues/16450), resolved, and now available in the latest release. The [revised documentation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_stata.html) also provides helpful information.\n\nNow that Pandas supports Stata's `strL` data type, the first of the two code samples below should be sufficient. Also, if all text fields are 2045 characters or less the second code block below works well to produce a Stata `dta` file:\n\n```Python\nimport pandas as pd\npd.read_json('DemoFileRaw.json').to_stata('DemoFileRaw.dta', write_index=False, \n              version=117, convert_strl=['list', 'of', 'fields')\n```\n\nA workaround that will also be sufficient for many is to first convert to MS Excel `xlsx` which Stata can then imported the command line:\n\n```Python\nimport pandas as pd\npd.read_json('DemoFileRaw.json').to_excel(pd.ExcelWriter('DemoFileRaw.xlsx'), index=False)\n```\n\n# 5. License\n\nExcept where otherwise specifically noted:\n\nMIT License\n\nCopyright (c) 2018 Adam Ross Nelson JD PhD\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamrossnelson%2Fstataquickreference","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamrossnelson%2Fstataquickreference","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamrossnelson%2Fstataquickreference/lists"}