@RobPratt @Ksharp Maybe I didn't explain the objective function to well. Hopefully, the modified code will explain it better, assuming its correct. I changed the input dataset slightly to account for roll up (~16k as opposed to ~200k) and to calculate the def rate accurately. pd def cust_cnt 0.001% 0 1 0.002% 0 3 0.003% 0 2 n=nrow(start_end); n1=nrow(xx); temp=j(n1,3,.); temp1=j(n,1,.); do i=1 to n; idx=start_end[i,1]:start_end[i,2]; do j=start_end[i,1] to start_end[i,2]; temp[j,1]=have[j,1]; temp[j,2]=sum(have[idx,2])/sum(have[idx,3]); temp[j,3]=abs(temp[j,1]-temp[j,2]); end; temp1[i,1]=sum(temp[idx,3]); end; obj=sum(temp1); return (obj); thanks
... View more