2012年本科计量经济学实验上机手册学生版(为李子奈编写的计量经济学第二版中例题的SAS程序)

更新时间:2023-12-04 21:35:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

附页:上机手册

实验一 一元线性回归模型的参数估计和统计检验

模型:1978-2000年中国人均居民消费支出(CONSP)对人均GDP(GDPP)的回归; run;

proc print data=caizheng; title ‘caizheng’; run;

分析

CONSP?C???GDPP??

程序:(一) data china;

input year CONSP GDPP @@; cards;

数据行(自己输入) ; run;

proc print data=china; title ‘china’; run;

/*proc gplot data=china; symbol v=plus i=join; plot CONSP*GDPP; run; */

proc reg data=china; model CONSP=GDPP; title ‘china’; run;

程序 (二)P54页习题11数据 data caizheng;

input year Y GDP @@; cards;

数据行(自己输入)

/*proc gplot data= caizheng; symbol v=plus i=join; plot Y*GDP; run; */

proc reg data= caizheng; model Y=GDP; title ‘caizheng’; run;

实验二 多元线性回归模型的参数估计和统计检验

程序(一)课本P77页表3.5.1数据,分别估计课本中P78页式子(3.5.18)和P80页中式子(3.5.19)(注意:这里只采用了1981-1994的数据): data xiaofei;

input year XC1990 Q1990 P01990 P11990 @@; cards;

数据行(自己输入) ; run;

proc print data=xiaofei;

title‘中国城镇居民人均消费支出’;

run;

data xiaofei2;

1

set xiaofei; lnQ=log(Q1990); lnX=log(XC1990); lnP0=log(P01990); lnP1=log(P11990); x1=XC1990/P01990; y1=P11990/P01990; lnXP0=log(x1); lnP1P0=log(y1); run;

proc reg data=xiaofei2; model lnQ=lnX lnP1 lnP0/DW; title ‘模型3.5.18’; run;

proc reg data=xiaofei2; model lnQ=lnXP0 lnP1P0/DW; title ‘模型3.5.19’; run;

data zhizhao2; set zhizhao; lnY=log(Y); lnK=log(K); lnL=log(L); run;

proc print data=zhizhao2; title ‘zhizhao2’; run;

proc reg data=zhizhao2; model lnY=lnK lnL;

print cli;/*可得95%的置信区间及相对误差值*/ run;

data zhizhao3;

set zhizhao2(keep=Y lnY lnK lnL); lnYY=1.15397+0.60925*lnK+0.36078*lnL;

?/* 即为lnY??0??1*ln K??2*lLn*/

程序(二)课本P92页习题11数据,模型为对数线性模型: data zhizhao; input number Y K L@@; cards;

数据行(自己输入) ; run;

proc print data=zhizhao;

title ‘中国2000年的制造业总体规模’; run;

?lnY?YY=exp(lnYY); /* 即为Y?e */

?aa=Y-YY; /* 即为(Y?Y) */

Yresid=aa/Y; /* 即为(Y?Y)/Y */ proc print data=zhizhao3; title ‘简单拟合’; run;

data zhizhao4; set zhizhao3;

keep Y lnYY YY Yresid; proc print data=zhizhao4; run;

? 2

data zhizhao5; set zhizhao; a=Y/L; lnYL=log(a); b=K/L; lnKL=log(b); run;

proc print data=zhizhao5; title ‘zhizhao5’; run;

proc reg data=zhizhao5; model lnYL=lnKL; run;

实验三 异方差模型的检验和处理 程序(一)课本P101页表4.1.1数据:data nongcun;

input diqu $ Y X1 X2 @@; cards4;

数据行(自己输入) ;;;; run;

proc print data=nongcun; title ‘中国农村居民人均消费’; run;

data nongcun2; set nongcun; lnY=log(Y); lnX1=log(X1); lnX1X1=lnX1*lnX1; lnX2=log(X2);

lnX2X2=lnX2*lnX2; lnX1X2= lnX1*lnX2; run;

proc reg data=nongcun2; model lnY=lnX1 lnX2; title ‘nongcun2’; run;

data nongcun3; set nongcun2;

e=lnY-(1.60258+0.32541*lnX1+0.50708*lnX2); e1=abs(e); e2=e*e; run;

/*proc gplot data=nongcun3; symbol v=plus i=jion; plot e2*lnX2; run;*/

proc reg data=nongcun3; model e1=lnX1 lnX2;

title ‘用戈里瑟法检验异方差’; run;

proc reg data=nongcun3; model e1=X1 X2;

title ‘用戈里瑟法检验异方差1’; run;

proc reg data=nongcun3;

model e2=lnX1 lnX1X1 lnX2 lnX2X2 lnX1X2; title ‘怀特检验法检验异方差’;

run;

proc reg data=nongcun3;

3

model e2=lnX1 lnX1X1 lnX2 lnX2X2 ; title ‘没有交叉项的怀特检验’; run;

data nongcun4; set nongcun2;

