样本公司的哑变量sp为1,需要从哑变量sp为0的公司的寻找配对样本,条件是年份year相同,行业ind相同。
我运行了前辈给的程序
bys year ind sp (stkcd):g exp=_n if sp
bys year ind :egen s=max(exp)
drop if s==.
expandcl s if !sp,cl(year stkcd) gen(g)
bys year stkcd:replace exp=_n if !sp
bys year ind exp:egen r=sum(asset*sp)
g q=abs(asset-r) if !sp
sort q stkcd
count if q<.
loc m=r(N)
forv i=1/`m'{
loc v=stkcd[`i']
replace q=. if stkcd==`v'&_n>`i'&!sp
}
drop if q==.&!sp
bys year ind exp:egen u=min(q) if !sp
drop if u!=q&!sp
egen mat=group(year ind exp)
drop exp-u
sort mat sp
但是样本量太大,一直跑不出结果来,真心求问还有什么解决办法。