Stata笔记 北京科技大学 联系客服

发布时间 : 星期四 文章Stata笔记 北京科技大学更新完毕开始阅读7b6abd45aa00b52acec7ca22

. order CompanyCode y 将公司代码排第一列,年份排第二列

help reshape

reshape wide Incmope- InventoryTurnoverRatio,i( CompanyCode) j( y)一定在i和前面有逗号!

. g Accrecv2009mean=( Accrecv2009+ Accrecv2008)/2 reshape long .....,

----------4.17---------------

destring 变量名,replace 使字符型变数值型

g y=real(substr( Accper,1,4)) 从字符型取年份,并变成数值型,从左向右取四位

. drop Accper

. order Stkcd y 按变量1,变量2 排序

. keep if y==2000|y==2001

. g infee=ln( Tcost) 对Tcost取对数产生infee变量

. drop Tcost

g brandname=1 if substr( Dadtunit,1,4)==\普华\(4441 missing values generated)

. replace brand=1 if substr( Dadtunit,1,4)==\德勤\(51 real changes made) . drop Dadtunit

. g opinion=0 if Audittyp==\标准无保留意见\

. replace opinion=1 if opinion==. 将缺失值替代为1 (214 real changes made)

-----------------

import excel \sheet(\ . br

. g y=year( _EndDt)

. drop _EndDt

. g inasset=ln( _Totass) 对总资产取对数 . g invrec=( _Accrecv +_Invtr)/ _Totass drop _Accrecv _Invtr _Totass

. order _A_Stkcd y

. save bs

file bs.dta saved

. clear

. import excel \sheet(\

. duplicates drop _Stkcd y,force删除重复的

Duplicates in terms of _Stkcd y (42 observations deleted)

. drop if _n<3 删除前两行,_n就是序号的意思 (2 observations deleted)

merge 1:1 _Stkcd y using bs1

variables _Stkcd y do not uniquely identify observations in the using data 合并有重复的,在自子数据库 use bs1

. duplicates drop _Stkcd y,force 与对母数据库同样操作,都除重后就可以合并了

Duplicates in terms of _Stkcd y

(42 observations deleted)

. merge 1:1 _Stkcd y using is2

Result # of obs. -----------------------------------------

not matched 30

from master 12 (_merge==1) from using 18 (_merge==2)

matched 5,077 (_merge==3)

-----------------------------------------

. g len=length( _Stkcd) 对股票代码取长度 看看有没有长度为0的就是空的

. su len 看看len的情况,summarize 发现有长度为0的

Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------

len | 5131 5.948548 .5532848 0 6

. list if len==0

. drop if len==0 删掉len=0的 (44 observations deleted)

. drop len 去除len变量

Merge之后 算ROE=净利润/所有者权益

. g roe= _Netprf/ _TotSHE

. g list=1 if roe>0 & roe<=0.02 产生哑变量list,若。。。时就=1 “和”一定用&

(4758 missing values generated)

. replace list=0 if roe==. (0 real changes made)

save bsis3 合并的叫这个 reshape wide roe, i( _Stkcd) j( y) 转置 (note: j = 2010 2011)

Data long -> wide ----------------------------------------------------------------------------- Number of obs. 5077 -> 2669 Number of variables 3 -> 3 j variable (2 values) y -> (dropped) xij variables:

roe -> roe2010 roe2011

.

g right=1 if 0.06

. replace right=0 if right==. (2341 real changes made) . drop roe2010 roe2011

. save right

Use fee2

Duplicates report Duplicates drop

Duplicates list 变量1 变量2,force

Merge时候注意变量名相同,要除重 合并fee3和bsis叫feebsis

drop _merge 去掉_merge才能继续合并

merge m:1 _Stkcd using right 一对多得合并 合并后keep if _merge==3然后drop _merge

su infee- right 看看有没有缺失变量 .drop if infee==.

save rightfeebsis合并的文件

su infee- right if y==2010 注意是两个等号,描述性统计

pwcorr infee- right if y==2010 自变量之间相关性不要太大,自变量因变量之间大一点好

. pwcorr infee- right if y==2011, sig star(0.05)

| infee brandn~e opinion right -------------+------------------------------------ infee | 1.0000 | |

brandname | 0.5387* 1.0000 | 0.0000 |

opinion | -0.0979* -0.0311 1.0000 | 0.0000 0.1735 |

right | -0.0507* 0.0011 -0.0721* 1.0000 | 0.0264 0.9618 0.0016

---------------------------------4.24-----------------------------

Pwcorr 变量1-变量n sig star(0.1) 上面一行是系数(被标星),下面是p值

Save xx,replace 将xx替换成现在的文件

Egen average=mean(变量名) 扩展,可以含有函数的产生 reg infee brandname- right if y==2010 交互项y=x+z+xz(乘积,z为调节项) g xx=变量1*变量2

reg 变量1 变量2 xx 就是含有交互项的回归

p(概率,面积)越小越好,t越大越好

vif 做完回归后做,>10不好,可能是否存在多重共线性。方差膨胀因子