Announcement

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

  • 95%CI for percentages

    I have come across several articles reporting 95%CIs for percentages/prevalences using Stata. I emailed some authors, and only one of them briefly said that it can achieved using margins command in Stata. I was unable to use do so for means and proportions, but not for counts or percentages. I also searched for similar topic in some forums, but to no avail. May be someone from Statalist is familiar with it or can suggest a method, using the Sysuse Auto dataset. Here is a reference article:
    Click image for larger version

Name:	Capture d’écran, le 2018-10-28 à 17.57.38.png
Views:	1
Size:	267.6 KB
ID:	1467915



    My target is to report CIs for the each of the values in the following example:


    Code:
    . sysuse auto2.dta
    (1978 Automobile Data)
    
    . ta rep78 foreign, col nofreq
    
        Repair |
        Record |       Car type
          1978 |  Domestic    Foreign |     Total
    -----------+----------------------+----------
          Poor |      4.17       0.00 |      2.90 
          Fair |     16.67       0.00 |     11.59 
       Average |     56.25      14.29 |     43.48 
          Good |     18.75      42.86 |     26.09 
     Excellent |      4.17      42.86 |     15.94 
    -----------+----------------------+----------
         Total |    100.00     100.00 |    100.00
    Last edited by Sonnen Blume; 28 Oct 2018, 16:25.

  • #2
    Percentages are just proportions scaled up by a factor of 100. So calculate the proportions, and then multiply the estimate as well as the confidence limits by 100.

    You give no examples of confidence intervals around counts, and that would be rather unusual in any case. But if you are in a position where you need to do that, you would have to say more about the variable you are counting and what could be assumed about its distribution. One might model it as the outcome of a Poisson or negative binomial regression and then use -margins-, assuming that one of those distributions is a reasonable model of the real data generating process.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Percentages are just proportions scaled up by a factor of 100. So calculate the proportions, and then multiply the estimate as well as the confidence limits by 100.

      You give no examples of confidence intervals around counts, and that would be rather unusual in any case. But if you are in a position where you need to do that, you would have to say more about the variable you are counting and what could be assumed about its distribution. One might model it as the outcome of a Poisson or negative binomial regression and then use -margins-, assuming that one of those distributions is a reasonable model of the real data generating process.
      Thanks a lot Clyde. I updated the example in my original post. I think I am already a step ahead with the use of proportions as it does compute the CIs. I can do the multiplying-by-100 part in excel, but it'd be good to know if that is doable in Stata.

      Code:
      . proportion rep78 foreign, cformat(%9.3f)
      
      Proportion estimation             Number of obs   =         69
      
      --------------------------------------------------------------
                   |                                   Logit
                   | Proportion   Std. Err.     [95% Conf. Interval]
      -------------+------------------------------------------------
      rep78        |
              Poor |      0.029      0.020         0.007       0.112
              Fair |      0.116      0.039         0.058       0.218
           Average |      0.435      0.060         0.321       0.556
              Good |      0.261      0.053         0.169       0.380
         Excellent |      0.159      0.044         0.089       0.269
      -------------+------------------------------------------------
      foreign      |
          Domestic |      0.696      0.056         0.575       0.795
           Foreign |      0.304      0.056         0.205       0.425
      --------------------------------------------------------------

      Comment


      • #4
        Code:
        sysuse auto, clear
        
        proportion foreign rep78
        
        // RETRIEVE STORED RESULTS
        matrix T = r(table)
        
        // EXTRACT ROWS FOR PROPORTION AND CONFIDENCE LIMITS
        matrix T = T[1, 1...] \ T[5..6, 1...]
        
        // SCALE UP BY 100
        matrix T = 100*T
        
        // SHOW RESULTS
        matrix list T, format(%4.3f)

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          Code:
          sysuse auto, clear
          
          proportion foreign rep78
          
          // RETRIEVE STORED RESULTS
          matrix T = r(table)
          
          // EXTRACT ROWS FOR PROPORTION AND CONFIDENCE LIMITS
          matrix T = T[1, 1...] \ T[5..6, 1...]
          
          // SCALE UP BY 100
          matrix T = 100*T
          
          // SHOW RESULTS
          matrix list T, format(%4.3f)
          Thanks Clyde, finally an answer to a long-sought puzzle. Also, I never used matrix method before, so just want to know if the following is applicable for tables of any dimension.
          Code:
          matrix T = T[1, 1...] \ T[5..6, 1...]

          Comment


          • #6
            Yes. The subscripting notation [whatever, 1...] means to use the row(s) specified by whatever, and however many columns there happen to be. So the code does not need to be modified if you change the dimensions of the problem.

            Comment


            • #7
              Originally posted by Clyde Schechter View Post
              Yes. The subscripting notation [whatever, 1...] means to use the row(s) specified by whatever, and however many columns there happen to be. So the code does not need to be modified if you change the dimensions of the problem.
              Thanks indeed for your time!

              Comment

              Working...
              X