| |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Re: summing up digits and comparing to a check digit
ups...typo! The second example was supposed to be 1050457 sorry.
Thanks a lot
Lia
Michael Blasnik wrote:
I'm not sure I understand the problem -- one of your examples is an 8
digit number but you say you have 7 digit numbers. Anyway, here is
some "highly advanced programming" (?) :
gen x=string(myvar)
replace x="0"+x if length(x)==6
gen
check=mod(real(substr(x,2,1))+real(substr(x,3,1))+real(substr(x,4,1))+real(substr(x,5,1))+real(substr(x,6,1))+real(substr(x,7,1)),10)
make sure to remove any line break that the email puts in the last line.
Michael Blasnik
----- Original Message ----- From: "Lia Orfei" <[email protected]>
To: <[email protected]>
Sent: Wednesday, March 15, 2006 9:54 AM
Subject: st: summing up digits and comparing to a check digit
Dear all,
Here is a highly advanced programming challenge for you (!)
I have a variable that contains 7-digit numbers; the first digit is
the remainder of the sum of the last six digits divided by 10 (check
digit)
example: 1030332 => 0+3+0+3+3+2=11/10=1+1 => check digit=1
12050457 => 0+5+0+4+5+7=21/10=2+1 => check digit=1
and so on.
Now I want to assess whther the check digit is correct for each entry.
How do I calculate the partial sum of the contents of this variable?
Extra challenge: some of the numbers sum up to 10, 20 etc so the
check digit is actually 0 and it does not appear in the data for some
reason (example 50456 is correct becasue 5+0+4+5+6=20 so the
remainder is 0).
Any ideas?? I was thinking about using the string functions.
Thanks a lot
Lia
*
* 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/
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
*
* 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/