OLS Regression Skill
This skill provides comprehensive guidance for OLS regression and linear models in empirical research. It covers model specification, assumption testing, diagnostic checks, and result interpretation, with code examples in Python, R, and Stata.
Core Workflow
When assisting with OLS regression, follow this sequence:
- Clarify the research question and data — understand dependent variable, key regressors, and sample
- Specify the model — choose functional form, control variables, fixed effects if needed
- Run the regression — provide code in the user's preferred language
- Check assumptions — run diagnostics systematically (see references)
- Interpret and report — explain coefficients, significance, fit, and caveats
Key Concepts
Model Specification
- Write the regression equation explicitly: Y = β₀ + β₁X₁ + ... + βₖXₖ + ε
- Consider log transformations for skewed variables or elasticity interpretation
- Include relevant controls to reduce omitted variable bias
- Watch for irrelevant variables inflating standard errors
The Gauss-Markov Assumptions
- Linearity in parameters
- Random sampling
- No perfect multicollinearity
- Zero conditional mean of errors: E(ε|X) = 0
- Homoskedasticity: Var(ε|X) = σ²
- (For inference) Normally distributed errors
Violation of assumptions 4–5 does not bias OLS but affects standard errors. Violation of assumption 4 (endogeneity) biases estimates — recommend IV methods.
Standard Error Options
- Default OLS SE: valid only under homoskedasticity
- HC robust SE (White): use when heteroskedasticity is suspected; always safe for cross-section data
- Clustered SE: use when observations are grouped (e.g., by firm, region, year)
- Newey-West SE: use for time series with autocorrelation
Quick Code Templates
Python (statsmodels)
import statsmodels.api as sm
import statsmodels.formula.api as smf
# With robust standard errors
model = smf.ols('y ~ x1 + x2 + x3', data=df).fit(cov_type='HC3')
print(model.summary())
R
library(lmtest)
library(sandwich)
model <- lm(y ~ x1 + x2 + x3, data = df)
coeftest(model, vcov = vcovHC(model, type = "HC3"))
Stata
reg y x1 x2 x3, robust
Diagnostics Checklist
Run all diagnostics after fitting. See references/ols-reference.md for full test details.
| Issue |
Test |
Quick Fix |
| Heteroskedasticity |
Breusch-Pagan, White test |
Robust SE |
| Autocorrelation |
Durbin-Watson, Breusch-Godfrey |
Newey-West SE |
| Multicollinearity |
VIF > 10 |
Drop/combine variables |
| Non-normality of errors |
Jarque-Bera |
Check outliers; large N mitigates |
| Omitted variable bias |
Ramsey RESET |
Respecify model |
Reporting Standards (Academic)
- Report coefficients with standard errors in parentheses (or t-stats)
- Use asterisks for significance: * p<0.10, ** p<0.05, *** p<0.01
- Always state which standard errors are used (robust, clustered, etc.)
- Report R², adjusted R², N, and F-statistic
- Describe the identification strategy and potential endogeneity concerns
For detailed test formulas, code, and extended examples, see references/ols-reference.md.
Common Pitfalls
- Claiming causality without identification: OLS with controls does not establish causality — use IV, DID, or RDD for causal claims
- Using default SE with clustered data: Always cluster SE at the group level when observations are grouped
- Including "bad controls": Don't control for post-treatment variables (mediators) — they introduce collider bias
- Log-transforming variables with zeros: ln(0) is undefined; use asinh(x) or ln(x+1) with appropriate interpretation
- Reporting R² as evidence of a good model: High R² does not mean the model is correctly specified or causal
Related Skills & Commands
- panel-data: If your data has repeated observations on the same units
- iv-estimation: If you suspect endogeneity in your key regressor
- stats: Generate summary statistics before running regressions
- /diagnose: Run comprehensive diagnostic tests on your OLS model
- /robustness: Design robustness checks for your specifications
- /interpret: Get help interpreting regression output
- table: Format regression results for publication
1---2name: ols-regression3description: Econometrics skill for OLS regression and linear models. Activates when the user asks about: "run OLS", "linear regression", "ordinary least squares", "interpret regression results", "heteroskedasticity", "multicollinearity", "regression assumptions", "robust standard errors", "GLS", "WLS", "fit a regression model", "check regression diagnostics", "OLS假设", "最小二乘法", "线性回归", "回归系数", "残差检验", "异方差", "多重共线性", "普通最小二乘", "稳健标准误", "回归诊断"4---56# OLS Regression Skill78This skill provides comprehensive guidance for OLS regression and linear models in empirical research. It covers model specification, assumption testing, diagnostic checks, and result interpretation, with code examples in Python, R, and Stata.910## Core Workflow1112When assisting with OLS regression, follow this sequence:13141. **Clarify the research question and data** — understand dependent variable, key regressors, and sample152. **Specify the model** — choose functional form, control variables, fixed effects if needed163. **Run the regression** — provide code in the user's preferred language174. **Check assumptions** — run diagnostics systematically (see references)185. **Interpret and report** — explain coefficients, significance, fit, and caveats1920## Key Concepts2122### Model Specification23- Write the regression equation explicitly: Y = β₀ + β₁X₁ + ... + βₖXₖ + ε24- Consider log transformations for skewed variables or elasticity interpretation25- Include relevant controls to reduce omitted variable bias26- Watch for irrelevant variables inflating standard errors2728### The Gauss-Markov Assumptions291. Linearity in parameters302. Random sampling313. No perfect multicollinearity324. Zero conditional mean of errors: E(ε|X) = 0335. Homoskedasticity: Var(ε|X) = σ²346. (For inference) Normally distributed errors3536Violation of assumptions 4–5 does not bias OLS but affects standard errors. Violation of assumption 4 (endogeneity) biases estimates — recommend IV methods.3738### Standard Error Options39- **Default OLS SE**: valid only under homoskedasticity40- **HC robust SE (White)**: use when heteroskedasticity is suspected; always safe for cross-section data41- **Clustered SE**: use when observations are grouped (e.g., by firm, region, year)42- **Newey-West SE**: use for time series with autocorrelation4344## Quick Code Templates4546### Python (statsmodels)47```python48import statsmodels.api as sm49import statsmodels.formula.api as smf5051# With robust standard errors52model = smf.ols('y ~ x1 + x2 + x3', data=df).fit(cov_type='HC3')53print(model.summary())54```5556### R57```r58library(lmtest)59library(sandwich)6061model <- lm(y ~ x1 + x2 + x3, data = df)62coeftest(model, vcov = vcovHC(model, type = "HC3"))63```6465### Stata66```stata67reg y x1 x2 x3, robust68```6970## Diagnostics Checklist7172Run all diagnostics after fitting. See `references/ols-reference.md` for full test details.7374| Issue | Test | Quick Fix |75|-------|------|-----------|76| Heteroskedasticity | Breusch-Pagan, White test | Robust SE |77| Autocorrelation | Durbin-Watson, Breusch-Godfrey | Newey-West SE |78| Multicollinearity | VIF > 10 | Drop/combine variables |79| Non-normality of errors | Jarque-Bera | Check outliers; large N mitigates |80| Omitted variable bias | Ramsey RESET | Respecify model |8182## Reporting Standards (Academic)8384- Report coefficients with standard errors in parentheses (or t-stats)85- Use asterisks for significance: * p<0.10, ** p<0.05, *** p<0.0186- Always state which standard errors are used (robust, clustered, etc.)87- Report R², adjusted R², N, and F-statistic88- Describe the identification strategy and potential endogeneity concerns8990For detailed test formulas, code, and extended examples, see `references/ols-reference.md`.9192## Common Pitfalls9394- **Claiming causality without identification**: OLS with controls does not establish causality — use IV, DID, or RDD for causal claims95- **Using default SE with clustered data**: Always cluster SE at the group level when observations are grouped96- **Including "bad controls"**: Don't control for post-treatment variables (mediators) — they introduce collider bias97- **Log-transforming variables with zeros**: ln(0) is undefined; use asinh(x) or ln(x+1) with appropriate interpretation98- **Reporting R² as evidence of a good model**: High R² does not mean the model is correctly specified or causal99100## Related Skills & Commands101102- **panel-data**: If your data has repeated observations on the same units103- **iv-estimation**: If you suspect endogeneity in your key regressor104- **stats**: Generate summary statistics before running regressions105- **/diagnose**: Run comprehensive diagnostic tests on your OLS model106- **/robustness**: Design robustness checks for your specifications107- **/interpret**: Get help interpreting regression output108- **table**: Format regression results for publication