Here's my problem: select(1,0) \ 999 gives a conformability error. Apparently, select(1,0) is not conformable with anything except itself, since select(1,0) , 999 errors out but select(1,0)\select(1,0) works, as does the same with a comma. Strangely (to me), select((1\1),(0\0)) \ 999 runs without a hitch.
Long version: There are three products that might sell out in future days. I've predicted these sellouts in a 0/1 matrix (1=sellout expected, days on rows, products on columns) and want to grab the day of the first predicted sellout for each product. If no sellout is predicted, there's a default "day" of 999:
I realize I could write a special rule for treatment of the one-day case:
However, that's terribly clunky and I'm sure there's a way around this conformability error. How could select(1,0) be conformable with nothing?
Long version: There are three products that might sell out in future days. I've predicted these sellouts in a 0/1 matrix (1=sellout expected, days on rows, products on columns) and want to grab the day of the first predicted sellout for each product. If no sellout is predicted, there's a default "day" of 999:
Code:
// two days left works fine: days = 51\52 pred_sellout = (0,0,1) \ (0,0,1) res = J(1,3,.) for (j=1;j<=3;j++) res[j] = (select(days,pred_sellout[,j])\999)[1] // one day left breaks days = 52 pred_sellout = (0,0,1) res = J(1,3,.) for (j=1;j<=3;j++) res[j] = (select(days,pred_sellout[,j])\999)[1] // conformability error for j = 1
Code:
res[j] = length(days) > 1 ? (select(days,pred_sellout[j])\999)[1] : (pred_sellout[j] ? days : 999)
Comment