stata怎么看durbin hjb统计量怎么看

温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
阅读(4001)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'【转】stata常用命令',
blogAbstract:'(转自人大论坛) 调整变量格式: format x1 %10.3f ——将x1的列宽固定为10,小数点后取三位 format x1 %10.3g ——将x1的列宽固定为10,有效数字取三位 format x1 %10.3e ——将x1的列宽固定为10,采用科学计数法 format x1 %10.3fc ——将x1的列宽固定为10,小数点后取三位,加入千分位分隔符 format x1 %10.3gc ——将x1的列宽固定为10,有效数字取三位,加入千分位分隔符 format x1 %-10.3gc ——将x1的列宽固定为10,有效数字取三位,加入千分位分隔符,加入“-”表示左对齐 合并数据: use \"C:\\Documents and Settings\\xks\\桌面\\2006.dta\", clear merge using',
blogTag:'',
blogUrl:'blog/static/3',
isPublished:1,
istop:false,
modifyTime:0,
publishTime:3,
permalink:'blog/static/3',
commentCount:1,
mainCommentCount:1,
recommendCount:1,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'1',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list} 上传我的文档
 下载
 收藏
 下载此文档
正在努力加载中...
1 STATA简介
下载积分:222
内容提示:1 STATA简介
文档格式:PDF|
浏览次数:259|
上传日期: 15:55:52|
文档星级:
全文阅读已结束,如果下载本文需要使用
 222 积分
