例子:Probit模型与Logit模型的估计
代码部分
# lec09
# 计量实验6:定性相应模型-代码部分
# 导入程序包
import pandas as pd
import statsmodels.api as sm
import ssl
# 禁用SSL证书校验
ssl._create_default_https_context = ssl._create_unverified_context
# 导入(在线)数据
df = pd.read_excel(r"https://cdn.seit2019.xyz/data/econometrics/table15.7.xlsx")
# 展示数据
print("数据展示如下:")
print(df, "\n")
# 简要统计描述
print("简要统计描述:")
print(df.describe(), "\n")
# 定义变量
grade = df["GRADE"]
x = df[["GPA", "TUCE", "PSI"]]
X = sm.add_constant(x)
# 线性概率模型(LPM)
print("线性概率模型(LPM):")
OLS_LPM = sm.OLS(grade, X).fit()
print(OLS_LPM.summary(), "\n")
# Probit模型
print("Logit模型:")
Logit_model = sm.Logit(grade, X).fit()
print(Logit_model.summary(), "\n")
# Logit模型
print("Probit模型:")
Probit_model = sm.Probit(grade, X).fit()
print(Probit_model.summary(), "\n")