Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Problem with adding 3 numbers


From   "Kanter, Rebecca" <rkanter@jhsph.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Problem with adding 3 numbers
Date   Fri, 16 Oct 2009 22:27:45 -0400

Hi,

I am trying to add three numbers (1-2 digit code for state plus 3 digit code for municipality + 4 digit code for locality). together unique for each state in a country. I have tried this various ways and each time, after the 1st state, STATA starts to round (I think) some of the numbers. I have tried this numerous ways. No state, municipality, or locality are missing. State is byte. Municipality and locality are strings (that I convert to numeric see below).

gen munloc=mun+loc
destring munloc, generate(test)
generate ent2=ent*10000000
generate claveloc=ent2+test

or whereby:
mun2=real(mun)
loc2=real(loc)
gen claveloc =((state*10000000)+ (mun2*10000))+loc2

****Anyway I try this, I get problems like this:

state      mun   loc             munloc  test        state2             claveloc
      2         001     0001    0010001 10001   20000000        20010000 (should be 20010001)
   ent  mun      loc        munloc              test               state2                claveloc
    2             001 0139      0010139 10139   20000000        20010140 (should be 20010139)

*Should be like this:

state             mun loc                 munloc        test                  state2    claveloc
1                     001       0001    0010001 10001   10000000        10010001



Can someone please help me get this to work correctly.

Thank you so much,
Rebecca


___________________________________________
Rebecca M. Kanter
PhD Candidate
Johns Hopkins Bloomberg School of Public Health
Department of International Health
Center for Human Nutrition

*
*   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/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index