The question clearly implied leading zeros could exist. If the variable
was numeric and displayed with a leading zero format, the best way to
work would I think be in terms of something like
substr(string(mynum, "%04.0f"), 1, 1)
etc.
Note that there is no need at all to create an extra variable, convert
the variable, etc. It can all be done on the fly.
Nick
[email protected]
Martin Weiss
If ever your variable was indeed numeric, the case for turning them into
strings may be strong, but I think you could also stick to the numeric
ones,
though I am willing to bow to superior wisdom here...
*************
clear*
inp myvar
0011
8944
4500
3512
0989
end
//formatting not essential, but still...
format myvar %04.0f
list, noobs
//two leading zeroes
drop if myvar-mod(myvar,100)==0
list, noobs
//one leading zero
drop if myvar-mod(myvar,1000)==0
list, noobs
*************
Ermias Ogbai Weldemicael
I am trying to drop observation from one variable. The variable contains
four digit values (e.g. 0011 8944 4500 3512..). Is it possible to drop
an
observation by if condition of the first digit..or first two digits.
Like
'drop if value starts with 00'
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/