-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample-7-8.py
More file actions
36 lines (29 loc) · 1.18 KB
/
Copy pathExample-7-8.py
File metadata and controls
36 lines (29 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import wooldridge as woo
import numpy as np
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
lawsch85 = woo.dataWoo('lawsch85')
# define cut points for the rank:
cutpts = [0, 10, 25, 40, 60, 100, 175]
# create categorical variable containing ranges for the rank:
lawsch85['rc'] = pd.cut(lawsch85['rank'], bins=cutpts,
labels=['(0,10]', '(10,25]', '(25,40]',
'(40,60]', '(60,100]', '(100,175]'])
# display frequencies:
freq = pd.crosstab(lawsch85['rc'], columns='count')
print(f'freq: \n{freq}\n')
# run regression:
reg = smf.ols(formula='np.log(salary) ~ C(rc, Treatment("(100,175]")) +'
'LSAT + GPA + np.log(libvol) + np.log(cost)',
data=lawsch85)
results = reg.fit()
# print regression table:
table_reg = pd.DataFrame({'b': round(results.params, 4),
'se': round(results.bse, 4),
't': round(results.tvalues, 4),
'pval': round(results.pvalues, 4)})
print(f'table_reg: \n{table_reg}\n')
# ANOVA table:
table_anova = sm.stats.anova_lm(results, typ=2)
print(f'table_anova: \n{table_anova}\n')