Dear listers,
I am grateful to Michael Blasnik, Scott Merryman, Russell Diamond and Nick
Cox for their helpful advice and code.
Russell's code worked best, either as it was, or with Nick's modifications.
Michael's made Stata complain "not possible with numeric variable" and
would not work even after I used decode. Scott's code produced the same
effect as my original code, namely '1' at the start of each block of
observations of a company, and '0' for the rest of the block.
Thanks to Nick Cox for the additional advice concerning why the
incrementing of `count'+1 in my code would not work.
I now have code which allows me to identify a large number of companies by
a numeric tag and to be able to count the total number in one easy line.