# PyOutreg
[](https://badge.fury.io/py/pyoutreg)
[](https://pypi.org/project/pyoutreg/)
[](https://opensource.org/licenses/MIT)
[](https://github.com/brycewang-stanford/pyoutreg)
[](https://pypi.org/project/pyoutreg/)
A Python implementation of Stata's popular `outreg2` command for exporting regression results to Excel and Word formats with publication-quality formatting.
## Features
- **Regression Export**: Export results from `statsmodels` and `linearmodels` to Excel (.xlsx) and Word (.docx)
- **Model Support**: OLS, Fixed Effects, Random Effects, Logit, Probit, IV, Panel Data
- **Professional Formatting**: Publication-ready tables with significance stars, standard errors
- **Model Comparison**: Side-by-side comparison of multiple models in single tables
- **Customization**: Extensive options for decimal places, variable selection, titles, notes
- **Summary Statistics**: Descriptive statistics and cross-tabulation export
- **Ecosystem Integration**: Part of the **statar** ecosystem for comprehensive Stata and R-like functionality in Python
- **Future-Ready**: Designed for seamless integration with **pdtab**, **pywinsor2**, **pyegen**, and other statistical tools
## Installation
```bash
pip install pyoutreg
```
## Related Packages
PyOutreg is part of a growing ecosystem of Python packages that bring Stata-like functionality to Python:
### [statar](https://github.com/brycewang-stanford/statar)
The **PyOutreg** library will be integrated into **statar**, a comprehensive Python package that provides Stata and R-like functionality in Python. statar aims to provide Stata users with familiar commands and workflows while leveraging Python's powerful data science ecosystem.
### [StasPAI](https://github.com/brycewang-stanford/StasPAI)
For users interested in AI-powered analysis, **StasPAI** offers a related project focused on integrating statistics, econometrics, machine learning, and LLMs/AI methods. StasPAI provides advanced analytical capabilities that combine traditional statistical methods with modern AI approaches.
## Integration with Broader Ecosystem
**PyOutreg** is part of a comprehensive statistical analysis ecosystem:
### [statar](https://github.com/brycewang-stanford/statar)
The **PyOutreg** library will be integrated into **statar**, a comprehensive Python package that provides Stata-like functionality in Python. statar aims to provide Stata users with familiar commands and workflows while leveraging Python's powerful data science ecosystem.
**Key Integration Features:**
- **Unified Command Interface**: PyOutreg's `outreg()` function will be accessible as `st.outreg()` within statar
- **Seamless Workflow**: Direct integration with statar's regression commands and data manipulation functions
- **Consistent Syntax**: Stata-like command structure for familiar user experience
- **Enhanced Functionality**: Combined with other statistical tools for comprehensive analysis
### [StasPAI](https://github.com/brycewang-stanford/StasPAI)
**StasPAI** is a related but independent project that focuses on integrating statistics, econometrics, machine learning, and LLMs/AI methods. It provides advanced analytical capabilities combining traditional statistical methods with modern AI approaches.
**Ecosystem Components:**
- **[statar](https://github.com/brycewang-stanford/statar)** - Main package integrating PyOutreg and other Stata-like tools
- **[pdtab](https://github.com/brycewang-stanford/pdtab)** - Pandas-based tabulation library for cross-tabulation and summary statistics
- **[pywinsor2](https://github.com/brycewang-stanford/pywinsor2)** - Winsorization and outlier treatment utilities
- **[pyegen](https://github.com/brycewang-stanford/pyegen)** - Data generation and variable creation tools
- **PyOutreg** - Regression table export functionality (this package)
- **[StasPAI](https://github.com/brycewang-stanford/StasPAI)** - AI-powered statistical analysis (related package)
### Future Integration Examples
```python
# Future statar integration
import statar as st
# Regression analysis with immediate export
st.regress('wage education experience age', data)
st.outreg('regression_results.xlsx', title="Wage Analysis")
# Combined workflow with integrated tools
st.summarize(data)
st.tabulate('gender region', data) # pdtab integration
st.winsor2('wage', data, p=[0.01, 0.99]) # pywinsor2 integration
st.egen('wage_group = cut(wage)', data) # pyegen integration
st.outreg_compare([model1, model2], 'comparison.xlsx')
```
## Quick Start
### Basic Regression Export
```python
import pandas as pd
import statsmodels.api as sm
from pyoutreg import outreg
# Load data and run regression
data = pd.read_csv('your_data.csv')
y = data['wage']
X = sm.add_constant(data[['education', 'experience', 'age']])
result = sm.OLS(y, X).fit()
# Export to Excel with professional formatting
outreg(result, 'regression_results.xlsx',
title="Wage Regression Analysis",
ctitle="OLS Model",
replace=True)
# Export to Word with custom notes
outreg(result, 'regression_results.docx',
title="Wage Regression Analysis",
addnote="Standard errors in parentheses. *** p<0.01, ** p<0.05, * p<0.1",
replace=True)
```
### Multiple Model Comparison
```python
from pyoutreg import outreg_compare
# Fit multiple models
X1 = sm.add_constant(data[['education']])
model1 = sm.OLS(y, X1).fit()
X2 = sm.add_constant(data[['education', 'experience']])
model2 = sm.OLS(y, X2).fit()
X3 = sm.add_constant(data[['education', 'experience', 'age']])
model3 = sm.OLS(y, X3).fit()
# Compare models side-by-side
outreg_compare(
[model1, model2, model3],
'model_comparison.xlsx',
model_names=['Basic', 'Add Experience', 'Full Model'],
title='Progressive Model Specification',
replace=True
)
```
### Panel Data Analysis
```python
import linearmodels.panel as lmp
# Prepare panel data
panel_data = data.set_index(['individual_id', 'year'])
# Fixed Effects Model
dependent = panel_data['wage']
exogenous = panel_data[['education', 'experience']]
fe_model = lmp.PanelOLS(dependent, exogenous, entity_effects=True)
fe_result = fe_model.fit(cov_type='clustered', cluster_entity=True)
# Random Effects Model
re_model = lmp.RandomEffects(dependent, exogenous)
re_result = re_model.fit()
# Compare panel models
outreg_compare(
[fe_result, re_result],
'panel_comparison.xlsx',
model_names=['Fixed Effects', 'Random Effects'],
title='Panel Data Model Comparison',
replace=True
)
```
### Logistic Regression with Odds Ratios
```python
# Binary outcome regression
y_binary = data['employed'] # 1=employed, 0=unemployed
X_logit = sm.add_constant(data[['education', 'experience', 'age']])
logit_model = sm.Logit(y_binary, X_logit)
logit_result = logit_model.fit()
# Export coefficients
outreg(logit_result, 'logit_coefficients.xlsx',
title="Employment Probability Analysis",
ctitle="Coefficients",
replace=True)
# Export odds ratios
outreg(logit_result, 'logit_odds_ratios.xlsx',
title="Employment Probability Analysis",
ctitle="Odds Ratios",
eform=True, # Convert to odds ratios
replace=True)
```
### Summary Statistics
```python
from pyoutreg import summary_stats
# Basic descriptive statistics
summary_stats(
data,
'summary_stats.xlsx',
variables=['wage', 'education', 'experience', 'age'],
title="Descriptive Statistics",
replace=True
)
# Grouped statistics
summary_stats(
data,
'grouped_stats.xlsx',
variables=['wage', 'education'],
by='gender', # Group by gender
title="Statistics by Gender",
replace=True
)
# Detailed statistics with percentiles
summary_stats(
data,
'detailed_stats.xlsx',
variables=['wage', 'education'],
detail=True, # Include percentiles, skewness, kurtosis
title="Detailed Descriptive Statistics",
replace=True
)
```
### Cross-tabulation
```python
from pyoutreg import cross_tab
# Cross-tabulation with counts and percentages
cross_tab(
data,
'gender', # Row variable
'region', # Column variable
'crosstab_gender_region.xlsx',
title="Gender by Region Cross-tabulation",
replace=True
)
```
### Advanced Customization
```python
# Extensive customization options
outreg(result, 'customized_output.xlsx',
replace=True,
title="Wage Regression with Custom Formatting",
ctitle="Full Model",
# Decimal control
dec=3, # Overall decimal places
bdec=4, # Coefficient decimal places
sdec=5, # Standard error decimal places
# Variable selection
keep=['education', 'experience'], # Only show these variables
# drop=['age'], # Alternative: drop specific variables
# Additional statistics
addstat={
'Mean Wage': data['wage'].mean(),
'Sample Size': len(data),
'Data Period': '2010-2020'
},
# Notes and formatting
addnote="Robust standard errors. Data from national survey.",
font_size=12
)
```
## API Reference
### Main Functions
#### `outreg(model_result, filename, **options)`
Export single regression model to Excel or Word.
**Parameters:**
- `model_result`: Fitted regression model (statsmodels or linearmodels)
- `filename`: Output filename (.xlsx or .docx) or None for preview
- `ctitle`: Column title for the model
- `title`: Table title
- `replace`: Replace existing file (default: False)
- `append`: Append to existing file (default: False)
- `dec/bdec/sdec`: Decimal places for overall/coefficients/standard errors
- `keep/drop`: Variable selection
- `addstat`: Dictionary of additional statistics
- `addnote`: Custom notes
- `eform`: Export odds ratios for logistic regression
#### `outreg_compare(models_list, filename, **options)`
Compare multiple models side-by-side.
**Parameters:**
- `models_list`: List of fitted regression models
- `filename`: Output filename or None for preview
- `model_names`: List of model names
- `title`: Table title
- Other options same as `outreg`
#### `summary_stats(data, filename, **options)`
Export descriptive statistics.
**Parameters:**
- `data`: pandas DataFrame
- `filename`: Output filename or None for preview
- `variables`: List of variables to include
- `by`: Grouping variable
- `detail`: Include percentiles and distribution statistics
#### `cross_tab(data, row_var, col_var, filename, **options)`
Export cross-tabulation table.
**Parameters:**
- `data`: pandas DataFrame
- `row_var`: Row variable name
- `col_var`: Column variable name
- `filename`: Output filename or None for preview
## Output Examples
### Regression Table Output
```
Variable Model 1 Model 2 Model 3
education 482.135*** 462.891*** 458.023***
(24.726) (25.018) (25.134)
experience 301.274*** 287.345***
(18.642) (19.123)
age 156.789***
(12.456)
Constant 15234.567*** 12845.321*** 11234.789***
(387.234) (425.178) (456.234)
Observations 1,000 1,000 1,000
R-squared 0.234 0.287 0.312
F-statistic 152.34 189.45 167.23
*** p<0.01, ** p<0.05, * p<0.1
```

### Summary Statistics Output
```
Variable Obs Mean Std. Dev. Min Max
wage 1,000 45,234.56 12,456.78 15,000 120,000
education 1,000 15.8 2.4 8 25
experience 1,000 12.3 8.9 0 40
age 1,000 35.2 10.1 18 65
```
## Integration with statar
PyOutreg is designed to be integrated into the **statar** package, which aims to provide comprehensive Stata-like functionality in Python. As part of the broader statistical ecosystem, PyOutreg will work seamlessly with other Stata-like tools:
```python
# Future integration (planned)
import statar as st
# Direct regression analysis and export
st.regress('wage education experience age', data)
st.outreg('wage_analysis.xlsx', title="Wage Regression Results")
# Summary statistics and cross-tabulation
st.summarize(data, by='gender')
st.tabulate('education region', data)
# Advanced model comparison workflow
model1 = st.regress('wage education', data)
model2 = st.regress('wage education experience', data)
model3 = st.regress('wage education experience age', data)
st.outreg_compare([model1, model2, model3],
'progressive_models.xlsx',
model_names=['Basic', 'Add Experience', 'Full Model'])
# Integration with other ecosystem tools
st.pdtab.crosstab(data, 'gender', 'region') # pdtab integration
st.winsor2('wage', data, p=[0.01, 0.99]) # pywinsor2 integration
st.egen('wage_decile = xtile(wage)', data) # pyegen integration
st.summary_stats(data, detail=True) # PyOutreg functionality
```
**Integrated Ecosystem Benefits:**
- **Unified Interface**: Single import for all Stata-like functionality
- **Seamless Workflow**: No need to switch between different packages
- **Consistent Documentation**: Integrated help system and examples
- **Enhanced Performance**: Optimized integration between components
**Related Projects in the Ecosystem:**
- **[statar](https://github.com/brycewang-stanford/statar)**: Main integration package providing Stata-like functionality
- **[pdtab](https://github.com/brycewang-stanford/pdtab)**: Pandas-based tabulation library for statistical summaries
- **[pywinsor2](https://github.com/brycewang-stanford/pywinsor2)**: Winsorization and outlier treatment utilities
- **[pyegen](https://github.com/brycewang-stanford/pyegen)**: Data generation and variable creation tools
- **PyOutreg**: Regression table export (this package)
**Related but Independent:**
- **[StasPAI](https://github.com/brycewang-stanford/StasPAI)**: AI-powered statistical analysis combining traditional methods with machine learning and LLMs
## Documentation
For comprehensive documentation and more examples:
- **Tutorial**: See `tutorial.ipynb` for a complete walkthrough
- **Examples**: Check the `examples/` directory for specific use cases
- **API Reference**: Detailed function documentation
- **Tests**: `tests/` directory contains validation examples
## 🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
## 📄 License
MIT License
Copyright (c) 2025 Bryce Wang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Raw data
{
"_id": null,
"home_page": null,
"name": "pyoutreg",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "Bryce Wang <brycew6m@stanford.edu>",
"keywords": "regression, statistics, stata, econometrics, export, excel, word, tables, outreg",
"author": null,
"author_email": "Bryce Wang <brycew6m@stanford.edu>",
"download_url": "https://files.pythonhosted.org/packages/f7/bb/63f0c7274ddf976e0c2b828edf7ccab5900bb18051e9f6604649cac51e55/pyoutreg-0.1.1.tar.gz",
"platform": null,
"description": "# PyOutreg\n\n[](https://badge.fury.io/py/pyoutreg)\n[](https://pypi.org/project/pyoutreg/)\n[](https://opensource.org/licenses/MIT)\n[](https://github.com/brycewang-stanford/pyoutreg)\n[](https://pypi.org/project/pyoutreg/)\n\nA Python implementation of Stata's popular `outreg2` command for exporting regression results to Excel and Word formats with publication-quality formatting.\n\n## Features\n\n- **Regression Export**: Export results from `statsmodels` and `linearmodels` to Excel (.xlsx) and Word (.docx)\n- **Model Support**: OLS, Fixed Effects, Random Effects, Logit, Probit, IV, Panel Data\n- **Professional Formatting**: Publication-ready tables with significance stars, standard errors\n- **Model Comparison**: Side-by-side comparison of multiple models in single tables\n- **Customization**: Extensive options for decimal places, variable selection, titles, notes\n- **Summary Statistics**: Descriptive statistics and cross-tabulation export\n- **Ecosystem Integration**: Part of the **statar** ecosystem for comprehensive Stata and R-like functionality in Python\n- **Future-Ready**: Designed for seamless integration with **pdtab**, **pywinsor2**, **pyegen**, and other statistical tools\n\n## Installation\n\n```bash\npip install pyoutreg\n```\n\n## Related Packages\n\nPyOutreg is part of a growing ecosystem of Python packages that bring Stata-like functionality to Python:\n\n### [statar](https://github.com/brycewang-stanford/statar)\nThe **PyOutreg** library will be integrated into **statar**, a comprehensive Python package that provides Stata and R-like functionality in Python. statar aims to provide Stata users with familiar commands and workflows while leveraging Python's powerful data science ecosystem.\n\n### [StasPAI](https://github.com/brycewang-stanford/StasPAI)\nFor users interested in AI-powered analysis, **StasPAI** offers a related project focused on integrating statistics, econometrics, machine learning, and LLMs/AI methods. StasPAI provides advanced analytical capabilities that combine traditional statistical methods with modern AI approaches.\n\n## Integration with Broader Ecosystem\n\n**PyOutreg** is part of a comprehensive statistical analysis ecosystem:\n\n### [statar](https://github.com/brycewang-stanford/statar)\nThe **PyOutreg** library will be integrated into **statar**, a comprehensive Python package that provides Stata-like functionality in Python. statar aims to provide Stata users with familiar commands and workflows while leveraging Python's powerful data science ecosystem.\n\n**Key Integration Features:**\n- **Unified Command Interface**: PyOutreg's `outreg()` function will be accessible as `st.outreg()` within statar\n- **Seamless Workflow**: Direct integration with statar's regression commands and data manipulation functions\n- **Consistent Syntax**: Stata-like command structure for familiar user experience\n- **Enhanced Functionality**: Combined with other statistical tools for comprehensive analysis\n\n### [StasPAI](https://github.com/brycewang-stanford/StasPAI)\n**StasPAI** is a related but independent project that focuses on integrating statistics, econometrics, machine learning, and LLMs/AI methods. It provides advanced analytical capabilities combining traditional statistical methods with modern AI approaches.\n\n**Ecosystem Components:**\n- **[statar](https://github.com/brycewang-stanford/statar)** - Main package integrating PyOutreg and other Stata-like tools\n- **[pdtab](https://github.com/brycewang-stanford/pdtab)** - Pandas-based tabulation library for cross-tabulation and summary statistics\n- **[pywinsor2](https://github.com/brycewang-stanford/pywinsor2)** - Winsorization and outlier treatment utilities\n- **[pyegen](https://github.com/brycewang-stanford/pyegen)** - Data generation and variable creation tools\n- **PyOutreg** - Regression table export functionality (this package)\n- **[StasPAI](https://github.com/brycewang-stanford/StasPAI)** - AI-powered statistical analysis (related package)\n\n### Future Integration Examples\n```python\n# Future statar integration\nimport statar as st\n\n# Regression analysis with immediate export\nst.regress('wage education experience age', data)\nst.outreg('regression_results.xlsx', title=\"Wage Analysis\")\n\n# Combined workflow with integrated tools\nst.summarize(data)\nst.tabulate('gender region', data) # pdtab integration\nst.winsor2('wage', data, p=[0.01, 0.99]) # pywinsor2 integration\nst.egen('wage_group = cut(wage)', data) # pyegen integration\nst.outreg_compare([model1, model2], 'comparison.xlsx')\n```\n\n## Quick Start\n\n### Basic Regression Export\n\n```python\nimport pandas as pd\nimport statsmodels.api as sm\nfrom pyoutreg import outreg\n\n# Load data and run regression\ndata = pd.read_csv('your_data.csv')\ny = data['wage']\nX = sm.add_constant(data[['education', 'experience', 'age']])\nresult = sm.OLS(y, X).fit()\n\n# Export to Excel with professional formatting\noutreg(result, 'regression_results.xlsx', \n title=\"Wage Regression Analysis\",\n ctitle=\"OLS Model\",\n replace=True)\n\n# Export to Word with custom notes\noutreg(result, 'regression_results.docx',\n title=\"Wage Regression Analysis\", \n addnote=\"Standard errors in parentheses. *** p<0.01, ** p<0.05, * p<0.1\",\n replace=True)\n```\n\n### Multiple Model Comparison\n\n```python\nfrom pyoutreg import outreg_compare\n\n# Fit multiple models\nX1 = sm.add_constant(data[['education']])\nmodel1 = sm.OLS(y, X1).fit()\n\nX2 = sm.add_constant(data[['education', 'experience']])\nmodel2 = sm.OLS(y, X2).fit()\n\nX3 = sm.add_constant(data[['education', 'experience', 'age']])\nmodel3 = sm.OLS(y, X3).fit()\n\n# Compare models side-by-side\noutreg_compare(\n [model1, model2, model3],\n 'model_comparison.xlsx',\n model_names=['Basic', 'Add Experience', 'Full Model'],\n title='Progressive Model Specification',\n replace=True\n)\n```\n\n### Panel Data Analysis\n\n```python\nimport linearmodels.panel as lmp\n\n# Prepare panel data\npanel_data = data.set_index(['individual_id', 'year'])\n\n# Fixed Effects Model\ndependent = panel_data['wage']\nexogenous = panel_data[['education', 'experience']]\n\nfe_model = lmp.PanelOLS(dependent, exogenous, entity_effects=True)\nfe_result = fe_model.fit(cov_type='clustered', cluster_entity=True)\n\n# Random Effects Model \nre_model = lmp.RandomEffects(dependent, exogenous)\nre_result = re_model.fit()\n\n# Compare panel models\noutreg_compare(\n [fe_result, re_result],\n 'panel_comparison.xlsx',\n model_names=['Fixed Effects', 'Random Effects'],\n title='Panel Data Model Comparison',\n replace=True\n)\n```\n\n### Logistic Regression with Odds Ratios\n\n```python\n# Binary outcome regression\ny_binary = data['employed'] # 1=employed, 0=unemployed\nX_logit = sm.add_constant(data[['education', 'experience', 'age']])\n\nlogit_model = sm.Logit(y_binary, X_logit)\nlogit_result = logit_model.fit()\n\n# Export coefficients\noutreg(logit_result, 'logit_coefficients.xlsx',\n title=\"Employment Probability Analysis\",\n ctitle=\"Coefficients\",\n replace=True)\n\n# Export odds ratios\noutreg(logit_result, 'logit_odds_ratios.xlsx',\n title=\"Employment Probability Analysis\",\n ctitle=\"Odds Ratios\",\n eform=True, # Convert to odds ratios\n replace=True)\n```\n\n### Summary Statistics\n\n```python\nfrom pyoutreg import summary_stats\n\n# Basic descriptive statistics\nsummary_stats(\n data,\n 'summary_stats.xlsx',\n variables=['wage', 'education', 'experience', 'age'],\n title=\"Descriptive Statistics\",\n replace=True\n)\n\n# Grouped statistics\nsummary_stats(\n data,\n 'grouped_stats.xlsx', \n variables=['wage', 'education'],\n by='gender', # Group by gender\n title=\"Statistics by Gender\",\n replace=True\n)\n\n# Detailed statistics with percentiles\nsummary_stats(\n data,\n 'detailed_stats.xlsx',\n variables=['wage', 'education'],\n detail=True, # Include percentiles, skewness, kurtosis\n title=\"Detailed Descriptive Statistics\",\n replace=True\n)\n```\n\n### Cross-tabulation\n\n```python\nfrom pyoutreg import cross_tab\n\n# Cross-tabulation with counts and percentages\ncross_tab(\n data,\n 'gender', # Row variable\n 'region', # Column variable \n 'crosstab_gender_region.xlsx',\n title=\"Gender by Region Cross-tabulation\",\n replace=True\n)\n```\n\n### Advanced Customization\n\n```python\n# Extensive customization options\noutreg(result, 'customized_output.xlsx',\n replace=True,\n title=\"Wage Regression with Custom Formatting\",\n ctitle=\"Full Model\",\n \n # Decimal control\n dec=3, # Overall decimal places\n bdec=4, # Coefficient decimal places\n sdec=5, # Standard error decimal places\n \n # Variable selection\n keep=['education', 'experience'], # Only show these variables\n # drop=['age'], # Alternative: drop specific variables\n \n # Additional statistics\n addstat={\n 'Mean Wage': data['wage'].mean(),\n 'Sample Size': len(data),\n 'Data Period': '2010-2020'\n },\n \n # Notes and formatting\n addnote=\"Robust standard errors. Data from national survey.\",\n font_size=12\n)\n\n```\n\n## API Reference\n\n### Main Functions\n\n#### `outreg(model_result, filename, **options)`\nExport single regression model to Excel or Word.\n\n**Parameters:**\n- `model_result`: Fitted regression model (statsmodels or linearmodels)\n- `filename`: Output filename (.xlsx or .docx) or None for preview\n- `ctitle`: Column title for the model\n- `title`: Table title\n- `replace`: Replace existing file (default: False)\n- `append`: Append to existing file (default: False)\n- `dec/bdec/sdec`: Decimal places for overall/coefficients/standard errors\n- `keep/drop`: Variable selection\n- `addstat`: Dictionary of additional statistics\n- `addnote`: Custom notes\n- `eform`: Export odds ratios for logistic regression\n\n#### `outreg_compare(models_list, filename, **options)`\nCompare multiple models side-by-side.\n\n**Parameters:**\n- `models_list`: List of fitted regression models\n- `filename`: Output filename or None for preview\n- `model_names`: List of model names\n- `title`: Table title\n- Other options same as `outreg`\n\n#### `summary_stats(data, filename, **options)`\nExport descriptive statistics.\n\n**Parameters:**\n- `data`: pandas DataFrame\n- `filename`: Output filename or None for preview\n- `variables`: List of variables to include\n- `by`: Grouping variable\n- `detail`: Include percentiles and distribution statistics\n\n#### `cross_tab(data, row_var, col_var, filename, **options)`\nExport cross-tabulation table.\n\n**Parameters:**\n- `data`: pandas DataFrame\n- `row_var`: Row variable name\n- `col_var`: Column variable name\n- `filename`: Output filename or None for preview\n\n## Output Examples\n\n### Regression Table Output\n```\n Variable Model 1 Model 2 Model 3\n education 482.135*** 462.891*** 458.023***\n (24.726) (25.018) (25.134)\n experience 301.274*** 287.345***\n (18.642) (19.123)\n age 156.789***\n (12.456)\n Constant 15234.567*** 12845.321*** 11234.789***\n (387.234) (425.178) (456.234)\n \n Observations 1,000 1,000 1,000\n R-squared 0.234 0.287 0.312\n F-statistic 152.34 189.45 167.23\n*** p<0.01, ** p<0.05, * p<0.1\n```\n\n\n### Summary Statistics Output\n```\nVariable Obs Mean Std. Dev. Min Max\nwage 1,000 45,234.56 12,456.78 15,000 120,000\neducation 1,000 15.8 2.4 8 25\nexperience 1,000 12.3 8.9 0 40\nage 1,000 35.2 10.1 18 65\n```\n\n## Integration with statar\n\nPyOutreg is designed to be integrated into the **statar** package, which aims to provide comprehensive Stata-like functionality in Python. As part of the broader statistical ecosystem, PyOutreg will work seamlessly with other Stata-like tools:\n\n```python\n# Future integration (planned)\nimport statar as st\n\n# Direct regression analysis and export\nst.regress('wage education experience age', data)\nst.outreg('wage_analysis.xlsx', title=\"Wage Regression Results\")\n\n# Summary statistics and cross-tabulation\nst.summarize(data, by='gender')\nst.tabulate('education region', data)\n\n# Advanced model comparison workflow\nmodel1 = st.regress('wage education', data)\nmodel2 = st.regress('wage education experience', data) \nmodel3 = st.regress('wage education experience age', data)\n\nst.outreg_compare([model1, model2, model3], \n 'progressive_models.xlsx',\n model_names=['Basic', 'Add Experience', 'Full Model'])\n\n# Integration with other ecosystem tools\nst.pdtab.crosstab(data, 'gender', 'region') # pdtab integration\nst.winsor2('wage', data, p=[0.01, 0.99]) # pywinsor2 integration\nst.egen('wage_decile = xtile(wage)', data) # pyegen integration\nst.summary_stats(data, detail=True) # PyOutreg functionality\n```\n\n**Integrated Ecosystem Benefits:**\n- **Unified Interface**: Single import for all Stata-like functionality\n- **Seamless Workflow**: No need to switch between different packages\n- **Consistent Documentation**: Integrated help system and examples\n- **Enhanced Performance**: Optimized integration between components\n\n**Related Projects in the Ecosystem:**\n- **[statar](https://github.com/brycewang-stanford/statar)**: Main integration package providing Stata-like functionality\n- **[pdtab](https://github.com/brycewang-stanford/pdtab)**: Pandas-based tabulation library for statistical summaries\n- **[pywinsor2](https://github.com/brycewang-stanford/pywinsor2)**: Winsorization and outlier treatment utilities\n- **[pyegen](https://github.com/brycewang-stanford/pyegen)**: Data generation and variable creation tools\n- **PyOutreg**: Regression table export (this package)\n\n**Related but Independent:**\n- **[StasPAI](https://github.com/brycewang-stanford/StasPAI)**: AI-powered statistical analysis combining traditional methods with machine learning and LLMs\n\n## Documentation\n\nFor comprehensive documentation and more examples:\n\n- **Tutorial**: See `tutorial.ipynb` for a complete walkthrough\n- **Examples**: Check the `examples/` directory for specific use cases\n- **API Reference**: Detailed function documentation\n- **Tests**: `tests/` directory contains validation examples\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## \ud83d\udcc4 License\n\nMIT License\n\nCopyright (c) 2025 Bryce Wang\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",
"bugtrack_url": null,
"license": null,
"summary": "A Python implementation of Stata's outreg2 for exporting regression results",
"version": "0.1.1",
"project_urls": {
"Bug Tracker": "https://github.com/brycewang-stanford/pyoutreg/issues",
"Changelog": "https://github.com/brycewang-stanford/pyoutreg/blob/main/CHANGELOG.md",
"Documentation": "https://github.com/brycewang-stanford/pyoutreg/blob/main/README.md",
"Homepage": "https://github.com/brycewang-stanford/pyoutreg",
"Repository": "https://github.com/brycewang-stanford/pyoutreg"
},
"split_keywords": [
"regression",
" statistics",
" stata",
" econometrics",
" export",
" excel",
" word",
" tables",
" outreg"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "a86eca55c9fe9d867b28b200e6e2fa16f9d81b9ac7f87fe6249b34d504e5bb39",
"md5": "4319d29746f7dfb4db359760280d6d9a",
"sha256": "fceb0290684fa19621f69a4a14818f1a8fcb319bb8154a30a09e6ca7a2e2959e"
},
"downloads": -1,
"filename": "pyoutreg-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4319d29746f7dfb4db359760280d6d9a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 26741,
"upload_time": "2025-08-02T00:05:32",
"upload_time_iso_8601": "2025-08-02T00:05:32.645738Z",
"url": "https://files.pythonhosted.org/packages/a8/6e/ca55c9fe9d867b28b200e6e2fa16f9d81b9ac7f87fe6249b34d504e5bb39/pyoutreg-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "f7bb63f0c7274ddf976e0c2b828edf7ccab5900bb18051e9f6604649cac51e55",
"md5": "59c10d731d2f24dddb5418889c492f6e",
"sha256": "a8fdcf0a8f8fb5853a316a6afa8c309422bc2d309cd093b7be5db5f0300683f6"
},
"downloads": -1,
"filename": "pyoutreg-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "59c10d731d2f24dddb5418889c492f6e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 30399,
"upload_time": "2025-08-02T00:05:34",
"upload_time_iso_8601": "2025-08-02T00:05:34.034747Z",
"url": "https://files.pythonhosted.org/packages/f7/bb/63f0c7274ddf976e0c2b828edf7ccab5900bb18051e9f6604649cac51e55/pyoutreg-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-02 00:05:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "brycewang-stanford",
"github_project": "pyoutreg",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "pandas",
"specs": [
[
">=",
"1.3.0"
]
]
},
{
"name": "numpy",
"specs": [
[
">=",
"1.20.0"
]
]
},
{
"name": "statsmodels",
"specs": [
[
">=",
"0.12.0"
]
]
},
{
"name": "linearmodels",
"specs": [
[
">=",
"4.25"
]
]
},
{
"name": "openpyxl",
"specs": [
[
">=",
"3.0.0"
]
]
},
{
"name": "python-docx",
"specs": [
[
">=",
"0.8.11"
]
]
},
{
"name": "scipy",
"specs": [
[
">=",
"1.7.0"
]
]
}
],
"lcname": "pyoutreg"
}