rounding variable values

rounding variable values

by Mariya Samoylova -
Number of replies: 1

It turns out I've been missing a lot of data because some of my procedure keys are coded as, for example, 84.300000002 instead of 84.3.

Any advice on how to remove those extra decimal points?

I've tried round(var,0.01) and format var %12.2f, but neither of those seems to help-- the variable displays as I'd like to see it in the data view, but the actual value doesn't seem to change.

 

Thanks,
Mariya

In reply to Mariya Samoylova

Re: rounding variable values

by Michael Peters -

Mariya,

 

  Sorry it took me a little while to figure out how to do this.  Did you try to just generate a new variable using the round command?

such as

gen RoundVar = round(var1, .01) or just using the replace command

replace var1 = round(var1, 0.01)

Both of these options seemed to work for me.  

 

Now, this would only work if you are interested in rounding because you don't need this additional data.  You say that these are procedure codes, does the .00000003 tell you something?  Would you be better off converting these to string variables, and then recoding them as strings?

 

Let me know if this was any help?

Michael