proc sort data=nongcun4; by X2;

proc print data=nongcun4; title ‘nongcun4’; run;

data nongcun5; set nongcun2; X22=X2; if X2<=876.0;

proc sort data=nongcun5; by X2;

proc print data=nongcun5; title ‘nongcun5’; run;

proc reg data=nongcun5; model lnY=lnX1 lnX2; title ‘G-Q检验子样本1’; run;

data nongcun6; set nongcun2; X22=X2; if X2>=1303.6;

proc sort data=nongcun6; by X2;

proc print data=nongcun6; title ‘nongcun6’;

run;

proc reg data=nongcun6; model lnY=lnX1 lnX2; title ‘G-Q检验子样本2’; run;

data nongcun7; set nongcun3; lnYjiaq=lnY/e1; lnX1jiaq=lnX1/e1; lnX2jiaq=lnX2/e1; proc print data=nongcun7; title ‘nongcun7’; run;

proc reg data=nongcun7;

model lnYjiaq=lnX1jiaq lnX2jiaq /DW noint;

title ‘加权最小二乘法’; run;

实验四 序列相关模型的检验和处理 程序(一)课本P115页中国商品进口模型,表4.2.1中数据: data MGDP;

input year GDP Mt @@; cards; 数据自己输入 ; run;

proc print data=MGDP; title ‘MGDP’; run;

proc reg data=MGDP;

4

model Mt=GDP/DW;

title ‘中国商品进口模型’; run; data MGDP2; set MGDP;

MM= 152.90574+ 0.02039*GDP; et=Mt-MM; et_1=lag(et); et_2=lag(et_1); et_3=lag(et_2); run;

/* proc gplot data=MGDP2; Symbol v=star i=join; plot et*year; run;

proc gplot data=MGDP2; Symbol v=plus i=join; plot et* et_1; run;*/ /*回归检验法*/ proc reg data=MGDP2; model et=et_1; title ‘回归法1’; run;

proc reg data=MGDP2; model et=et_1 et_2; title ‘回归法2’; run;

/*拉格朗日乘数检验*/ proc reg data=MGDP2; model et=GDP et_1 et_2;

title ‘拉格朗日乘数检验2阶序列相关’; run;

proc reg data=MGDP2; model et=GDP et_1 et_2 et_3;

title ‘拉格朗日乘数检验3阶序列相关’; run;

/*杜宾两步法修正*/ data MGDP3; set MGDP2; Mt_1=lag(Mt); Mt_2=lag(Mt_1); GDPt_1=lag(GDP); GDPt_2=lag(GDPt_1); run;

proc reg data=MGDP3;

model Mt=Mt_1 Mt_2 GDP GDPt_1 GDPt_2; title ‘杜宾法第一步估计相关系数’; run; data MGDP4; set MGDP3;

Mtstar=Mt-( 0.93825*Mt_1-0.46865*Mt_2);

GDPstar=GDP-( 0.93825*GDPt_1-0.46865*GDPt_2); run;

proc print data=MGDP4; title ‘MGDP4’; run;

proc reg data=MGDP4;

5

model Mtstar=GDPstar; title ‘杜宾法第二步’; run;

/*科克伦-奥克特迭代法(只迭代两步)修data MGDP7; set MGDP6;

MtMt=Mt-(1.19578*Mt_1-0.76487*Mt_2); GDPGD=GDP-(1.19578*GDPt_1+-0.76487*GD正*/

proc reg data=MGDP2; model et=et_1 et_2/noint; title ‘第一次估计相关系数’; run; data MGDP5; set MGDP3;

MtM=Mt-(1.10999*Mt_1-0.75138*Mt_2); GDPG=GDP-(1.10999*GDPt_1-0.75138*GDPt_2); run;

proc reg data=MGDP5; model MtM=GDPG;

title ‘第一次估计待估参数’; run; data MGDP6;

set MGDP3(drop=MM et et_1 et_2 et_3); MMM=107.39666+0.01991*GDP; et=Mt-MMM; et_1=lag(et); et_2=lag(et_1); et_3=lag(et_2); run;

proc reg data=MGDP6; model et=et_1 et_2/noint; title ‘第二次估计相关系数’; run;

Pt_2); run;

proc reg data=MGDP7; model MtMt=GDPGD;

title ‘第二次估计待估参数’; run;

/*回归法求4.2.26式*/ data MGDP8; set MGDP3;

AR1=Mt_1-93.74328-0.02001*GDPt_1; AR2=Mt_2-93.74328-0.02001*GDPt_2; run;

proc print data=MGDP8; title ‘MGDP8’; run;

proc reg data=MGDP8; model Mt=GDP AR1 AR2/DW; title ‘估计式4.2.26’; run;

实验五 多重共线性模型的检验和处理 程序(一)课本P124页粮食生产模型,表格4.3.3数据: data grain1;

input year total X1 X2 X3 X4 X5 @@; cards;

数据自己输入 ; run;

proc print data=grain1;

title \粮食生产模型原始样本观测值数据

