- // 同行业其他公司 (不包括本公司) 平均值
- webuse grunfeld, clear
- // 前 4 家公司为第 1 产业;后 6 家公司为第 2 产业。
- gen ind = cond(company <= 4, 1, 2)
- // Method 1
- bys ind: egen tem1 = total(invest)
- bys ind: egen tem2 = count(invest)
- gen wanted1 = (tem1-invest)/(tem2-1)
- // Method 2 (ssc install rangestat)
- rangestat (mean) invest, interval(ind 0 0) exclude
- // Method 3 (ssc install asrol)
- bys ind: asrol invest, stat(mean) xf(focal)
- asser invest_mean == mean_invest