tempname pc
preserve
keep if `touse'
keep `thres'
duplicates drop /*去除门槛变量中的重复值*/
local qnt = _N /*对于门槛变量的观察值小于400的情况,采用真实个数*/
if `qn' == 400 & `qnt'<400{
local qn = int(0.94*`qnt')
}
else if `qn'!= 400 & `qn'>`qnt'{
local qn = `qnt'
n dis in g "Note: there are only " in y `qnt' in g " unique values in threshold variable " in y "`thres'"
n dis in g " qn is now specified as " in y `qnt'
}
mat `pc' = J(`qn',1,0) /*存储分位数的向量*/
_pctile `thres' , n(`=`qn'+1')
forvalues i = 1(1)`qn'{
mat `pc'[`i',1]= r(r`i')
}
restore,preserve
keep if `touse'
sum
local NT = r(N)
tempname data
save "`data'",replace /*以备后面BS时调用*/
eret clear
local lim_obs = `minobs'
} /*qui over*/