Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: St: Dataset generation


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: St: Dataset generation
Date   Fri, 14 Jun 2002 16:40:02 +0100

[email protected]
> 
> Please could somebody explain to me how this could occur:
> 
> I want to generate a dataset with 6561 observations, with two 
> variables, let us say x and y, which take values between -2 and 2, 
> with step value 0.05. The aim of this is to test a function which I 
> have programmed which is causing some trouble. Therefore I need 81 
> occurences of x==-2, and 81 of x==-1.95 and so on for both x and y. 
> If I construct x as follows (crude so feel free to suggest 
> alternatives)
> 
> egen ind=fill (1 2)
> replace ind=ind-1
> gen x=int(ind/81)
> replace x=(x/20)-2
> 
> this should work, and does when the data is displayed to 2 decimal 
> places. However closer examination of the data with the data browser 
> shows some anomalies, where rather that x==-.95 it actually reads 
> x==.-9499999. This occurs for many values in between -1 and 1 and 
> attempts to rectify it using
> 
> gen x2=round(x,0.05)
> 
> have not bourne fruit. What am I missing?
> 

You are missing the fact that Stata is holding the numbers in binary. 
See (e.g.) 

http://www.stata.com/support/faqs/data/float.html

http://www.stata.com/support/faqs/data/mod.html

and 

[U] 16.10 Precision and problems therein. 

Nick 
[email protected] 
*
*   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/



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