Announcement

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

  • Using cii proportions with loop

    Hello,

    I am trying to compute confidence intervals for proportions (number of cases / total) on each observations of a simple database using the ci proportions / cii proportions command.
    Here is my code and the database:

    Code:
    input str7 continent cases total
    Africa 544 863
    America 43 172
    Asia 372 734
    Oceania 19 25
    
    local contlist Africa America Asia Oceania
        
        foreach continent of local contlist {
         ci proportions total cases if continent == "`continent'"    
        
    }
    This gives an output with empty values. I have also tried with cii proportions, which was also unsuccesful.

    I can get the results one by one, by typing the following command - for Africa for instance - but I would like to have it automatized:

    Code:
    cii proportions 863 544

    Does anyone have a idea on how to solve this?

    I am using Stata 14.

    Many thanks in anticipation

  • #2
    https://www.stata.com/support/faqs/d...iate-commands/ appears to be what you seek.

    Comment


    • #3
      You could also use the meta-analysis package metan for this (via SSC; latest verson v4.06 12oct2022). It leaves behind effect-sizes, standard errors and confidence intervals, and there are options to control how the confidence intervals are calculated (that is, the options of ci proportions). You don't have to perform meta-analysis pooling or draw a forest plot! For instance:

      Code:
      . metan cases total, proportion exact study(continent) nooverall nograph
      . list _ES _LCI _UCI

      Comment


      • #4
        Dear Nick,

        Thanks for the response.
        I understand that with this do-file I store the output of the cii command in a dataset - which is not exactly what I would like to do. Moreover, with this approach, I would need in any case to type the figures one by one i.e.

        Code:
         
         run mycii 863 544
        (and so on for each continent)

        Instead, what I am interested in is simply to display the output of cii from an existing database. I would like to run the cii command for for each observation of my dataset (no need to store the CIs in a new dataset, it's OK for me to have them printed in the result window).

        Let me know if this is not clear,

        Thanks

        Comment


        • #5
          Dear David,
          Thank you for sharing this package.
          The command you proposed did exactly what I needed, thanks,

          Best

          Comment


          • #6
            The idea mentioned in #2 can be adapted to the case of data already in memory.

            Code:
            clear 
            input str7 continent cases total
            Africa 544 863
            America 43 172
            Asia 372 734
            Oceania 19 25
            end 
            
            quietly foreach v in N proportion se lb ub {
                gen `v' = .
            }
            
            quietly forval i = 1/`=_N' { 
                cii proportions `=total[`i']' `=cases[`i']' 
                foreach v in N proportion se lb ub {
                    replace `v' = r(`v') in `i'
                }
            }
            
            
                +----------------------------------------------------------------------------+
                 | contin~t   cases   total     N   propor~n         se         lb         ub |
                 |----------------------------------------------------------------------------|
              1. |   Africa     544     863   863   .6303592   .0164316   .5971731   .6626518 |
              2. |  America      43     172   172        .25   .0330169   .1872156   .3216102 |
              3. |     Asia     372     734   734    .506812   .0184536   .4699971   .5435719 |
              4. |  Oceania      19      25    25        .76   .0854166    .548712   .9064355 |
                 +----------------------------------------------------------------------------+

            Comment


            • #7
              Thank you Nick! Very useful to know this,
              Best

              Comment


              • #8
                See also the user-written command -xcipoibin- (available on github, see below), if you're interested in calculating exact CIs.

                Code:
                https://github.com/anddis/xcipoibin
                https://anddis.github.io/xcipoibin/xcipoibin_ex.html
                Disclaimer: I'm the author of xcipoibin.

                Comment


                • #9
                  Thanks

                  Comment

                  Working...
                  X