STATA 按STKCD YEAR 合并所有的kamd

use linshi0510,clear
bys stkcd year:gen bz=_n
local k=_N
local aa ""
local bb ""
local dd ""
gen bzz=""
format bzz %200s
forvalues i=1/`k'{
    local aa=stkcd[`i']
    local bb=year[`i']
    if bz[`i']==1 & `i'!=1{
        replace bzz="`dd'" if stkcd==stkcd[`i'-1] & year==year[`i'-1]
        local dd ""
    }
    if bz[`i']>=1{
        local dd="`dd'"+kamd[`i']
        disp "`dd'"
        disp length("`dd'")
    }

    
}
 replace bzz="`dd'" if stkcd==stkcd[`k'] & year==year[`k']

 

posted @ 2023-05-10 11:28  myrj  阅读(127)  评论(0编辑  收藏  举报