Statalist


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

Re: st: A precision problem


From   Maarten buis <[email protected]>
To   [email protected]
Subject   Re: st: A precision problem
Date   Sat, 26 Jan 2008 11:10:01 +0000 (GMT)

What about:
list houscode cinp_qty cinp_unpx cinp_totcost /// 
if reldif(cinp_qty*cinp_unpx, cinp_totcost) > 1e-6

Hope this helps,
Maarten

--- Ronnie Babigumira <[email protected]> wrote:

> 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/
> 


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________
Support the World Aids Awareness campaign this month with Yahoo! For Good http://uk.promotions.yahoo.com/forgood/
*
*   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