Note that the problem here is one of consecutive values.
In addition to other answers, consider this:
levelsof myvar, local(present)
numlist "1/256"
local shouldbe "`r(numlist)'"
di "`: list local shouldbe - present'"
The -levelsof- command identifies what is present
and the -numlist- command allows a list of what
should be there to be produced. Then you can see
the set difference.
Nothing here tests for sequence, but that is covered by
other answers, and indeed does not seem central to
your problem.
Nick
[email protected]
Manasi Vydyanath
I was wondering whether there was any command for checking
for gaps in a given variable. In other words - supposing I have
"myvar" which is supposed to run from 1 to 256 consecutively. But
there may be gaps in this variable, and it might be missing, say, 69
and 78. Is there a command I can use to detect this sort of thing?
In case anyone is interested, a fuller context of the problem is that
I am creating synthetic cohorts from a series of random cross
sections, and one of the conditions is that there must be no empty
cohort. I wrote a do-file that takes my time-invariant parameters
(age, race and gender) and partitions the set of individuals across
each year. One of the conditions I would like to impose is that there
should be no empty partition, and I was wondering whether there might
be an easy way to check this condtion.)
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/