6

\run;

proc reg data=grain1;

model total=X1 X2 X3 X4 X5/DW; run;

proc corr;/*求相关系数矩阵*/ var X1 X2 X3 X4 X5; run;

proc reg data=grain1; model total=X1 /DW; run;

proc reg data=grain1; model total=X2/DW; run;

proc reg data=grain1; model total=X4/DW; run;

proc reg data=grain1; model total=X5/DW; run;

/*以下是逐步回归过程*/ proc reg data=grain1;

model total=X1 X2 X3 X4 X5/ dw selection=stepwise details=all slentry=0.05 slstay=0.05;

/*selecton=stepwise 表示的是reg过程所提供的九种模型选择方法中的逐步法:从不包含任何自变量的模型开始,每一步加入一个自变量,同时判断模型内自变量是否达到剔除标准,如果是则剔除一个自变量;可以先不用details=all这个选项运行一下查看结果,再与有details=all的结果作比较。可选all、或steps——显示每一步骤的信息和变量筛选汇总表、或summary——表示仅显示变量筛选汇总表;slentry=0.05表示用来指定变量的入选标准(变量进入模型所需达到的显著性水平,此处为0.05),默认值为0.15;slstay=0.05表示用来指定变量的剔除标准(模型中的变量剔除出模型(或者是理解成将变量保留在模型中)所需达到的显著性水平,此处为0.05),默认值为0.15*/

title \粮食生产模型逐步回归\run;

data grain; set grain1 ;

totalguji=-11978+5.25594*X1+0.40843*X2-0.19461*X3;/*加波浪线的数值是前面估计得来的参数值,需要从前面的回归结果中得到。*/

wucha=total-totalguji; xdwucha=wucha/total;

keep year total et wucha_1 wucha X1 X2 X3 totalguji xdwucha; et=abs(wucha); wucha_1=lag(wucha); proc print data=grain; run;

/*proc reg data=grain; model wucha=wucha_1; title '自相关检验'; run;

proc reg data=grain; model et=X1 X2 X3;

title '用戈里瑟法检验异方差'; run;*/

data grain2;

merge grain1 grain;/*合并数据集*/

keep year total totalguji wucha xdwucha; proc print data=grain2;

title '粮食生产模型模拟结果'; run;

程序(二)用第一版课本P83页表2.10.3中消费模型样本观测值数据(李子奈 编著,《计量经济学》(第一版),高等教育出版社,其中程序中的Ct变量是当年的人均消费(元), It表示人均国内生产总值(元), Ct_1是前期人均居民消费(元),Ct_1是Ct的滞后变量。 data consume;

input year Ct It Ct_1 @@; cards;

1981 262 480 236 1982 284 514 262 1983 311 566 284

7

1984 354 668 311 1985 437 811 354 1986 485 908 437 1987 550 1043 485 1988 693 1355 550 1989 762 1512 693 1990 803 1634 762 1991 896 1879 803 1992 1070 2287 896 1993 1331 2939 1070 1994 1781 3923 1331 1995 2311 4854 1781 1996 2677 5634 2311 ; run;

proc print data=consume;/*输出表2.10.3*/

title '消费模型样本观测值数据'; run;

/*proc gplot data=consume; symbol v=star i=jion; plot Ct*It; run;

proc gplot data=consume; symbol v=plus i=jion; plot Ct*Ct_1;

run;*//*/**/中程序用于画散点图*/ proc reg data=consume; model Ct=It Ct_1;

title '样本观测数据处理';

run;/*由于模型中的解释变量含有滞后内生变量,D.W检验失效,故用回归法检验*/ data new; set consume;

keep year Ct et et_1;/*保留变量*/ CtCt=28.340830+0.359279*It+0.271635*Ct_1;

et=Ct-CtCt;

et_1=lag(et); run; proc print data=new;

title '消费模型序列相关检验样本数据'; run;

/*proc reg data=new; model et=et_1;

title '自相关检验'; run;*/ data new1;

merge consume new; proc print data=new1; title '中间数据集'; run;

data new2; set new1;

keep year Y It Ct_1 et; Y=abs(et); /*SAS函数,对变量取绝对值*/ run;

/*proc reg data=new2; model Y=It Ct_1;

title '用戈里瑟法检验异方差'; run;*/

proc reg data=new1; model It=Ct_1;

title '检验共线性'; run;

data new3; set new1;

Ctdif=dif(Ct); /*SAS函数作差分运算*/ Itdif=dif(It); Ct_1dif=dif(Ct_1); proc reg data=new3;

model Ctdif=Itdif Ct_1dif; title '消除共线性'; run;

proc reg data=new3; model Ct=It; title 'new3'; run;

data new4; set consume;

keep year Ct CtCt CtCtCt; CtCt=49.764106+0.458309*It; X=Ct-CtCt; CtCtCt=X/Ct; run;

proc print data=new4; title '消费模型模拟结果'; run;

8

本文来源:https://www.bwwdw.com/article/cobt.html

Top