伍德里奇计量经济学导论计算机习题第六章第13题c - 6.13

clear,clc; % c6.13 by

% 打开文字文件和数据文件 importdata('meap00_01.des'); data=xlsread('meap00_01');

% 检验所用数据是否为非空 Isnan=isnan(data(:,[3,5,8,9])); a=sum(Isnan')'; b=find(a==0); data1=data(b,:);

% 变量命名

math4=data1(:,3); lunch=data1(:,5); lenroll=data1(:,8); lexppp=data1(:,9);

% OLS估计

result1=ols(math4,[ones(length(math4),1),lunch,lenroll,lexppp]); vnames=char('math4','constant','lunch','lenroll','lexppp'); prt(result1,vnames)

% 回归结果

% Ordinary Least-squares Estimates

% Dependent Variable = math4 % R-squared = 0.3729 % Rbar-squared = 0.3718 % sigma^2 = 234.1638 % Durbin-Watson = 1.7006 % Nobs, Nvars = 1692, 4

% *************************************************************** % Variable Coefficient t-statistic t-probability

% constant 91.932484 4.605444 0.000004 % lunch -0.448743 -30.647631 0.000000 % lenroll -5.399153 -5.741265 0.000000 % lexppp 3.524742 1.680172 0.093109

% 由回归结果中的p值发现lunch,lenroll是在5%的水平上显著的,而lexppp在5%水平上不显著,

% 但在10%的显著水平上是显著的.

% 求出回归的拟合值及其取值范围

yhat=result1.yhat; std_yhat=std(yhat);

mean_yhat=mean(yhat);

yhat_qujian=[mean_yhat-2*std_yhat,mean_yhat+2*std_yhat] % yhat的取值范围是(49.1090 ,96.2665)

% 求出math4的实际取值范围

math4_qujian=[min(math4),max(math4)]

% math4的实际取值范围是(0 ,100),可见拟合值的取值范围要比实际范围窄

% 求出回归残差 resid=result1.resid; max_resid=max(resid);

row=find(resid==max_resid) school_code=data1(row,2)

% 学校类型是school_code=1141,说明该学校的实际数学考试通过率要比估计的数学考试通 % 过率高很多,也就这所学校的数学教学质量较高

% 求取解释变量数据的平方项 lenroll2=lenroll.^2; lexppp2=lexppp.^2; lunch2=lunch.^2;

%在方程中加入所有解释变量的平方项进行回归

result2=ols(math4,[ones(length(math4),1),lunch,lenroll,lexppp,lunch2,lenroll2,lexppp2]); vnames=char('math4','constant','lunch','lenroll','lexppp','lunch2','lenroll2','lexppp2'); prt(result2,vnames)

% 检验联合显著性 rsqr1=result1.rsqr; rsqr2=result2.rsqr;

F=((rsqr2-rsqr1)/3)/((1-rsqr2)/(1692-6-1)) p=1-fcdf(F,3,1685) % F =0.5180 % p =0.6699

% 所以这几个解释变量的平方项是联合不显著的,所以不应该把他们放到模型中

% 求所用数据值除以其标准差 lenroll_new=lenroll/std(lenroll); lunch_new=lunch/std(lunch); lexppp_new=lexppp/std(lexppp); math4_new=math4/std(math4);

% 重新进行回归

result3=ols(math4_new,[ones(length(math4_new),1),lunch_new,lenroll_new,lexppp_new]); vnames=char('math4_new','constant','lunch_new','lenroll_new','lexppp_new'); prt(result3,vnames)

% 回归结果

% Ordinary Least-squares Estimates

% Dependent Variable = math4_new % R-squared = 0.3729 % Rbar-squared = 0.3718 % sigma^2 = 0.6282 % Durbin-Watson = 1.7006 % Nobs, Nvars = 1692, 4

% *************************************************************** % Variable Coefficient t-statistic t-probability

% constant 4.761759 4.605444 0.000004 % lunch_new -0.612853 -30.647631 0.000000 % lenroll_new -0.114620 -5.741265 0.000000 % lexppp_new 0.034743 1.680172 0.093109

% 由结果lunch,lenroll和lexppp分别提高一倍,会使数学通过率分别变化0.613,0.115和 % 0.035个标准差,所以lunch对数学考试通过率影响最大

联系客服:779662525#qq.com(#替换为@)