下载此文档
该用户还上传了这些文档
1 STATA简介
关注微信公众号(window.slotbydup=window.slotbydup || []).push({
id: '2014386',
container: s,
size: '234,60',
display: 'inlay-fix'
&&|&&3次下载&&|&&总60页&&|
您的计算机尚未安装Flash,点击安装&
阅读已结束,如需下载到电脑,请使用积分()
下载:20积分
8人评价29页
8人评价25页
14人评价138页
3人评价134页
0人评价58页
所需积分:(友情提示:大部分文档均可免费预览!下载之前请务必先预览阅读,以免误下载造成积分浪费!)
(多个标签用逗号分隔)
文不对题,内容与标题介绍不符
广告内容或内容过于简单
文档乱码或无法正常显示
文档内容侵权
已存在相同文档
不属于经济管理类文档
源文档损坏或加密
若此文档涉嫌侵害了您的权利,请参照说明。
我要评价:
下载:20积分当前位置: >>
stata自用资料
调整变量格式: format x1 %10.3f ――将 x1 的列宽固定为 10,小数点后取三位 format x1 %10.3g ――将 x1 的列宽固定为 10,有效数字取三位 format x1 %10.3e ――将 x1 的列宽固定为 10,采用科学计数法 format x1 %10.3fc ――将 x1 的列宽固定为 10,小数点后取三位,加入千分位分隔符 forma
t x1 %10.3gc ――将 x1 的列宽固定为 10,有效数字取三位,加入千分位分隔符 format x1 %-10.3gc ――将 x1 的列宽固定为 10,有效数字取三位,加入千分位分隔符,加入D-‖ 表示左对齐 合并数据: use &C:\Documents and Settings\xks\桌面\2006.dta&, clear merge using &C:\Documents and Settings\xks\桌面\1999.dta& ――将 1999 和 2006 的数据按照样本(observation)排列的自然顺序合并起来 use &C:\Documents and Settings\xks\桌面\2006.dta&, clear merge id using &C:\Documents and Settings\xks\桌面\1999.dta& ,unique sort ――将 1999 和 2006 的数据按照唯一的 (unique) 变量 id 来合并, 在合并时对 id 进行排序 (sort) 建议采用第一种方法。 对样本进行随机筛选: sample 50 在观测案例中随机选取 50%的样本,其余删除 sample 50,count 在观测案例中随机选取 50 个样本,其余删除 查看与编辑数据: browse x1 x2 if x3&3 (按所列变量与条件打开数据查看器) edit x1 x2 if x3&3 (按所列变量与条件打开数据编辑器) 数据合并(merge)与扩展(append) merge 表示样本量不变, 但增加了一些新变量; append 表示样本总量增加了, 但变量数目不变。 one-to-one merge: 数据源自 stata tutorial 中的 exampw1 和 exampw2 第一步:将 exampw1 按 v001~v003 这三个编码排序,并建立临时数据库 tempw1 clear use &t:\statatut\exampw1.dta& su ――summarize 的简写 sort v001 v002 v003 save tempw1 第二步:对 exampw2 做同样的处理 clear use &t:\statatut\exampw2.dta& su sort v001 v002 v003 save tempw2 第三步:使用 tempw1 数据库,将其与 tempw2 合并: clear use tempw1 merge v001 v002 v003 using tempw2 第四步:查看合并后的数据状况: ta _merge ――tabulate _merge 的简写 su 第五步:清理临时数据库,并删除_merge,以免日后合并新变量时出错 erase tempw1.dta erase tempw2.dta drop _merge 数据扩展 append: 数据源自 stata tutorial 中的 fac19 和 newfac clear use &t:\statatut\fac19.dta& ta region append using &t:\statatut\newfac& ta region 合并后样本量增加,但变量数不变 茎叶图: stem x1,line(2) (做 x1 的茎叶图, 每一个十分位的树茎都被拆分成两段来显示, 前半段为 0~4, 后半段为 5~9) stem x1,width(2) (做 x1 的茎叶图,每一个十分位的树茎都被拆分成五段来显示,每个小树茎 的组距为 2) stem x1,round(100) (将 x1 除以 100 后再做 x1 的茎叶图) 直方图 采用 auto 数据库 histogram mpg, discrete frequency normal xlabel(1(1)5) (discrete 表示变量不连续,frequency 表示显示频数,normal 加入正太分布曲线,xlabel 设定 x 轴,1 和 5 为极端值,(1)为单位) histogram price, fraction norm (fraction 表示 y 轴显示小数,除了 frequency 和 fraction 这两个选择之外,该命令可替换为 Dpercent‖百分比,和Ddensity‖密度;未加上 discrete 就表示将 price 当作连续变量来绘图) histogram price, percent by(foreign) (按照变量Dforeign‖的分类,将不同类样本的Dprice‖绘制出来,两个图分左右排布) histogram mpg, discrete by(foreign, col(1)) (按照变量Dforeign‖的分类,将不同类样本的Dmpg‖绘制出来,两个图分上下排布) histogram mpg, discrete percent by(foreign, total) norm (按照变量Dforeign‖的分类,将不同类样本的Dmpg‖绘制出来,同时绘出样本整体的D总‖直方图) 二变量图: graph twoway lfit price weight || scatter price weight (作出 price 和 weight 的回归线图――Dlfit‖,然后与 price 和 weight 的散点图相叠加) twoway scatter price weight,mlabel(make) (做 price 和 weight 的散点图,并在每个点上标注Dmake‖,即厂商的取值) twoway scatter price weight || lfit price weight,by(foreign) (按照变量 foreign 的分类,分别对不同类样本的 price 和 weight 做散点图和回归线图的叠加, 两图呈左右分布) twoway scatter price weight || lfit price weight,by(foreign,col(1)) (按照变量 foreign 的分类,分别对不同类样本的 price 和 weight 做散点图和回归线图的叠加, 两图呈上下分布) twoway scatter price weight [fweight= displacement],msymbol(oh) ( 画 出 price 和 weight 的 散 点 图 , Dmsybol(oh)‖ 表 示 每 个 点 均 为 中 空 的 圆 圈 , [fweight= displacement]表示每个点的大小与 displacement 的取值大小成比例) twoway connected y1 time,yaxis(1) || y2 time,yaxis(2) (画出 y1 和 y2 这两个变量的时间点线图,并将它们叠加在一个图中,左边Dyaxis(1)‖为 y1 的度 量,右边Dyaxis(2)‖为 y2 的) twoway line y1 time,yaxis(1) || y2 time,yaxis(2) (与上图基本相同,就是没有点,只显示曲线) graph twoway scatter var1 var4 || scatter var2 var4 || scatter var3 var4 (做三个点图的叠加) graph twoway line var1 var4 || line var2 var4 || line var3 var4 (做三个线图的叠加) graph twoway connected var1 var4 || connected var2 var4 || connected var3 var4 (叠加三个点线相连图) 更多变量: graph matrix a b c y (画出一个散点图矩阵,显示各变量之间所有可能的两两相互散点图) graph matrix a b c d,half (生成散点图矩阵,只显示下半部分的三角形区域) 用 auto 数据集: graph matrix price mpg weight length,half by( foreign,total col(1) ) (根据 foreign 变量的不同类型绘制 price 等四个变量的散点图矩阵,要求绘出总图,并上下排 列】=具) 其他图形: graph box y,over(x) yline(.22) (对应 x 的每一个取值构建 y 的箱型图,并在 y 轴的 0.22 处划一条水平线) graph bar (mean) y,over(x) 对应 x 的每一个取值, 显示 y 的平均数的条形图。 括号中的Dmean‖也可换成 median、 sum、 sd、 p25、p75 等 graph bar a1 a2,over(b) stack (对应在 b 的每一个取值,显示 a1 和 a2 的条形图,a1 和 a2 是叠放成一根条形柱。若不写入 Dstack‖,则 a1 和 a2 显示为两个并排的条形柱) graph dot (median)y,over(x) (画点图,沿着水平刻度,在 x 的每一个取值水平所对应的 y 的中位数上打点) qnorm x (画出一幅分位-正态标绘图) rchart a1 a2 a2 (画出质量控制 R 图,显示 a1 到 a3 的取值范围) 简单统计量的计算: ameans x (计算变量 x 的算术平均值、几何平均值和简单调和平均值,均显示样本量和置信区间) mean var1 [pweight = var2] (求取分组数据的平均值和标准误,var1 为各组的赋值,var2 为每组的频数) summarize y x1 x2,detail (可以获得各个变量的百分比数、最大最小值、样本量、平均数、标准差、方差、峰度、偏度) ***注意*** stata 中 summarize 所计算出来的峰度 skewness 和偏度 kurtosis 有问题,与 ECELL 和 SPSS 有较大差异,建议不采用 stata 的结果。 summarize var1 [aweight = var2], detail (求取分组数据的统计量,var1 为各组的赋值,var2 为每组的频数) tabstat X1,stats(mean n q max min sd var cv) (计算变量 X1 的算术平均值、样本量、四分位线、最大最小值、标准差、方差和变异系数) 概率分布的计算: (1)贝努利概率分布测试: webuse quick bitest quick==0.3,detail (假设每次得到成功案例?1‘的概率等于 0.3,计算在变量 quick 所显示的二项分布情况下,各种 累计概率和单个概率是多少) bitesti 10,3,0.5,detail (计算当每次成功的概率为 0.5 时,十次抽样中抽到三次成功案例的概率:低于或高于三次成功 的累计概率和恰好三次成功概率) (2)泊松分布概率: display poisson(7,6) . (计算均值为 7,成功案例小于等于 6 个的泊松概率) display poissonp(7,6) . (计算均值为 7,成功案例恰好等于 6 个的泊松概率) display poissontail(7,6) . (计算均值为 7,成功案例大于等于 6 个的泊松概率) (3)超几何分布概率: display hypergeometricp(10,3,4,2) .3 (计算在样本总量为 10,成功案例为 3 的样本总体中,不重置地抽取 4 个样本,其中恰好有 2 个为成功案例的概率) display hypergeometric(10,3,4,2) . (计算在样本总量为 10,成功案例为 3 的样本总体中,不重置地抽取 4 个样本,其中有小于或 等于 2 个为成功案例的概率) 检验极端值的步骤: 常见命令:tabulate、stem、codebook、summarize、list、histogram、graph box、gragh matrix step1.用 codebook、summarize、histogram、graph boxs、graph matrix、stem 看检验数据的 总体情况: codebook y x1 x2 summarize y x1 x2,detail histogram x1,norm (正态直方图) graph box x1(箱图) graph matrix y x1 x2,half(画出各个变量的两两 x-y 图) stem x1(做 x1 的茎叶图) 可以看出数据分布状况,尤其是最大、最小值 step2.用 tabulate、list 细致寻找极端值 tabulate code if x1==极端值(作出 x1 等于极端值时 code 的频数分布表,code 表示地区、年份 等序列变量,这样便可找出那些地区的数值出现了错误) list code if x1==极端值(直接列出 x1 等于极端值时 code 的值,当 x1 的错误过多时,不建议使 用该命令) list in -20/l(l 表示 last one,-20 表示倒数第 20 个样本,该命令列出了从倒数第 20 个到倒数第 一个样本的各变量值) step3.用 replace 命令替换极端值 replace x1=? if x1==极端值 去除极端值: keep if y&1000 drop if y&1000 对数据排序: sort x gsort +x (对数据按 x 进行升序排列) gsort -x (对数据按 x 进行降序排列) gsort -x, generate(id) mfirst (对数据按 x 进行降序排列,缺失值排最前,生成反映位次的变量 id) 对变量进行排序: order y x3 x1 x2 (将变量按照 y、x3、x1、x2 的顺序排列) 生成新变量: gen logx1=log(x1)(得出 x1 的对数) gen x1`=exp(logx1)(将 logx1 反对数化) gen r61_100=1 if rank&=61&rank&=100(若 rank 在 61 与 100 之间,则新变量 r61_100 的取值 为 1,其他为缺失值) replace r61_100 if r61_100!=1(D!=‖表示不等于,若 r61_100 取值不为 1,则将 r61_100 替换 为 0,就是将上式中的缺失值替换为 0) gen abs(x)(取 x 的绝对值) gen ceil(x)(取大于或等于 x 的最小整数) gen trunc(x)(取 x 的整数部分) gen round(x)(对 x 进行四舍五入) gen round(x,y)(以 y 为单位,对 x 进行四舍五入) gen sqrt(x)(取 x 的平方根) gen mod(x,y)(取 x/y 的余数) gen reldif(x,y)(取 x 与 y 的相对差异,即|x-y|/(|y|+1)) gen logit(x)(取 ln[x/(1-x)]) gen x=autocode(x,n,xmin,xmax)(将 x 的值域,即 xmax-xmin,分为等距的 n 份) gen x=cond(x1&x2,x1,x2)(若 x1&x2 成立,则取 x1,若 x1&x2 不成立,则取 x2) sort x gen gx=group(n)(将经过排序的变量 x 分为尽量等规模的 n 个组) egen zx1=std(x1)(得出 x1 的标准值,就是用(x1-avgx1)/sdx1) egen zx1=std(x1),m(0) s(1)(得出 x1 的标准分,标准分的平均值为 0,标准差为 1) egen sdx1=sd(x1)(得出 x1 的标准差) egen meanx1=mean(x1)(得出 x1 的平均值) egen maxx1=max(x1)(最大值) egen minx1=min(x1)(最小值) egen medx1=med(x1)(中数) egen modex1=mode(x1)(众数) egen totalx1=total(x1)(得出 x1 的总数) egen rowsd=sd(x1 x2 x3)(得出 x1、x2 和 x3 联合的标准差) egen rowmean=mean(x1 x2 x3)(得出 x1、x2 和 x3 联合的平均值) egen rowmax=max(x1 x2 x3)(联合最大值) egen rowmin=min(x1 x2 x3)(联合最小值) egen rowmed=med(x1 x2 x3)(联合中数) egen rowmode=mode(x1 x2 x3) (联合众数) egen rowtotal=total(x1 x2 x3)(联合总数) egen xrank=rank(x)(在不改变变量 x 各个值排序的情况下,获得反映 x 值大小排序的 xrank) 数据计算器 display 命令: display x[12](显示 x 的第十二个观察值) display chi2(n,x)(自由度为 n 的累计卡方分布) display chi2tail(n,x)(自由度为 n 的反向累计卡方分布,chi2tail(n,x)=1-chi2(n,x)) display invchi2(n,p)(卡方分布的逆运算,若 chi2(n,x)=p,那么 invchi2(n,p)=x) display invchi2tail(n,p)(chi2tail 的逆运算) display F(n1,n2,f)(分子、分母自由度分别为 n1 和 n2 的累计 F 分布) display Ftail(n1,n2,f)(分子、分母自由度分别为 n1 和 n2 的反向累计 F 分布) display invF(n1,n2,P)(F 分布的逆运算,若 F(n1,n2,f)=p,那么 invF(n1,n2,p)=f) display invFtail(n1,n2,p)(Ftail 的逆运算) display tden(n,t)(自由度为 n 的 t 分布) display ttail(n,t)(自由度为 n 的反向累计 t 分布) display invttail(n,p)(ttail 的逆运算) 给数据库和变量做标记: label data &~~~&(对现用的数据库做标记,&~~~&就是标记,可自行填写) label variable x &~~~&(对变量 x 做标记) label values x label1(赋予变量 x 一组标签:label1) label define label1 1 &a1& 2 &a2&(定义标签的具体内容:当 x=1 时,标记为 a1,当 x=2 时,标 记为 a2) 频数表: tabulate x1,sort tab1 x1-x7,sort(做 x1 到 x7 的频数表,并按照频数以降序显示行) table c1,c(n x1 mean x1 sd x1) (在分类变量 c1 的不同水平上列出 x1 的样本量和平均值) 二维交互表: auto 数据库: table rep78 foreign, c(n mpg mean mpg sd mpg median mpg) center row col (rep78,foreign 均为分类变量,rep78 为行变量,foreign 为列变量,center 表示结果显示在单 元格中间,row 表示计算行变量整体的统计量,col 表示计算列变量整体的统计量) tabulate x1 x2,all (做 x1 和 x2 的二维交互表,要求显示独立性检验 chi2、似然比卡方独立性检验 lrchi2、对定序 变量适用的等级相关系数 gamma 和 taub、以及对名义变量适用的 V) tabulate x1 x2,column chi2(做 x1 和 x2 的二维交互表,要求显示列百分比和行变量和列变量的 独立性检验――零假设为变量之间独立无统计关系) tab2 x1-x7,all nofreq(对 x1 到 x7 这七个变量两两地做二维交互表,不显示频数:nofreq) 三维交互表: by x3,sort:tabulate x1 x2,nofreq col chi2(同时进行 x3 的每一个取值内的 x1 和 x2 的二维交互 表,不显示频数、显示列百分比和独立性检验) 四维交互表: table x1 x2 x3,c(ferq mean x1 mean x2 mean x3) by(x4) tabstat X1 X2,by(X3) stats(mean n q max min sd var cv) col(stats) tabstat X1 X2,by(X3) stats(mean range q sd var cv p5 p95 median),[aw=X4] (以 X4 为权重求 X1、X2 的均值,标准差、方差等) ttest X1=1 count if X1==0 count if X1&=0 gen X2=1 if X1&=0 corr x1 x2 x3(做 x1、x2、x3 的相关系数表) swilk x1 x2 x3(用 Shapiro-Wilk W test 对 x1、x2、x3 进行正太性分析) sktest x1 x2 x3(对 x1、x2、x3 进行正太性分析,可以求出峰度和偏度) ttest x1=x2(对 x1、x2 的均值是否相等进行 T 检验) ttest x1,by(x2) unequal(按 x2 的分组方式对 x1 进行 T 检验,假设方差不齐性) sdtest x1=x2(方差齐性检验) sdtest x1,by(x2)(按 x2 的分组方式对 x1 进行方差齐性检验) 聚类分析: cluster kmeans y x1 x2 x3, k(3) ――依据 y、x1、x2、x3,将样本分为 n 类,聚类的核为随机选取 cluster kmeans y x1 x2 x3, k(3) measure(L1) start(everykth) ―― &start&用于确定聚类的核,&everykth&表示将通过构造三组样本获得聚类核:构造方法为将 样本 id 为 1、1+3、1+3×2、 1+3×3……分为一组、将样本 id 为 2、2+3、2+3×2、2+3×3…… 分为第二组,以此类推,将这三组的均值作为聚类的核; &measure&用 于计算相似性和相异性 的方法, &L1& 表示采用欧式距离的绝对值,也直接可采用欧式距离( L2 )和欧式距离的平方 (L2squared) 。PS:这个方法 所得的结果与 SPSS 所得结果相同。 sort c1 c2(对 c1 和 c2 两个分类变量排序) by c1 c2:reg y x1 x2 x3(在 c1、c2 的各个水平上分别进行回归) bysort c1 c2:reg y x1 x2 x3 if c3=1(逗号前面相当于将上面两步骤合一,既排序又回归,逗号 后面的Dif c3=1‖表示只有在 c3=1 的情况下才进行回归) stepwise, pr(.2): reg y x1 x2 x3(使用 Backward selection,去除 P 值大于 0.2 时变量) stepwise, pe(.2): reg y x1 x2 x3(使用 forward selection,去除 P 值小于 0.2 时变量) stepwise, pr(.2) pe(.01):reg y x1 x2 x3(使用 backward-stepwise selection,取 P 值在 0.01 和 0.2 之间的变量) stepwise, pe(.2) forward: reg y x1 x2 x3(使用 forward-stepwise selection) reg y x1 x2 x3 predict Yhat,xb predict u,resid predict ustd,stdr(获得残差的标准误) predict std,stdp(获得 y 估计值的标准误) predict stdf,stdf(获得 y 预测值的标准误) predict e,e(1,12)(获得 y 在 1 到 12 之间的估计值) predict p,pr(1,12)(获得 y 在 1 到 12 之间的概率) predict rstu,rstudent(获得 student 的 t 值) predict lerg,leverage(获得杠杆值) predict ckd,cooksd(获得 cooksd) reg y x1 x2 x3 c1 c2 adjust x1 x2 x3,se(使得变量 x1、x2 和 x3 等于其均值,求 y 的预测值和标准误) adjust x1 x2 x3,stdf ci(使得变量 x1、x2 和 x3 等于其均值,求 y 的预测值,预测标准误和置 信区间) adjust x1 x2,by(c1) se ci(控制变量 x1、x2,亦即取它们的均值,在分类变量 c1 的不同水平上 求 y 预测值,标准误和置信区间) adjust x1 x2 x3,by(c1) stdf ci(控制变量 x1、x2、x3,亦即取它们的均值,在分类变量 c1 的不 同水平上求 y 预测值,预测标准误和置信区间) adjust x1 x2,by(c1 c2) se ci(控制变量 x1、x2,在分类变量 c1、c2 的不同水平上求 y 的预测 值,标准误和置信区间) adjust x1 x2 x3,by(c1 c2) stdf ci(控制变量 x1、x2、x3,在分类变量 c1、c2 的不同水平上求 y 的预测值,预测标准误和置信区间) adjust x1=a x2=b x3=c,se ci(当 x1=a、x2=b、x3=c 时,求 y 的预测值、标准误和置信区间) adjust x1=a x2=b x3=c, by(c1) se ci (当 x1=a、 x2=b、 x3=c 时, 在分类变量 c1 的不同水平上, 求 y 的预测值、标准误和置信区间) adjust x1=a x2=b c1=1,by(c1) se ci(当 x1=a、x2=b,并假设所有的样本均为 c1=1,求在分 类变量 c1 的不同水平上,因为变量 x3 的均值不同,而导致的 y 的不同的预测值……) mvreg Y1 Y2 ……: X1 X2 X3……(多元回归) mvreg y1 y2 y3: x1 x3 x3(多元回归分析,y1 y2 y3 为因变量,x1 x3 x3 为自变量) 以下命令只有在进行了 mvreg 之后才能进行 test [y1](测试对 y1 的回归系数联合为 0) test [y1]: x1 x2(测试对 y1 的回归中 x1、x2 的系数为 0) test x1 x2 x3(测试在所有的回归中,x1、x2、x3 的系数均为 0) test [y1=y2](对 y1 的回归和对 y2 的回归系数相等) test [y1=y2]: x1 x2 x3, mtest(对 y1 和 y2 的回归中,分别测试 x1、x2、x3 的系数是否相等, 若没有 mtest 这个命令,则测试他们的联和统计) test [y1=y2=y3](三个回归的系数是否相等,可加 mtest 以分别测试) test [y1=y2=y3]: x1 x2 (测试三个回归中的 x1、x2 是否相等,可加 mtest) est 命令的用法: (1)储存回归结果: reg y x1 x2 x3(不限于 reg,也可储存 ivreg、mvreg、reg3) est store A (2)重现回归结果: est replay A (3)对回归结果进行进一步分析 est for A:sum(对 A 回归结果中的各个变量运行 sum 命令) 异方差问题: 获得稳健性标准误 reg y x1 x2 x3 if c1==1(当分类变量 c1=1 时,进行 y 和诸 x 的回归) reg y x1 x2 x3,robust(回归后显示各个自变量的异方差-稳健性标准误) estat vif(回归之后获得 VIF) estat hettest,mtest(异方差检验) 异方差检验的套路: (1)Breusch-pagan 法: reg y x1 x2 x3 predict u,resid gen usq=u^2 reg usq x1 x2 x3 求F值 display R/(1-R)*n2/n1(n1 表示分子除数,n2 表示分母除数) display Ftail(……) 求 LM 值 display R*n(n 表示总样本量) display chi2tail(……) (2)white 法: reg y x1 x2 x3 predict u,resid gen usq=u^2 predict y gen ysq=y^2 reg usq y ysq 求F值 display R/(1-R)*n2/n1(n1 表示分子除数,n2 表示分母除数) display Ftail(……) 求 LM 值 display R*n(n 表示总样本量) display chi2tail(……) (3)必要补充 F 值和 LM 值转换为 P 值的命令: display Ftail(n1,n2,a)(利用 F 值求 p 值,n1 表示分子除数,n2 表示分母除数,a 为 F 值) display chi2tail(n3,b) (利用 LM 值求 p 值, n3 表示自由度的损失量, 一般等于 n1, b 为 LM 值) 异方差的纠正――WLS(weighted least square estimator) (1)基本思路: reg y x1 x2 x3 [aw=x1](将 x1 作为异方差的来源,对方程进行修正) 上式相当于: reg y/(x1^0.5) 1/(x1^0.5) x1/(x1^0.5) x2/(x1^0.5) x3/(x1^0.5),noconstant (2)纠正异方差的常用套路(构造 h 值) reg y x1 x2 x3 predict u,resid gen usq=u^2 gen logusq=log(usq) reg logusq x1 x2 x3 predict g gen h=exp(g) reg y x1 x2 x3 [aw=1/h] 异方差 hausman 检验: reg y x1 x2 x3 est store A(将上述回归结果储存到 A 中) reg y x1 x2 x3 [aw=1/h] est store B hausman A B 当因变量为对数形式时(log(y))如何预测 y reg logy x1 x2 x3 predict k gen m=exp(k) reg y m,noconstant m 的系数为 i y 的预测值=i×exp(k) 方差分析: 一元方差分析 anova y g1 / g1|g2 /(g*表示不同分类变量,计算 g1 和交互项/ g1|g2 /这两种分类的 y 值是否存 在组内差异) anova y d1 d2 d1*d2(d*表示虚拟变量,计算 d1、d2 和 d1*d2 的这三种分类的 y 值是否有组内 差异) anova y d1 d2 x1 d2*x1, continuous(x1)(x*表示连续的控制变量) 多元方差分析 webuse jaw manova y1 y2 y3 = gender fracture gender*fracture (按性别、是否骨折及二者的交互项对 y1、 y2 和 y3 进行方差分析) manova y1 = gender fracture gender*fracture(相当于一元方差分析,以 y1 为因变量) ―――――――――――― webuse nobetween gen mycons = 1 manova test1 test2 test3 = mycons, noconstant mat c = (1,0,-1 \ 0,1,-1) manovatest mycons, ytransform(c) 进行多元回归的方法: 多元回归分析: (与 mvreg 相同) foreach vname in y1 y2 y3 { (确定 y 变量组 vname) reg `vname' x1 x2 x3 (将 y 变量组中的各个变量与诸 x 变量进行回归分析,注意 vname 的标 点符号) } 上式等价于: mvreg y1 y2 y3 = x1 x2 x3 reg3 命令: (1)简单用法: reg3 (y1 = x1 x2 x3) (y2 = x1 x3 x4) (y3 = x1 x2 x5) 测试 y1 coefs = 0 test [y1] 测试不同回归中相同变量的系数: test [y1=y2=y3], common test ([y1=y2]) ([y1=y3]), common constant(constant 表示包含截距项) (2)用 reg3 进行 2SLS reg3 (y1 = y2 x1 x2) (y2 = y1 x4),2sls (2)用 reg3 进行 OLS reg3 (y1 = y2 x1 x2) (y2 = y1 x4),ols 对两个回归结果进行 hausman 检验: reg3 (y1=x1 x2 x3)(y2=y1 x4),2sls est store twosls reg3 (y1=x1 x2 x3)(y2=y1 x4),ols est store ols hausman twosls ols,equations(1:1)(对两次回归中的方程 1,即Dy1=x1 x2 x3‖进行 hausman 检 验) hausman twosls ols,equations(2:2) (对两次回归中的方程 2, 即Dy2=y1 x4‖进行 hausman 检验) hausman twosls ols,alleqs (对所有方程一起进行检验) 检验忽略变量(模型的 RESET) : reg y x1 x2 x3 estat ovtest 滞后变量的制取 对变量 y 滞后一期: gen y_l1=y[_n-1] 滞后两期: gen y_l2=y[_n-2] 以此类推。 制取样本序号: gen id=_n 获得样本总量: gen id=_N 时间序列回归: 回归元严格外生时 AR(1)序列相关的检验 reg y x1 x2 predict u,resid gen u_1=u[_n-1] reg u u_1,noconstant 回归之后,u_1 的序数如果不异于零,则该序列不相关 用 Durbin-Watson Statistics 检验序列相关: tsset year @(对时间序列回归中代表时间的变量进行定义)@ reg y x1 x2 dwstat @(求出时间序列回归的 DW 值)@ durbina @ (对该回归是否具有序列相关进行检验, H0 为无序列相关, 可根据 chi2 值求出 P 值) @ durbina,small @(small 可以根据 F 值求出 P 值,以代替 chi2 值)@ durbina,force @(让检验能在 robust、neway 之后进行)@ durbina,small lag(1/10) @(lag 可以求出更高阶滞后的序列相关,如本例中可求出 1 到 10 阶的 序列相关)@ durbina,robust lag(1/10) @(robust 可进行异方差―稳健性回归,避免未知形式的异方差)@ bgodfrey @(利用 Breusch-Godfrey test 求出高阶序列相关)@ bgodfrey,small lag(1/10) 数据调查:survey data 源数据:dataset 文件夹中的 svydata 步骤: 1、定义 survey data svyset psuid [pweight=finalwgt], strata(stratid) ――定义 primary sampling unit 为 psuid。可能是测试的编号,1or2 ――定义 pweight 为 finalwgt ――定义 stratum identifer 为 stratid。可能是测试中被试的编号,1to31 2、生成 male gen male= (sex==1) if !missing(sex) ――当 sex 不缺失且等于 1 时,male=sex 3、生成行变量为 highbp,列变量为 sizplace 的表格 svy, subpop(male): tabulate highbp sizplace, col obs pearson lr null wald ――subpop 规定了以 male 为数据调查的范围 ――tabulate highbp sizplace 表示绘制行变量为 highbp,列变量为 sizplace 的表格 ――col 表示每一列的加总为 100%,row 表示每一行的加总为 100%,cell 表示横纵所有单元格 的加总为 100% ――obs 表示列出每个单元格的样本量,se 表示列出每个单元格的标准误,ci 表示列出每个单 元格的置信区间 ――pearson 表示求取 pearson's chi-squired,皮尔逊的卡方检定 ――lr 表示求取 likelihood ratio ――null 表示求取 null-based statistics ――wald 表示求取 adjusted wald,llwald 表示求取 adjusted log-linear Wald,noadjust 表示求 取 unadjusted Wald statistics 4、svy:mean x1 x2 x3 ――对 x1、x2、x3 求取 mean、se 和 ci 5、简单的 tabulate twoway(不用 svyset 就可执行) tab2 y x,col chi2 exact lr ――col、cell、row 等均可换用,chi2 指的是 Pearson's chi-squared、exact 指的是 fisher exact test、lr 指的是 likelihood-ratio chi-squared 6、svy 的其他用法: svy:reg y x 建立人工数据集: 创建一个包含从独立标准正态分布中抽取的 2000 个观察案例和三个随机 Z1、Z2、Z3,并分别 定义他们的平均值和标准差。 matrix m=(0,2,3) ――定义三个变量的平均值 matrix sd=(1,.5,2) ――定义三个变量的标准差 drawnorm z1 z2 z3,n(2000) means(m) sds(sd) ――创建样本量为 2000,均值和标准差符合上 面定义的数据集 补充:除了定义均值和标准差之外,还可定义相关矩阵和协方差矩阵等。 logit 回归 logit y x1 x2 x3 ――y 必须为二分变量 glogit outcomedata populationdata x1 x2 x3 ――outcomedata 为 目 标 样 本 总 量 , populationdata 为 观 测 样 本 总 量 , outcomedata/populationdata 的值便是一个概率,相当于 logit 命令中的 y 面板数据(Panel Data) 1、基本套路: xtreg y x1 x2,re est store re xtreg y x1 x2,fe est store fe hausman re fe ――如果 hausman 检验的结果为显著,则采用固定效应(fe)模型,不显著,则选取随机效应 (re)模型 2、随机效应的检验: xtreg y x1 x2,re xttest0 xttest1 ――xttest1 是 xttest0 的扩展,若这 xttest0 的结果为显著,则采用随机效应(re)模型 xttest1 的假设是没有随机效应和/或没有序列相关,它的七个结果分别表示: 1) LM Test for random effects, assuming no serial correlation (假设没有序列相关情况下对随机效应进行 LM 检验) 2) Adjusted LM test for random effects, which works even under serial correlation (假设有序列相关的情况下对随机 LM 检验) 3) One sided version of the LM test for random effects (假设没有序列相关的情况下对随机效应进行单边检验) 4) One sided version of the adjusted LM test for random effects (假设有序列相关的情况下对随机效应进行单边检验) 5) LM test for first-order serial correlation, assuming no random effects (假设没有随机效应的情况下对一阶序列相关进行检验) 6) Adjusted test for first-order serial correlation, which works even under random effects (假设有随机效应的情况下对一阶序列相关进行检验) 7) LM Joint test for random effects and serial correlation (随机效应和序列相关的联合检验) 3、固定效应模型,可采用广义最小二乘法(gls)进行估算,也可采用固定效应方程(fe) : xtserial y x1 x2 xtgls y x1 x2 xttest2 xttest3 ――xtserial 用于检验固定效应模型中的一阶序列自相关,可通用于 xtgls 和 fe 之前 ――xttest2 用于检验不同厂商的相似性,若显著则各厂家的截面相似,可通用于 xtgls 和 fe 之 后 ――xttest3 用于检验固定效应模型中的异方差问题,若显著则有异方差,可通用于 xtgls 和 fe 之后Stata: 输出 regression table 到 word 和 excel1. 安装 estout。最简单的方式是在 stata 的指令输入: ssc install estout, replace EST 安装的指导网址是:http://repec.org/bocode/e/estout/installation.html 2.跑你的 regression 3.写下这行指令 esttab using test.rtf,然后就会出现个漂亮的表格给你(WORD 文档) 。只要再 小幅修改,就可以直接用了。这个档案会存在 my document\stata 下。如果你用打开的是一个 stata do file,结果会保存到 do 文件所在文件夹中。如果要得到 excel 文件,就把后缀改为.xls 或者.csv 就可以了 4.跑多个其实也不难,只要每跑完一个 regression,你把它取个名字存起来:est store m1。m1 是你要改的,第一个 model 所以我叫 m1,第二个的话指令就变成 est store m2,依次类推。 5.运行指令:esttab m1 m2 ... using test.rtf 就行了。 异方差的检验: Breusch-Pagan test in STATA: 其基本命令是:estat hettest var1 var2 var3 其中,var1 var2 var3 分别为你认为导致异方差性的几个自变量。是你自己设定的一个 滞后项数量。 同样,如果输出的 P-Value 显著小于 0.05,则拒绝原假设,即不存在异方差性。 White 检验: 其基本命令是在完成基本的 OLS 回归之后,输入 imtest, white 如果输出的 P-Value 显著小于 0.05,则拒绝原假设,即不存在异方差性处理异方差性问题的方法: 方法一:WLS WLS 是 GLS(一般最小二乘法)的一种,也可以说在异方差情形下的 GLS 就是 WLS。在 WLS 下,我们设定扰动项的条件方差是某个解释变量子集的函数。之所以被称为加权最小二乘法,是 因为这个估计最小化的是残差的加权平方和,而上述函数的倒数恰为其权重。 在 stata 中实现 WLS 的方法如下: reg (被解释变量) (解释变量 1) (解释变量 2)…… [aweight=变量名] 其中,aweight 后面的变量就是权重,是我们设定的函数。 一种经常的设定是假设扰动项的条件方差是所有解释变量的某个线性组合的指数函数。在 stata 中也可以方便地实现: 首先做标准的 OLS 回归,并得到残差项; reg (被解释变量) (解释变量 1) (解释变量 2)…… predict r, resid 生成新变量 logusq,并用它对所有解释变量做回归,得到这个回归的拟合值,再对这个拟合值 求指数函数; gen logusq=ln(r^2) reg logusq (解释变量 1) (解释变量 2)…… predict g, xb gen h=exp(g) 最后以 h 作为权重做 WLS 回归; reg (被解释变量) (解释变量 1) (解释变量 2)…… [aweight=h] 如果我们确切地知道扰动项的协方差矩阵的形式,那么 GLS 估计是最小方差线性无偏估计,是 所有线性估计中最好的。显然它比 OLS 更有效率。虽然 GLS 有很多好处,但有一个致命弱点: 就是一般而言我们不知道扰动项的协方差矩阵,因而无法保证结果的有效性。 方法二:HC SE There are 3 kinds of HC SE (1)Huber-White Robust Standard Errors HC1, 其基本命令是: reg var1 var2 var3, robust White(1980)证明了这种方法得到的标准误是渐进可用(asymptotically valid)的。这种方法 的优点是简单,而且需要的信息少,在各种情况下都通用。缺点是损失了一些效率。这种方法在 我们日常的实证研究中是最经常使用。 (2)MacKinnon-White SE HC2,其基本命令是: reg var1 var2 var3, hc2 (3)Long-Ervin SE HC3,其基本命令是: reg var1 var2 var3, hc3约束条件检验: 如果需要检验两个变量,比如 x 与 y,之间系 数之间的关系,以检验两者系数相等为例,我们可以直接输入命令: test x=y 再如检验两者系数之和等于 1,我们可以直接输入命令: test x+y=1 如果输出结果对应的 P-Value 小于 0.05,则说明原假设显著不成立,即拒绝原假设。序列相关性问题的检验与处理 序列相关性问题的检验: 首先,要保证所用的数据必须为时间序列数据。如果原数据不是时间序列数据, 则需要进行必要的处理,最常用的方法就是: gen n=_n tsset n 这两个命令的意思是,首先要生成一个时间序列的标志变量 n(或者 t 也可以) ; 然后通过 tsset 命令将这个数据集定义为依据时间序列标志变量 n 定义的时间序 列数据。 最直观的检验方式是通过观察残差分布,其基本步骤是在跑完回归之后,直接输 入 Predict error, stdp 这样就得到了残差值;然后输入命令: plot error n 会得到一个 error 随 n 变化的一个散点图。D-W 检验――对一阶自相关问题的检验: D-W 检验是对一阶自相关问题的常用检验方法,但是如果实际问题中存在高阶 序列相关性问题,则不能用这个检验方法。 D-W 检验的命令如下: 首先,输入回归命令, reg Variable1 Variable2 Variable3…VariableM 输出一个简单的 OLS 估计结果。然后,再输入命令: dwstat 这时会输出一个 DW 统计量。通过与临界值之间的比较,可以得出结论。也可 以执行如下命令 estat durbinalt 直接进行 Durbin 检验。 Breusch-GodfreyTest in STATA――检验高阶序列相关性: 在得到一个基本回归结果和 error 之后,我们假设这样一个关系: et = α0 + α1 et-1 + α2 et-2 …+ αk et-p + β1 x1t + β2 x2t … +βk xkt +εt BG 检验的原假设是:H0 : α1 = α2 = … αp =0。 其基本命令是: bgodfrey , lags(p) 其中 p 是你自己设定的一个滞后项数量。如果输出的 p-value 显著小于 0.05,则 可以拒绝原假设,这就意味着模型存在 p 阶序列相关性;如果输出的 p-value 显 著大于 0.05 甚至很大,则可以接受原假设,即不存在 p 阶序列相关性。处理序列相关性问题的方法――GLS: 常用的几种 GLS 方法: (1) Cochrane-Orcutt estimator 和 Prais-Winsten estimator 其基本命令是 prais var1 var2 var3, corc (2) Newey-West standard errors 其基本命令是 newey var1 var2 var3, lag(3) 其中,lag(3)意思是对三阶序列相关性问题进行处理;如果需要对 p 阶序列相 关性问题进行处理,则为 lag(p)t 因变量,g,f,c 是自变量,_26 存放了弟 26 个观测值,为需要预测的值 reg t g f c if _n!=26 点预测 predict taxpredict if _n==26均值的区间预测 predictnl py=predict(xb),ci(lb ub) l(95) 因变量的区间预测 adjust g= f=24649.95 c=99.9,stdf ci level(95)Hausman 检验是检验内生性的最常用的方法。它是通过比较一致估计量与有效估计量的 Wald 统计量。 命令格式为: .hausman name-constistent [name-efficent] [,options] 其中,name-cosistent 指一致估计的结果, name-efficent 指有效估计的结果。注意,一致、 有效估计量的先后顺序不能改变。 Option 选项: constant 计算检验统计量将常数也包括在内,默认值为排除常数 allegs 利用所有方程进行检验,默认只对第一个方程进行检验 skipeqs(eqlist) eqlist 只能以方程名称而不能以方程序号表示 equation(matchlist) 比较设定的方程。 force 即使假设条件不满足仍进行检验 df(#) 默认值为一致估计与有效估计的协方差矩阵的差的估计 sigmamore 协方差矩阵采用有效估计量的协方差矩阵 sigmaless 协方差矩阵采用一致估计量的协方差矩阵 tconsistent(string) 一致估计量的标题 tefficient(string) 有效估计量的标题工具变量估计 命令格式: .ivregress esitimator depvar [varlist1] [varlist2=varlist_iv] [if] [in] [weight][,options] 其中,estimator 包括 2sls,gmm,liml 三种。varlist1 为模型中的外生变量,varlist2 为模型中的内 生变量,varlist_iv 为模型中的工具变量。 Nonconstant 不包括常数项 Hascons 用户自己设定常数项 CMM 选项: wmatrix(wmtype) robust,cluster clustvar,hac kernel, unadjusted center 权数矩阵采用中心矩 igmm 采用迭代 GMM 估计 eps(#) 参数收敛标准。默认值为 eps(le-6) weps(#) 权数矩阵的收敛标准。默认值为 w eps(le-6) Vce(vcetype) unajusted,robust,cluster clustvar,bootstrap,jackknife,hac kernel level(#)置信区间 First 输出第一阶段的估计结果 Small 小样本下的自由度调整 .estat firststage [,all forcenonrobust] 该命令给出第一阶段的估计结果以及各种统计量,包括排除外生变量的相关性检验。All 选 项给出所有的拟合优度统计量。如果模型存在多个内生变量,则 stata 给出 R2、偏 R2、调整的 R2 、F 统计量;如果模型存在多个内生变量,则 stata 给出 Shea 偏 R2 和调整的偏 R2。 forcenonrobust 给出最小特征值统计量及其临界值,即使采用稳健估计(这一检验的假设条 件是误差项为独立正态分布) 。estat overid[,lag(#) forceweights forcenonrobust] 该命令给出了过度识别约束检验。如果使用 2sls 估计估计,则 Stata 给 Sargan‘s(1958) 和 Basman‘s(1960)卡方统计量,这也是 Wooldridge‘(1995)稳健得分检验。如果采用 liml 估计方 法,则 stata 给出 Anderson and Rubin‘s(1950) 卡方统计量以及 Basmann F 统计量;如果采用 GMM 估计,则 stata 给出 hansen‘s(1982)J 统计量。Lags(#)用于计算得分检验的 HAC(异方差 自相关一致)统计量的过程中进行去噪时设定滞后阶数。如果设定 lag(0),则表示不进行去噪处 理。默认选择为 lag(1)。这一选择仅使用于 2sls 估计方法和设定 vce(hac)选项情况。 Forceweight 表示即使采用 aweights,pweights 或 iweights 也进行检验。Stata 仅对于 fweights 的情况进行检验,其他权数所得到临界值可能不准确。 Forcenonrobust 指在 2sls 或 LIML 估计中即使采用稳健标准差也进行 Sargan and Basmann 检 验(这一检验的假设的假设条件是误差项为独立正态分布) 。 例子: log(wage)=a+b*educ+c*exper+d*expersq+u 怀疑模型教育 (educ) 具有内生性问题, 利用父母接受教育的年数 (fatheduc,motheduc) 作 educ 的工具变量估计上述模型。 (1)利用 2SLS 估计模型 .ivregress 2sls lwage exper expersq (educ=fatheduc motheduc),first 第一阶段回归结果为: educhat=9.1+0.19fatheduc+0.16motheduc+0.05exper (21.34) (5.62) (4.39) (1.12) - 0.001expersq (-0.84) 第二阶段的估计结果为: lwagehat=0.05+0.06educ+0.04exper-0.001expersq (0.12) (1.95) (5.29) (-2.24) (2)检验 educ 的内生性 .quietly ivreg iwage exper expersq {educ=fatheduc motheduc} .est store IV_reg .quietly regress lwage exper expersq educ .est store LS_reg .hausman IV_reg LS_reg 可以得到 hausman 估计量=2.7,P 值=0.44。接受原假设,即 educ 是外生的。 (3)进行过度识别的约束检验 .estat overid 可得 Sargan 统计量=0.38,P 值=0.54 接受原假设。 面板数据估计 首先对面板数据进行声明: 前面是截面单元,后面是时间标识: tsset company year tsset industry year 产生新的变量:gen newvar=human*lnrd 产生滞后变量 Gen fiscal(2)=L2.fiscal 产生差分变量 Gen fiscal(D)=D.fiscal 描述性统计: xtdes :对 Panel Data 截面个数、时间跨度的整体描述 Xtsum:分组内、组间和样本整体计算各个变量的基本统计量 xttab 采用列表的方式显示某个变量的分布Stata 中用于估计面板模型的主要命令:xtreg xtreg depvar [varlist] [if exp] , model_type [level(#) ] Model type 模型 be Between-effects estimator fe Fixed-effects estimator re GLS Random-effects estimator pa GEE population-averaged estimator mle Maximum-likelihood Random-effects estimator 主要估计方法: xtreg: Fixed-, between- and random-effects, and population-averaged linear models xtregar:Fixed- and random-effects linear models with an AR(1) disturbance xtpcse :OLS or Prais-Winsten models with panel-corrected standard errors xtrchh :Hildreth-Houck random coefficients models xtivreg :Instrumental variables and two-stage least squares for panel-data models xtabond:Arellano-Bond linear, dynamic panel data estimator xttobit :Random-effects tobit models xtlogit : Fixed-effects, random-effects, population-averaged logit models xtprobit :Random-effects and population-averaged probit models xtfrontier :Stochastic frontier models for panel-data xtrc gdp invest culture edu sci health social admin,betaxtreg 命令的应用: 声明面板数据类型:tsset sheng t 描述性统计:xtsum gdp invest sci admin 1.固定效应模型估计: xtreg gdp invest culture sci health admin techno,fe 固定效应模型中个体效应和随机干扰项的方差估计值(分别为 sigma u 和 sigma e) , 二者之间的 相关关系(rho) 最后一行给出了检验固定效应是否显著的 F 统计量和相应的 P 值2.随机效应模型估计: xtreg gdp invest culture sci health admin techno,re 检验随机效应模型是否优于混合 OLS 模型: 在进行随机效应回归之后,使用 xttest0 检验得到的 P 值为 0.0000,表明随机效应模型优于混合 OLS 模型 3. 最大似然估计 Ml: xtreg gdp invest culture sci health admin techno,mleHausman 检验 Hausman 检验究竟选择固定效应模型还是随机效应模型: 第一步:估计固定效应模型,存储结果 xtreg gdp invest culture sci health admin techno,fe est store fe 第二步:估计随机效应模型,存储结果 xtreg gdp invest culture sci health admin techno,re est store re 第三步:进行 hausman 检验 hausman fe Hausman 检验量为: H=(b-B)? [Var(b)-Var(B)]-1(b-B)~x2(k) Hausman 统计量服从自由度为 k 的 χ2 分布。当 H 大于一定显著水平的临界值时,我们就认为 模型中存在固定效应,从而选用固定效应模型,否则选用随机效应模型 如果 hausman 检验值为负,说明的模型设定有问题,导致 Hausman 检验的基本假设得不到满 足,遗漏变量的问题,或者某些变量是非平稳等等 可以改用 hausman 检验的其他形式: hausman fe, sigmaless 对于固定效应模型的异方差检验和序列相关检验: Xtserial gdp invest culture sci health admin techno 异方差检验: xtreg gdp invest culture sci health admin techno,fe xttest3 (Modified Wald statistic for groupwise heteroskedasticity in fixed effect model) 随机效应模型的序列相关检验: xtreg gdp invest culture sci health admin techno,re Xttest1 Xttest1 用于检验随机效应(单尾和双尾) 、一阶序列相关以及两者的联合显著 检验结果表明存在随机效应和序列相关,而且对随机效应和序列相关的联合检验也非常显著 可以使用广义线性模型 xtgls 对异方差和序列相关进行修正: xtgls gdp invest culture sci health admin techno, panels(hetero) ,修正异方差 xtgls gdp invest culture sci health admin techno, panels(correlated) ,修正依横截面而变化的异 方差 xtgls gdp invest culture sci health admin techno, panels(hetero) corr(ar1),修正异方差和一阶 序列相关 ar(1) Chapter 1. Start STATA 1. Run STATA Double click the ?STATA 10.0‘ icon in the Window. 2. Define Directory . cd Show the current directory. . cd c:\mydata Change the directory to the one where you will save the data and output files. 3. Create Output File (LOG File) . capture log close Close log files, if any, currently open. . log using c:\stata10\mylog, text Create a new log file on the directory c:\stata10 under the file name ?mylog‘ in ?text‘ format (mylog.txt). A log file saves all results (including STATA commands you have used) for review. You can copy and paste the results directly from the STATA window or open it using either Notepad or MSWord. . log using c:\stata10\mylog, text replace Replace the old log file, ?mylog‘, saved already with the updated one under the same log file name. . log close Close the current log file. Any commands and results are saved in the log file, ?mylog‘, before closing. . log off Temporarily stop the log file. . log on Restart the log file. 4. Create Command File (DO File) Open do-file editor Type in commands that you want to execute sysuse auto, clear log using c:\stata10\mylog1, text reg mpg length weight foreign sort foreign by foreign: reg mpg length weight foreign log close Save the file with an extension Ddo.‖ For example, c:\stata10\mydo.do . do c:\stata10\mydo.do (or run c:\stata10\mydo.do) Execute the do file, ?mydo‘. Run is different in that it does not display the execution on the screen Use Ddo‖ instead of Drun‖ when generating a log file Chapter 2. Data Input There are three ways to enter data into STATA. 1. Load a data set . use smoke.dta, clear Load the dataset ?smoke.dta‘ (which should be saved in a STATA -format) in the memory and clear other data in use from the memory. 2. Data in an Excel format Copy the selected cells in Excel, open the STATA editor, place the cursor on the cell that will be the upper left corner, and paste. 3. Type the data in . input educ cigpric age You can input data with variables named Deduc‖ Dcigpric‖ Dage‖. Type in the following values one by one for each observation. 16 60.506 46 16 57.883 40 12 57.664 58 13.5 57.883 30 10 58.32 17 6 59.34 86 12 57.883 35 Type in Dend‖ to finish inputting 4. Data management . clear Drop any data set in memory . save c:\mydata\smoke Save the data in a file named Dsmoke‖ in directory Dc:\mydata‖ You can save the file in any other directory of your choice . edit Allow one to input data or alter the data currently loaded using the STATA editor. Type in the following data for each observation 16 60.506 46 16 57.883 40 12 57.664 58 13.5 57.883 30 10 58.32 17 6 59.34 86 12 57.883 35 Click Dpreserve‖ to end l rename educ schooling change the name of the variable from Deduc‖ to Dschooling‖ l save c:\stata10\auto1, replace replace the old data Dsmoke‖ with a new (modified) one under the same data file name l make a Draw‖ file using any word processor Type in the following data (comma- or tab-separated) and save it as a text file named c:\stata10\auto2.raw make, mpg, weight, price AMC Concord, 1, 22, 2930 AMC Pacer, 2, 17, 3350 AMC Spirit, 3, 22, 2640 Buick Century, 4, 20, 3250 Buick Electra, 5, 15, 4080 l clear l insheet using c:\stata10\auto2.raw Loads the data in STATA format l save c:\stata10\auto2 l make a Draw‖ file using any word processor Type in the following data (space-separated) using notepad or wordpad and save it as a text file named c:\stata10\auto3.raw STATA could not read the double quotation mark in MS Word. But, it can read the double (or single) quotation mark in other basic programs, such as wordpad or notepad. DAMC Concord‖ 1 22 2930 DAMC Pacer‖ 2 17 3350 DAMC Spirit‖ 3 22 2640 DBuick Century‖ 4 20 3250 DBuick Electra‖ 5 15 4080 l clear l infile str14 make id mpg weight using c:\stata10\auto3.raw Loads the data in STATA format l save c:\stata10\auto3 l make a Draw‖ file using any word processor Type in the following data and save it as a text file named c:\stata10\auto4.raw AMC Concord
AMC Spirit
Buick Century
Buick Electra
l clear l infix 1: str18 make 1-18 2: mpg 1-2 weight 3-6 price 7-11 using c:\stata10\auto4.raw Loads the data in STATA format l save c:\stata10\auto4 l outsheet using c:\stata10\auto4 Writes data in a spreadsheet format and saves it in a file named c:\stata10\auto4.out l exit Exist from STATA 5. Other Useful Commands LARGE FILES l set memory 512000 Sets the amount of memory STATA will use to be 512000 kilobytes l set memory 512000, permanently Specifies that in addition to making the change right now, Stata will remember the new limit and use it in the future when l set matsize 800 Sets the maximum number of variables that can be included in any of Stata's estimation commands l set matsize 800, permanently Specifies that, in addition to making the change right now, Stata will remember the new limit and use it in the future when l query memory Displays memory settings MERGE FILES l sysuse auto l keep make price mpg l sort make Must sort before merging l save c:\stata10\auto_1 l browse l sysuse auto l drop price mpg l sort make Must sort before merging l save c:\stata10\auto_2 l merge make using c:\stata10\auto_1 l tab _merge l browse l l use c:\stata10\auto_1[u1] , clear l drop if make==‖Audi Fox‖ l sort make l save, replace l browse l use c:\stata10\auto_2 l drop if make==‖BMW 320i‖ l drop if make==‖Buick Opel‖ l sort make l save, replace l merge make using c:\stata10\auto_1 If _merge==1, the original file has the observation, but the merging file does not If _merge==2, the merging file has the observation, but the original file does not If _merge==3, both files have the observation l tab _merge browse RESHAPE A FILE l sysuse bplong l reshape wide bp, i(patient) j(when) Reshapes the file to be wide. That is, time-variable is displayed in rows Chapter 3. Variable Description & Management l clear l use c:\stata10\auto Loads a data named auto.dta previously stored at c:\stata10 Can also type in Duse c:\stata10\auto, clear‖ instead l describe (or enter F3) Shows what is in data c:\stata\auto.dta Can see the number of variables & observations Can also see the name & description of each variable l list in 1 Allows us to see the actual data of observation 1 l list in 1/6 Allows us to see the actual data from observation 1 to 6 l summarize rep78 (or sum rep78) Shows more about variable Drep78‖ across all observations by summarizing it Shows number of observations, mean, standard deviation, minimum value, and maximum value Rep78: Repair record in 1978 l summarize rep78, detail Shows 1, 5, 10, 25, 50, 75, 90, 99 percentiles Gives largest and smallest four figures Gives number of observation, mean, standard deviation, variance, skewness, and kurtosis. Kurtosis measures the degree of peakedness of a distribution or the degree of fat tails of a distribution l gen mpgsq=mpg^2 Generates a new variable named Dmpgsq‖ Mpg: mileage per gallon l rename mpgsq mpgs Changes the variable‘s name from Dmpgsq‖ to Dmpgs‖ l drop mpgs Drop the variable name Dmpgs‖ from the data set l egen mmpg=mean(mpg) Generates a new variable using a special function Generates a variable named Dmmpg‖ which takes the mean value of variable Dmpg‖ Examples of formula: max, min, mean, median, etc. l drop mmpg l sort price Sorts the observations in ascending order of Dprice‖ l gsort -price Sorts the observations in descending order of Dprice‖ l drop if price&=5000 Drop observation if the value of variable Dprice‖ is equal or greater than 5,000 l save c:\stata10\auto5 l use c:\stata10\auto l drop if price&5000 l save c:\stata10\auto6 l append using c:\stata10\auto5 Stacks data Dauto6‖ on top to data Dauto5‖ Chapter 4. Tabulation l sysuse dir List the names of data sets shipped with STATA l sysuse auto, clear Loads auto.dta that is shipped with STATA Clear option clears any file already in the memory FREQUENCY TABLE l tabulate rep78 (or tab rep78) Shows frequency, percentage, cumulative percentage of each categorical value l tabulate rep78, plot (or tab rep78, plot) Shows frequency of each categorical value The Dplot‖ option plots frequency l list if rep78==1 List all the observations in the data if variable named Drep78‖ takes a value of 1 l list if rep78==5 List all the observations in the data if variable named Drep78‖ takes a value of 5 CROSS TABULATION l tabulate rep78 foreign Generates a frequency table of both variables Drep78‖ and Dforeign‖ l tabulate rep78 foreign, column Generates a frequency table of both variables Drep78‖ and Dforeign‖ with column percent, i.e. the percent each Drep78‖ category is of the overall l tabulate rep78 foreign, row Generates a frequency table of both variables Drep78‖ and Dforeign‖ with row percent, i.e. the percent each Dforeign‖ category is of the overall l tabulate rep78 foreign, cell Generates a frequency table of both variables Drep78‖ and Dforeign‖ with cell percent, i.e. the percent each Drep78‖ and Dforeign‖ category is of the overall l tabulate rep78 foreign, column nofreq Generates a frequency table of both variables Drep78‖ and Dforeign‖ with column percent, but suppress actual count l tabulate foreign, summarize (rep78) Compares the mean, standard deviation, and frequency of Drep78‖ for each category of Dforeign‖ l tabulate rep78 foreign, summarize (weight) Compares the mean, standard deviation, and frequency of Dweight‖ for each category of Drep78‖ and Dforeign‖ Chapter 5. Graphics SCATTER PLOTS l sysuse auto, clear l scatter price weight Draws a scatter plot between variable Dweight‖ and Dprice‖ l correlate weight price (or corr weight price) Computes a correlation coefficient between variable Dweight‖ and Dprice‖ l sort foreign Sort observations by the value of Dforeign‖ l by foreign: sum weight price Summarize Dweight‖ and Dprice‖ by each value of Dforeign‖ l generate weightd=weight if ~foreign Generates a new variable named Dweightd‖ which takes a value of Dweight‖ if the observation is a domestic car and a missing value if the observation is a foreign car l generate weightf=weight if foreign Generates a new variable named Dweightf‖ which takes a value of Dweight‖ if the observation is a foreign car and a missing value if the observation is a domestic car l scatter weightd weightf price Draws a scatter plot between Dweight‖ and Dprice‖ for each value of Dforeign‖ in the same plot l scatter weight price, by(foreign ) Draws a scatter plot between Dweight‖ and Dprice‖ for each value of Dforeign‖ in multiple plots l scatter mpg displ Draws a scatter plot between Dmpg‖ and Ddispl‖ Displ: displacement l scatter mpg displ, saving(c:\stata10\scatter) Saves the scatter plot in a file named scatter.gph l graph use c:\stata10\scatter Read the saved scatter plot from the file named scatter.gph l scatter mpg displ, msize(large) Enlarges the marker font size. Also try out Dvtiny,‖ Dtiny,‖ Dvsmall,‖ Dsmall,‖ Dmedsmall,‖ Dmedium,‖ Dmedlarge,‖ Dlarge,‖ Dvlarge,‖ Dhuge,‖ Dvhuge,‖ Dehuge‖ l scatter mpg displ, msymbol(triangle) Changes the marker type to be a triangle. Also try out Dpoint,‖ Dnone,‖ Dcircle,‖ Dsquare,‖ Ddiamond,‖ Dplus,‖ Dx,‖ Dsmcircle,‖ Dsmsquare,‖ Dsmtriangle,‖ Dsmdiamond,‖ Dsmplus,‖ Dsmx,‖ Dcircle_hollow,‖ Dsquare_hollow,‖ Dtriangle_hollow,‖ Ddiamond_hollow,‖… l scatter mpg displ, mcolor(green) Changes the marker color to be a green. Also try out Dblack,‖ Dnone,‖ Dwhite,‖ Dyellow,‖ Dgold,‖ Dgreen,‖ Dlime,‖ Dmint,‖ … l scatter mpg displ, msize(small) msymbol(circle_hollow) mcolor(red) Produces a scatter plot with a small marker in red taking a shape of a hollow circle l scatter mpg displ, title(MPG vs. Engine Displacement) subtitle(1978 Automobile Data) Inserts titles in the graph l scatter mpg displ, scheme(s1mono) Changes into black and white and puts a border around the graph l scatter mpg displ, scheme(economist) Changes the graph into an Economist style l scatter mpg displ, yline(25) Overlays a horizontal line at 25 l scatter mpg displ, mlabel(foreign) Uses variable Dforeign‖ as a plotting symbol l graph matrix displ weight gear_ratio Draws a scatter plot matrix HISTOGRAMS l histogram mpg, bin(15) Draws a histogram using 15 bins l histogram mpg, bin(15) normal Draws a histogram using 15 bins with an overlaid normal distribution curve l histogram mpg, bin(15) normal by(foreign) Draws two histograms: one for foreigners and the other for domestics BOX-AND-WHISKER PLOTS l graph box price, by(foreign ) Draws box-and-whisker plots Line in the middle of the box is 50th percentile (or median) of the data Box extends from the 25th percentile (X25) to the 75th percentile (X75) This range = interquartile range = IQR Upper whisker is the largest data point less than or equal to X75 + 1.5IQR Lower whisker is the smallest data point greater than or equal to X25 C 1.5IQR BAR CHARTS l sysuse citytemp, clear Loads STATA sample data set named City Temperature Data l graph bar (mean) tempjuly tempjan, over(region) Draws a bar chart of temperature in July and January by region LINE CHARTS l sysuse uslifeexp, clear Loads STATA sample data set named U.S. Life Expectancy Data l line le year Draws a line chart le: life expectancy PIE CHARTS l clear l input sales marketing research development 1. 12 14 2 8 2. end l graph pie sales marketing research development HOW TO COPY AND PASTE GRAPHS While the graph window is open, go to menu EDIT and click COPY GRAPH Go to a your Word file and PASTEChapter 6. Hypotheses Testing DISTRIBUTIONS l sysuse auto, clear l gen pvalue=norm(1[u2] ) Returns the left-tail p-value when the critical value is 1 under the standard normal distribution curve. That is, P[-? & Z & 1] l list pvalue in 1 l gen zvalue=invnorm(0.75) Returns the left-tail z-value when the p-value is 0.75 under the standard normal distribution curve. That is, if norm(z) = 0.75 then invnorm(0.75) = z. l list zvalue in 1 l gen pvalue2=ttail(30, 2) Returns the right-tail p-value when the critical value is 2 under the t-distribution curve with 30 degrees of freedom. This is, P[T & 2] if degrees of freedom is 30 l list pvalue2 in 1 l gen tvalue=invttail(30, 0.05) Returns the right-tail t-value when the p-value is 0.05 under the t-distribution curve with 30 degrees of freedom. That is, if ttail(30, t) = 0.05, then invttail(30, 0.05) = t. l list tvalue in 1 l gen pvalue3=Ftail(30, 40, 2) Returns the right-tail p-value when the critical value is 2 under the F-distribution curve with 30 numerator and 40 denominator degrees of freedom. l list pvalue3 in 1 l gen fvalue=invFtail(30, 40, 0.05) Returns the right-tail F-value when the p-value is 0.05 under the F-distribution curve with 30 numerator and 40 denominator degrees of freedom. ONE SAMPLE T-TEST l sysuse auto, clear l ttest mpg=20 One-sample t-test l ttest price=length Paired t-test l ttest price=length, unpair Unpaired two sample t-test with equal variance l ttest price=length, unpair unequal Unpaired two sample t-test with unequal variance (by Satterwaite‘s degrees of freedom) TWO SAMPLE T-TEST l sort foreign l ttest mpg, by(foreign) Unpaired two population t-test with equal variance l ttest mpg, by(foreign) unequal Unpaired two population t-test with unequal variances l sysuse citytemp, clear Loads city temperature data l ttest tempjan=tempjuly Paired-sample t-test with equal variances l ttest tempjan=tempjuly, unpaired Unpaired-sample t-test with equal variances l ttest tempjan=tempjuly, unpaired unequal Unpaired-sample t-test with unequal variances l sysuse census, clear Loads 1980 census data by state l sort region l ttest medage if region==1 | region==4, by(region) Unpaired two population t-test with equal variance l sysuse auto, clear l xtile quart=price, nq(4) Group price into quartiles l tab quart l sort quart l by quart: sum price l ttest weight if quart==1 | quart==4, by(quart) ANOVA TEST l edit Type in the following data for each observation 1 117.5 1 113.8 1 104.4 2 48.9 2 50.4 2 58.9 3 70.4 3 86.9 4 87.7 4 67.3 Click preserve to end l rename var1 treatment l rename var2 weight l anova weight treatment Produce analysis-of-variance tableChapter 7. Regression SIMPLE LINEAR MODEL OLS l sysuse auto, clear l reg weight length Run regress with a constant l reg weight length, nocons Run regress without a constant FITTED LINE IN SCATTER PLOT l reg mpg displ Regress Dmpg‖ on Ddispl‖ and a constant l predict pmpg Obtain predicted values from the regression l twoway (scatter mpg displacement) (line pmpg displacement) Overlay a fitted line over the scatter plot MULTIPLE LINEAR MODEL OLS l reg price weight mpg foreign CONTROL l reg price foreign This will show no relationship between ?foreign‘ and ?price‘ But what if foreign cars are lighter and that is pulling down the price? What would be the relationship between ?price‘ and ?foreign‘ among the cars with similar car weight? l pwcorr foreign weight l sum weight, detail l gen dum_w=1 l replace dum_w=2 if weight&=2240 l replace dum_w=3 if weight&=3190 l replace dum_w=4 if weight&=3600 l sort dum_w l by dum_w: reg price foreign What are the coefficients on foreign? Last regression is not estimated because our ?foreign‘ variable is constant. Remember our variance formula. l reg price foreign weight What happens to the coefficient on foreign? l reg price foreign This will show no relationship between ?foreign‘ and ?price‘ But what if foreign cars are shorter and that is pulling down the price? What would be the relationship between ?price‘ and ?foreign‘ among the cars with similar length? l pwcorr price foreign length l sum length, detail l gen dum_l=1 l replace dum_l=2 if length&=170 l replace dum_l=3 if length&=193 l replace dum_l=4 if length&=204 l sort dum_l l by dum_l: reg price foreign What are the coefficients on foreign? Last regression is not estimated because our ?foreign‘ variable is constant. Remember our variance formula. l reg price foreign length What happens to the coefficient on foreign? COLLINEARITY l gen domestic=~foreign Generate a variable named domestic l reg price weight mpg foreign domestic Case of perfect collinearity What happens to the variable domestic? l reg price displ l reg price displ weight Compare the t-values and the F-values l corr displ weight Case of multicollinearity l reg price displ weight l vif Displays VIF and 1/VIF for each right-hand-side variable VIP = 1/(1-R2) from a regression where the variable of concern is on the left-hand-side and all other independent variables are on the right-hand-side (if above 0.5, evidence of multicollinearity) CORRELATION l corr displ weight rep78 Uses observations that exist for all the variables l pwcorr displ weight rep78 l pwcorr displ weight rep78, obs l corr displ weight rep78, covariance l pwcorr displ weight rep78, sig l pwcorr displ weight rep78, sig obs l pwcorr displ weight rep78, star(0.05) RIGHT HAND SIDE DUMMY VARIABLES l sysuse auto, clear l xi: reg mpg weight i.rep78 Regression with multiple dummy variables l xi: reg mpg i.foreign|weight Regression with a Dforeign‖ dummy variable that interacts with a continuous variable l xi: reg mpg i.foreign*weight Regression with a Dforeign‖ intercept dummy and a Dforeign‖ dummy variable that interacts with a continuous variable l xi: reg mpg i.foreign*i.rep78 Regression with dummy variables interacting with each other Chapter 8. More on Regressions F-TESTS l reg mpg foreign weight length l test length=0 F-test if coefficient on length is zero Compare p-value from t-test l test weight=length F-test if weight=length l test (foreign/100)-length=weight F-test if (foreign/100)-length=weight l test foreign=0 F-test if coefficient on foreign is zero l test foreign=0 l test length=0, accumulate Joint hypotheses testing F-test if coefficients on Dforeign‖ and Dlength‖ are zero l test foreign=0 l test length=0, accumulate l test weight=0, accumulate F-test if coefficients on Dforeign,‖ Dlength,‖ and Dweight‖ are zero Compare it with goodness of fit test l test foreign weight length Same as above l test Shows the last test again REGRESSION DIAGNOSTICS l reg mpg foreign weight length l avplot weight Draws added-variable plots (also known as partial regression line) Partial regression line: fitted line between two residuals One residual is estimated by regressing mpg on foreign and length The other residual is estimated by regressing weight on foreign and length l rvfplot, yline(0) Residual-versus-fitted plot If assumptions are correct, there should be no pattern in the graph l reg price displ l reg price displ, beta Standardized coefficients l reg price weight mpg foreign l predict estu if e(sample), rstudent Generates studentized residuals l list estu if abs(estu)&1.96 Shows studentized residuals if its absolute value is greater than 1.96 l reg price weight mpg foreign if abs(estu)&1.96 l reg price weight mpg foreign l dfbeta Generates DFBETA l list DFweight DFmpg DFforeign if abs(DFweight)&2/sqrt(74) | abs(DFmpg)&2/sqrt(74) | abs(DFforeign)&2/sqrt(74) Shows DFBETA if its absolute value is greater than 2/sqrt(N) N=number of observation l reg price weight mpg foreign if abs(DFweight)&2/sqrt(74) & abs(DFmpg)&2/sqrt(74) & abs(DFforeign)&2/sqrt(74) l reg price weight mpg foreign HETEROSCEDASTICITY l reg mpg weight l rvfplot, yline(0) l reg mpg weight, robust Use White‘s robust standard errors in the presence of heteroscedasticity SERIAL-CORRELATION l sysuse uslifeexp, clear Load sample STATA file named US Life Expectancy l tsset year Set variable Dyear‖ as the time variable l reg le_male le_female l dwstat Computes Durbin-Watson statistics l rvfplot, yline(0) Residual-versus-fitted plot l prais le_male le_female, corc Cochraine-Orcutt [u1]D D data in memory would be lost‖ D [u2]Unknown function norm()‖ Cannot progress. Robust regression is an alternative to least squares regression when data is contaminated with outliers or influential observations and it can also be used for the purpose of detecting influential observations. 汉密尔顿,应用 stata 做统计分析,p207 rreg 和 qrg 都能抵抗特异值的牵引, 在非正态和重尾型误差分布的情况下便能取得高于 OLS 的估计效率。但它们共享 OLS 关于误差独立和同分布的假定,因此,它们的标准误、统计 检验和置信区间在误差异分布或误差相关时也不可信。 在使用 reg 或其他模型命令是,想要放松误差独立和同分布假定的话,stata 也提供了估计 文件标准误的选项,robust。 p213 rreg 和 qreg 能较好地处理 y 上的特异值,除非是有异常 y 值的案例的同时还与异常的 x 值 (杠杆作用)。 p215 图 9.3 显示,reg 和 qreg 对于杠杆作用(即 x 上特异值)并不稳健,然而,rreg 程序 不但削弱了较大残差案例的权重,而且还自动地将那些 cook 的 D(影响)统计量大于 1 的 案例搁置在外了。当我们将 y3 与 x3 回归时,rreg 不再理睬这个最有影响力的观察案例, 在其他 19 个案例基础上求出了一条更加合理的正斜率的回归线。 将影响特大的案例至于不顾,就像 rreg 所为,提供了一种简单的但是并不十分安全的方式 杠杆作用来处理杠杆作用。其实还存在着更综合的方法,成为有限影响回归 (bounded-influence regression),也可在 stata 中执行。蒙特卡罗试验确认,像 rreg 和 qreg 这样的估计方法应用于重尾(特异值倾向)但对称的误差分布时,常能保持无偏,效 率要优于 OLS 估计 p216, 这就表明,在使用 rreg 或类似估计方法于偏态误差数据时要有所权衡:在 y 截距估计上存 在有偏风险, 但是回归系数估计可望无偏, 并相对更精确。 在许多场合, 斜率比截距有意义, 因此这种得失是值得的。 P222 数据存在特异质倾向或非正态误差时,rreg 和 qreg 都比 ols 的效果好。仍然当误差不服从独 立同分布时,那么由 reg,rreg,qreg 等方法估计出来的结果可能不够准确。 对这一 OLS 回归的更可信的标准误和置信区间可以用 robust 选项来得到。 一直不明白 stata 中有些命令最后要加的 nolog 是什么意思?比如做 logit 回归:logit y x1 x2 x3,nolog nolog suppresses display of the iteration log. . xtreg fatal beertax spircons unrate perincK, mle nolog Random-effects ML regression Group variable: state Random effects u_i ~ Gaussian Number of obs Number of groups = = 336 48 7Obs per group: min = avg = 7.0 max = 7 LR chi2(4) = Prob & chi2 67.39 = 0.0000Log likelihood = 12.784035-----------------------------------------------------------------------------fatal | Coef. Std. Err. z P&|z| [95% Conf. Interval] -------------+---------------------------------------------------------------beertax | -.0 0.188 -.68891 spircons | . 0.000 .23692 unrate | -.9 0.000 -.0561344 -.0201589 perincK | . 0.015 .81984 _cons | . 0.166 -..565636 -------------+---------------------------------------------------------------/sigma_u | .41 1.113243 /sigma_e | .76 .1737525 rho | .93 .9815318 -----------------------------------------------------------------------------Likelihood-ratio test of sigma_u=0: chibar2(01)= 479.84 Prob&=chibar2 = 0.000 . estimates store MLE . xtreg fatal beertax spircons unrate perincK, mle Fitting constant-only model: Iteration 0: log likelihood = Iteration 1: log likelihood = Iteration 2: log likelihood = Iteration 3: log likelihood = Iteration 4: log likelihood =-41.....911211Fitting full model: Iteration 0: log likelihood = -74.726121 Iteration Iteration Iteration Iteration Iteration Iteration1: 2: 3: 4: 5: 6:log log log log log loglikelihood likelihood likelihood likelihood likelihood likelihood= = = = = =-42......784035 Number of obs Number of groups = = 336 48 7Random-effects ML regression Group variable: state Random effects u_i ~ GaussianObs per group: min = avg = 7.0 max = 7 LR chi2(4) = Prob & chi2 67.39 = 0.0000Log likelihood = 12.784035-----------------------------------------------------------------------------fatal | Coef. Std. Err. z P&|z| [95% Conf. Interval] -------------+---------------------------------------------------------------beertax | -.0 0.188 -.68891 spircons | . 0.000 .23692 unrate | -.9 0.000 -.0561344 -.0201589 perincK | . 0.015 .81984 _cons | . 0.166 -..565636 -------------+---------------------------------------------------------------/sigma_u | .41 1.113243 /sigma_e | .76 .1737525 rho | .93 .9815318 -----------------------------------------------------------------------------Likelihood-ratio test of sigma_u=0: chibar2(01)= 479.84 Prob&=chibar2 = 0.000 不好意思,挖了这个坟。 。 。因为我也有同样的问题。 。 。然后就 run

我要回帖

更多关于 jb统计量怎么看 的文章

 

随机推荐