Skip to main content

Access Stata within python

Project description

Pystata

    1. Save python data to csv
    1. Use python to write stata do file following regression specifications
    1. Report regression results and re-read it into python

Stata required library (Install if you haven't done so)

  • ssc install reghdfe, ftools, esout

Example (See example.ipynb for more details)

from src.pystata import summary_col

# some random combinations of fixed effects
fx_1 = {'Stock fixed effects': 'fx1', 'Year fixed effects': 'fx2'}
fx_2 = {'Stock fixed effects': 'fx1', 'Industry Fixed effects': 'fx3'}
fx_3 = {'Stock fixed effects': 'fx1', 'Year fixed effects': 'fx2', 'Industry Fixed effects': 'fx3'}
# Syntax: [data, regression specification, covariance type (enter cluster list),fixed effects]
reg_inputs = [[data, 'Y  ~ 1  + x1+ x2', 'covariance type', {Fixed Effects}],  # This is an example (column 1)
[data1, 'y  ~ 1  + x1+ x2 ', 'robust', fx_1],  # (column 2) 
[data2, 'y  ~ 1  + x1+ x2 + x3 + x4', 'robust', fx_2],  # (column 3)
[data2, 'y  ~ 1  + x1+ x2 + x3 ', 'robust', fx_2],  # (column 4)
[data1, 'y  ~ 1  + x1+ x2 + x4', ['fx1', 'fx2'], fx_2],  # (column 5)
[data2, 'y  ~ 1  + x1+ x2 + x3 + x4', ['fx1', 'fx2'], fx_3]  # (column 6)
]
outputDir = '/home/user/pystata'  # set the directory to save Stata output (log and results)
table = summary_col(reg_inputs)  # read regression specification
table.set_dir(outputDir)  # set the directory to save Stata output (log and results)
table.name = 'table_pystata'  # set the name of the table
table.modelname = ["Y1", "Y1", "Var", "Variable", "Model name", "Y", ]  # set the name for columns
table.order = ['x1', 'x2', 'x3', 'x4']  # Determine independent variables order
table._main_()  # transit data from python to Stata and write Stata do file accordingly
table.run_do()  # run Stata do file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pystata-0.0.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pystata-0.0.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file pystata-0.0.1.tar.gz.

File metadata

  • Download URL: pystata-0.0.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for pystata-0.0.1.tar.gz
Algorithm Hash digest
SHA256 cb1b138d84399f7260323f2b969a3137cf9d56f051073c889b8210f3ad28b81e
MD5 4a3d7c347e65b15e2d2ee810ca08e540
BLAKE2b-256 a034e8f9a77775d514a51c74e6fb44143f82934a912448d0f491f1f5feb0407c

See more details on using hashes here.

File details

Details for the file pystata-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pystata-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for pystata-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 69da499fb9a11a60fbfb657abf932b7f9981a7b01949e551172aec96f0b735d0
MD5 a0fcd47e316404ddcdf04879d04205be
BLAKE2b-256 d7980f53a1fea2eb07418465f534e536cc9167d79313261f3a8badcb3538059d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page