Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

st: Problems rounding a variable using round()

From   L S <>
Subject   st: Problems rounding a variable using round()
Date   Sat, 24 Mar 2012 21:02:56 -0700


I am creating a variable that is the average of 5 0/1 variables.
However, instead of taking values on {0,.2,.4.6,.8,1}, it is taking
values like .40000001 and .60000002.  I tried to use the round()
command as below, but it's not working.  Any thoughts on how I can
make y take on the values {0,.2,.4.6,.8,1}?

Thank you.

set obs 1000

set seed 1234

forvalues i=1/5{
	gen x`i'=(uniform()>.5)

gen y = (1/5)*(x1+x2+x3+x4+x5)
* browse y
count if y==.6

replace y= round(y,.1)
count if y==.6
*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index