Announcement

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

  • Bug report: The number 0.1625 displays 0.162 NOT 0.163 as expected when using format(%9.3f)

    I found an unexpected result when analyzing ABES data. I am using Stata/SE 15.1, but this issue occurs in Stata 17 too.

    It seems that I can not upload the dataset with this post. The dataset can be downloaded freely from https://www.cdc.gov/healthyyouth/data/abes/data.htm.

    Declare survey design for dataset
    HTML Code:
    svyset psu [pweight=weight], strata(stratum)
    The upper limit of the prevelance of QN35 among male(Q2=2) is 0.1625.

    HTML Code:
    . svy ,subpop(if Q2==2): prop  QN35, cformat(%9.4f)
    (running proportion on estimation sample)
    
    --------------------------------------------------------------
                 |             Linearized            Logit
                 | Proportion   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            QN35 |
              1  |     0.1392     0.0109        0.1188      0.1625
              2  |     0.8608     0.0109        0.8375      0.8812
    --------------------------------------------------------------

    When I changed with format(%9.3f) option,the upper limit shows 0.162, NOT 0.163 as expected.

    HTML Code:
    . svy ,subpop(if Q2==2): prop  QN35, cformat(%9.3f)
    (running proportion on estimation sample)
    
    --------------------------------------------------------------
                 |             Linearized            Logit
                 | Proportion   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            QN35 |
              1  |      0.139      0.011         0.119       0.162
              2  |      0.861      0.011         0.838       0.881
    --------------------------------------------------------------
    I wonder someone can double check this issue.


    Solved ! Thank daniel klein for his kind help!


    The default results without format option:
    Code:
    . svy ,subpop(if Q2==2): prop  QN35
    (running proportion on estimation sample)
    
    Survey: Proportion estimation
    
    Number of strata = 16             Number of obs   =      7,448
    Number of PSUs   = 70             Population size = 7,452.8028
                                      Subpop. no. obs =      3,421
                                      Subpop. size    =  3,553.611
                                      Design df       =         54
    
    --------------------------------------------------------------
                 |             Linearized            Logit
                 | Proportion   std. err.     [95% conf. interval]
    -------------+------------------------------------------------
            QN35 |
              1  |   .1392273   .0108637      .1188397    .1624676
              2  |   .8607727   .0108637      .8375324    .8811603
    --------------------------------------------------------------
    Last edited by Qiguo Lian; 31 Mar 2022, 22:49.

  • #2
    No need to panic. This should give you a hint

    Code:
    . display %9.4f 0.16246
       0.1625
    
    . display %9.3f 0.16246
        0.162
    Last edited by daniel klein; 31 Mar 2022, 23:14.

    Comment


    • #3
      Originally posted by daniel klein View Post
      No nees to panic. This should give you a hint

      Code:
      . display %9.4f 0.16246
      0.1625
      
      . display %9.3f 0.16246
      0.162
      Thank you! You are right. The authors may make a small mistake, not Stata. The exact number of the upper limit is 0.1624676 in Stata by default.

      Use of Tobacco Products, Alcohol, and Other Substances Among High School Students During the COVID-19 Pandemic - Adolescent Behaviors and Experiences Survey, United States, January-June 2021
      https://pubmed.ncbi.nlm.nih.gov/35358166/ PMID: 35358166 DOI: 10.15585/mmwr.su7103a2

      Attached Files
      Last edited by Qiguo Lian; 31 Mar 2022, 22:53.

      Comment


      • #4
        let's clarify something more basic - the rules used in making computer chips related to rounding are that when a value is exactly halfway between two values the rounding is towards the EVEN number; this has become confused in many people's minds because spreadsheets over-ride this rule and always round up; I prefer the math chip rule and do not understand why spreadsheets over-ride but they all do - that does not make them right and if your actual value had been 0.1625 and you wanted it rounded to 3 decimals, then Stata would have been right to round down (in my opinion) and certainly would have been consistent with the chip standard

        Comment


        • #5
          Originally posted by Rich Goldstein View Post
          let's clarify something more basic - the rules used in making computer chips related to rounding are that when a value is exactly halfway between two values the rounding is towards the EVEN number; this has become confused in many people's minds because spreadsheets over-ride this rule and always round up; I prefer the math chip rule and do not understand why spreadsheets over-ride but they all do - that does not make them right and if your actual value had been 0.1625 and you wanted it rounded to 3 decimals, then Stata would have been right to round down (in my opinion) and certainly would have been consistent with the chip standard
          Thank you, Rich Goldstein , for the very good clarification.

          Comment

          Working...
          X