Hi Stata folks, I am working on a dataset where each ID is associated with a numeric value comprised of 0 and 1s. What I need to do now is to extract part of the numeric values based on a rule. For instance, for a value of 1001100, I need to extract the last three digits (100); for a value of 1010110, I need to extract the last two digit (10); for a value of 1011000, I need to extract the last four digits (1000). The rule is to extract the part where the last 1 was seen (together with the 0s behind the last 1s). Is there a way to achieve this using stata? Thanks!