Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: A precision problem


From   Ronnie Babigumira <[email protected]>
To   [email protected]
Subject   st: A precision problem
Date   Sat, 26 Jan 2008 02:48:27 +0100

Dear List

My setup is Stata 10, winxp

I am "cleaning" some household data and I would like to identify cases where the product of quantity (cinp_qtry) and price (cinp_unpx) is not equal to the total cost (cinp_totcost) as entered in the data.

The data look something like this

houscode cinp_qty cinp_unpx cinp_totcost
34 3 .6 1.8
69 3 .6 1.8
70 3 .6 1.8
75 6 .6 3.6
97 3 .6 1.8
100 6 .6 3.6
103 3 1 90

My first take was

- list houscode cinp_qty cinp_unpx cinp_totcost if cinp_totcost ! = (cinp_qty * cinp_unpx) -

houscode cinp_qty cinp_u~x cinp_t~t
1 5 .6 3 <--------
34 3 .6 1.8
54 5 .6 3
69 3 .6 1.8
70 3 .6 1.8
75 6 .6 3.6
90 5 .6 3


When this caught the 3, I changed it to

list houscode cinp_qty cinp_unpx cinp_totcost if cinp_totcost ! = float(cinp_qty * cinp_unpx)

This improved things a bit however, the 1.8's were still caught.

houscode cinp_qty cinp_u~x cinp_t~t
34 3 .6 1.8
69 3 .6 1.8
70 3 .6 1.8
75 6 .6 3.6
97 3 .6 1.8
100 6 .6 3.6
103 3 1 90

I then decided to first generate a new variable which I called pc_totcost computed as

gen float pc_totcost = cinp_qty * cinp_unpx

Then I issued

list househd houscode cinp_qty cinp_unpx cinp_totcost pc_totcost if ///
cinp_totcost != float(pc_totcost)


houscode cinp_qty cinp_unpx cinp_totcost pc_totcost
34 3 .6 1.8 1.8
69 3 .6 1.8 1.8
70 3 .6 1.8 1.8
75 6 .6 3.6 3.6
97 3 .6 1.8 1.8
100 6 .6 3.6 3.6
103 3 1 90 3 <----- this is the only "bug"
70 3 .6 1.8 1.8
70 3 .6 1.8 1.8
97 3 .6 1.8 1.8
97 3 .6 1.8 1.8
100 6 .6 3.6 3.6

The 1.8's and 3.6's are "ok" to me. How can I get Stata to ignore them

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