// SOLUTION
// 清除先前变量的内存
clear all
// 开启日志记录
cap log use
// 当数据过长时关闭more按钮,防止程序中断
set more off
*===========================*
// a. Automatically import the required data.  
// 导入Excel数据
import excel "Z:\Personal\MBA\课程\数据模型与决策 DMD\考试\CEO-Compensation.xlsx", sheet("DATA") firstrow
// // 删除第一行(Delete the 1st row)
// drop in 1 //我现在不需要删除第一行
// 改变为数据格式
destring, replace
// 数据预处理完毕
*===========================*
// b. Keep the first N listed companies from the file and drop the remaining listed companies.  
// (N is equal to the last two digits of your student id) 
// 我的学号是202120311006,后两位是06。但是样本量太小,拟合程度很差,所以在本do-file中直接使用所有样本进行拟合。
// keep in 1/54 // 保留前第1到第54行
*===========================*
// c. Check out the influence from the Var. Compensation to the Var. Returns  
// 利用简单回归命令,得到Compensation对Returns影响程度的回归拟合结果
reg Returnin2013 Compensationmillions
**=====假设条件的检验====**
// 提取相关变量
predict e, res
predict yhat, xb // 提取x的斜率b1
// // L-检验线性& E-检验同方差性:绘制残差e与X的散点图
// scatter e Compensationmillions, xtitle(Compensation)
// // I-检验独立性(略过)
// // N-检验正态性-残差分析:正态性拟合
// sort e
// qladder e
**=====假设条件的检验====**
// Y,X的散点图和直线拟合
scatter Returnin2013 Compensationmillions || lfit Returnin2013 Compensationmillions
// 修正方差(稳健的线性回归)
reg Returnin2013 Compensationmillions, r 
// 观测相关系数(检验线性)
corr Returnin2013 Compensationmillions
// *===========================*
// // d. Please explain the meaning of the regression results and give a conclusion. 
// // 回归结果的解读。
//
// 1. 通过假设条件的检验得知,本回归模型是有效的。
// 2. 通过F检验和t检验的结果得知,Compensation 与 Returns 之间存在线性关系。
// 3. 可决系数R-squared 较小(3.4%),回归模型对年销售额的预测能力很低。
// 4. 通过相关系数以及t检验值或者相应的p值得知,Compensation 对 Returns 在95%的置信水平下有显著正向影响。
// 5. 由于本回归模型的预测能力不足,可能需要考虑更有效的其他模型,从而实现更佳的拟合和预测。
//
// *===========================*