You are not logged in. You can browse but not post. Login or Register by clicking 'Login or Register' at the top-right of this page. For more information on Statalist, see the FAQ.
Variable changes_Telling stata to consider only 2 digits after decimal
var3
0.001
0.0005
0.00006
0.01
My question is very elementary or trivial, but as I am new to Stata ,I would like to get your help. My question is that ,how can I tell stata to take only first do digits after the point. In the above case,for the first observation in var3,I require only 0.00,which is 0 itself. I dont want to try the command format as it only a display convenience.Moreover,replace var3=round(var3, 0.05) wont be helpful as it gives "(0 real changes made)" as reply. I just want to tell stata that take 2 or 3 digits after decimal.
Thanks in advance
What you are asking for is, strictly speaking, impossible, because decimal numbers like 0.01 have no exact finite binary representation (just as 1/3 has no exact finite decimal representation). So when you ask Stata to deal with 0.01, it actually deals with the closest binary number to 0.01 it can find.
That said, I think the closest you can come to this would be:
Code:
gen var4 = floor(100*var3)/100
Note that I do not replace var3, since the transformation here is irreversible and information would be lost. Instead I create a new variable. If you are sure the loss of information will not come to bite you later on, you could -replace var3- instead.
Comment