Announcement

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

  • Calculating rate and confidence interval for a series of data.

    Hello all

    I am doing some time series stuff (using R to do interrupted time series analysis - long story) but i have a rate for each year as follows:

    year denominator Numerator rate
    2004 1117648 18869 16.88277
    2005 1135836 19209 16.91177
    2006 1149597 18915 16.45359
    2007 1153828 18610 16.12892
    2008 1164451 17741 15.23551
    2009 1156125 16008 13.84625
    2010 1127019 13940 12.36891
    2011 1111166 12502 11.25124
    2012 1070343 10439 9.752949
    2013 973473 8364 8.591918

    rate = numerator/denominator *1000

    I want to calculate the rate and 95% CI for each year. I know to use ci command:

    . cii proportions 1117648 18869

    -- Binomial Exact --
    Variable | Obs Proportion Std. Err. [95% Conf. Interval]
    -------------+---------------------------------------------------------------
    | 1,117,648 .0168828 .0001219 .0166447 .0171233

    but I want to know how to do it for each year 2004 to 2013 without having to enter this for every year. Is there a command that can summarise it? I have a few tables i need rate and CI for!

    Thanks

    Richard

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year long denominator int numerator float rate
    2004 1117648 18869 16.88277
    2005 1135836 19209 16.91177
    2006 1149597 18915 16.45359
    2007 1153828 18610 16.12892
    2008 1164451 17741 15.23551
    2009 1156125 16008 13.84625
    2010 1127019 13940 12.36891
    2011 1111166 12502 11.25124
    2012 1070343 10439 9.752949
    2013  973473  8364 8.591918
    end
    
    capture program drop one_year
    program define one_year
        local denominator = denominator[1]
        local numerator = numerator[1]
        cii proportion `denominator' `numerator'
        gen rate_recalculated = 1000*`r(proportion)'
        gen lower_bound = 1000*r(lb)
        gen upper_bound = 1000*r(ub)
        exit
    end
    
    isid year
    runby one_year, by(year)
    runby.ado is written by Robert Picard and me, and is available from SSC.

    In effect, this code loops over observations using -cii-. But the way -runby- works is more efficient than using -foreach- to directly loop over observations.

    I included in the output the variable rate_recalculated, which calculates the rate. You can see that it gives the same results you already have. Since you already have the rates themselves, you can omit this line of code if you like.



























    Comment


    • #3
      Wow that was quick! Thanks Clyde - I will have a go. Much appreciated.

      Comment

      Working...
      X