现对数据稍作修改,把roa变成绝对值,其余不变(数据为附件的match2),要求为“针对其中sp=1的公司,寻找sp=0,且同ind,同daq,roa最接近的样本(配对样本不能重复)”。
*原先的程序基本不变,只去掉变量year即可。另外,若配对样本观测值有多个,只取stkcd最小的那个。
use match2,clear
bys year ind daq sp (stkcd): g exp=_n if sp
bys year ind daq: 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 daq exp: egen r=sum(roa*sp)
g q=abs((roa-r)/r) if !sp
bys year ind daq exp: egen u=min(q) if !sp
drop if u!=q&!sp
egen mat=group(year ind daq exp)
bys mat sp (stkcd): replace exp=_n
drop if exp>1
drop exp-u