Announcement

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

  • confidence intervals on proportion

    Hi there
    Apologies in advance if this has already been answered elsewhere.
    I have a dataset of many numerators and denominators and I want to calculate the proportions and the 95% confidence intervals around those proportions.
    For example:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(numerator denominator)
    21 142
    56 341
    34 234
    65 432
    34 345
    7 543
    67 765
    78 234
    5 423
    43 234
    23 254
    4 653
    21 543
    45 654
    65 162
    end
    gen proportion = numerator/denominator
    [/CODE]

    I presume Stata must have a function command for the calculation of the 95% confidence intervals but I can't find it anywhere. Any advice greatly appreciated.

    To be clear, I need to create the confidence intervals in the dataset itself (as new variables) rather than in the output window, as I intend to visualise them in a table/graph.

    With thanks.
    Last edited by tim bradshaw; 17 Jan 2023, 14:32.

  • #2
    Code:
    gen proportion = .
    gen lb = .
    gen ub = .
    
    forvalues i = 1/`=_N' {
        cii proportions denominator[`i'] numerator[`i']
        foreach v of varlist proportion lb ub {
            replace `v' = r(`v') in `i'
        }
    }
    If you are not familiar with -cii- see -help cii- for options and more details.

    Comment


    • #3
      That might be followed with some effort to visualize the result, assuming that this example is about an increasing order of proportions, like:
      Code:
      sort proportion
      gen snr=_n
      tw (rarea ub lb snr , col(%70) lw(0)) (line proportion snr) , ///
          plotr(m(none)) ylab(,angle(none)) xlab(1(1)15)  xti("our topics")
      which results in:
      Click image for larger version

Name:	CaseProportionsCI.png
Views:	1
Size:	33.5 KB
ID:	1697677
      http://publicationslist.org/eric.melse

      Comment


      • #4
        Hi Tim,
        You could use metan for this; just suppress the pooling across observations. For example (based on your dataex):
        Code:
        metan numerator denominator, proportion nooverall citype(exact) dp(3)
        ...where citype(exact) requests exact binomial confidence limits, but you could replace with any option given in help ci##prop_options

        The confidence limits are then made available to you within new variables _LCI and _UCI.

        Best wishes,
        David.
        Last edited by David Fisher; 18 Jan 2023, 07:50.

        Comment


        • #5
          Very helpful replies, everyone. Thanks so much!

          Comment

          Working...
          X