Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with spread out rows when using table

    Hi Statalisters,

    I seem to have found some unexpected (to me) behaviour from the -table- command. A reproducible example is pasted below which describes a sample size calculation carried out using -power-, and then summarizing the results of total sample size into a neat table.

    Code:
    power twoproportions (0.05(0.05).3), power(0.9) diff(.05 .1 .15 .2) alpha(0.05) effect(diff) saving("mypowertable.dta", replace)
    use mypowertable
    table p2 p1 [fw=N], contents(freq) format(%5.0f) concise missing
    This is the output that I receive:

    Code:
    ----------------------------------------------
              |                 p1                
           p2 |  .05    .1   .15    .2   .25    .3
    ----------+-----------------------------------
           .1 | 1164     .     .     .     .     .
          .15 |  376  1836     .     .     .     .
           .2 |  202   532  2424     .     .     .
          .25 |  130   266   670  2928     .     .
           .3 |    .     .   322     .  3348     .
           .3 |    .   164     .   784     .     .
          .35 |    .     .   194   370   880  3684
           .4 |    .     .     .   218   406   954
          .45 |    .     .     .     .     .   434
          .45 |    .     .     .     .   236     .
           .5 |    .     .     .     .     .   248
    ----------------------------------------------
    And this is the output that I expect (note that there are no longer two rows for p2 = 0.3 or 0.45:

    Code:
    ----------------------------------------------
              |                 p1                
           p2 |  .05    .1   .15    .2   .25    .3
    ----------+-----------------------------------
           .1 | 1164     .     .     .     .     .
          .15 |  376  1836     .     .     .     .
           .2 |  202   532  2424     .     .     .
          .25 |  130   266   670  2928     .     .
           .3 |    .    164   322   784   3348     .
          .35 |    .     .   194   370   880  3684
           .4 |    .     .     .   218   406   954
          .45 |    .     .     .     .     236  434
           .5 |    .     .     .     .     .   248
    ----------------------------------------------

  • #2
    This looks to me like a precision problem (call it a bug) in power. I'd report it to StataCorp. Here is the problem shown and a work-around that is horrible, but heck, it works for your data.

    Code:
    clear
    power twoproportions (0.05(0.05).3), power(0.9) diff(.05 .1 .15 .2) alpha(0.05) effect(diff) saving("mypowertable.dta", replace)
    
    use mypowertable
    
    clonevar P2 = p2
    
    format P2 %21x
    
    sort p2
    
    gen workaround = round(p2, 0.05)
    
    list p2 P2 workaround, sepby(p2)
    
         +----------------------------------------+
         |  p2                      P2   workar~d |
         |----------------------------------------|
      1. |  .1   +1.999999999999aX-004         .1 |
         |----------------------------------------|
      2. | .15   +1.3333333333334X-003        .15 |
      3. | .15   +1.3333333333334X-003        .15 |
         |----------------------------------------|
      4. |  .2   +1.999999999999aX-003         .2 |
      5. |  .2   +1.999999999999aX-003         .2 |
      6. |  .2   +1.999999999999aX-003         .2 |
         |----------------------------------------|
      7. | .25   +1.0000000000000X-002        .25 |
      8. | .25   +1.0000000000000X-002        .25 |
      9. | .25   +1.0000000000000X-002        .25 |
     10. | .25   +1.0000000000000X-002        .25 |
         |----------------------------------------|
     11. |  .3   +1.3333333333333X-002         .3 |
     12. |  .3   +1.3333333333333X-002         .3 |
         |----------------------------------------|
     13. |  .3   +1.3333333333334X-002         .3 |
     14. |  .3   +1.3333333333334X-002         .3 |
         |----------------------------------------|
     15. | .35   +1.6666666666666X-002        .35 |
     16. | .35   +1.6666666666666X-002        .35 |
     17. | .35   +1.6666666666666X-002        .35 |
     18. | .35   +1.6666666666666X-002        .35 |
         |----------------------------------------|
     19. |  .4   +1.999999999999aX-002         .4 |
     20. |  .4   +1.999999999999aX-002         .4 |
     21. |  .4   +1.999999999999aX-002         .4 |
         |----------------------------------------|
     22. | .45   +1.cccccccccccccX-002        .45 |
         |----------------------------------------|
     23. | .45   +1.ccccccccccccdX-002        .45 |
         |----------------------------------------|
     24. |  .5   +1.0000000000000X-001         .5 |
         +----------------------------------------+
    PS You need to go

    Code:
    tab workaround
    to see that it does work.
    Last edited by Nick Cox; 14 Dec 2018, 07:07.

    Comment


    • #3
      Many thanks, Nick. I hesitated to call it a bug, but you're right, the machine precision somehow is slightly off for the same input values. Your workaround will work well enough for my purposes, and I'll report it to StataCorp.

      Comment


      • #4
        Wise programmers always hesitate before calling "bug". Sometimes the answer is PICNIC: problem in chair, not in computer.

        Comment


        • #5
          For future reference, I submitted this question to Stata Technical Support. Their response is that the issue is down to machine precision of the decimals, as Nick points out. Nick's solution is a workaround.

          I have suggested that the need of this workaround is a bit clumsy, and from a user's perspective, one does not require such high precision and perhaps the -power- command could have some option of rounding the inputs prior to performing the calculations.

          Comment

          Working...
          X