Announcement

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

  • Confidence interval for percent change in rate

    Building off of the example shown here: https://www.statalist.org/forums/new-content/51

    I'm attempting to do something similar in reporting percent change with confidence intervals compared to some baseline period.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float ac_drug_oral double volume_per10000 byte period float(monthly ln_volume_per10000)
    2 1260.6831300832241 1 732 7.139409
    2 1121.1703693867348 1 733 7.022129
    2 1297.5034939189118 1 734 7.168197
    2  1244.835560987853 1 735 7.126759
    2 1209.8619960138883 1 736 7.098261
    2 1276.7094465389555 1 737 7.152041
    2 1257.8345016583257 1 738 7.137147
    2 1250.1367395163436 1 739 7.131008
    2 1194.3472777250283 1 740 7.085355
    2  1217.227766272708 1 741 7.104331
    2 1188.4083496816286 1 742  7.08037
    2 1220.8647452373323 1 743 7.107315
    2 1195.1871343100497 2 744 7.086058
    2  1093.872239363099 2 745 6.997479
    2 1217.4365842951077 2 746 7.104503
    2 1155.7952853628883 2 747 7.052544
    2 1183.4685905249155 2 748 7.076205
    2 1180.5756265808982 2 749 7.073758
    2  1148.722932051039 3 750 7.046406
    2  1206.729594179629 3 751 7.095669
    2 1119.5237418002291 3 752 7.020658
    2 1132.7168821291311 3 753 7.032374
    2 1107.2286632215928 3 754 7.009615
    2 1137.4805390050224 3 755 7.036571
    end
    format %tm monthly


    reg ln_volume_per10000 i.period contrast r.period nlcom 100*(1-exp(_b[2.period])) nlcom 100*(1-exp(_b[3.period]))
    The issue that I encounter is trying to calculate a percent change compared to the baseline period (period of interest/baseline-1)*100). Is there a way to generate a percent change in the right direction? For example, one is positive and one is negative while the formula has both as positive.

    Thanks,

  • #2
    If you are talking about getting a percentage change in ln_volume, rather than figure out how to do it, I will ask you why you want to do it? Percentage changes in log-transformed outcomes are not really meaningful.

    If you are talking about getting a percentage change in volume itself, on the assumption that your "baseline" period is period == 1, then all you need is to look at the coefficients of the other two baseline periods in this regression of ln_volume, and multiply those, and their confidence limits, by 100. That will give you a reasonable approximation to the percentage difference in the expected value of volume between those periods and the baseline period, as long as those coefficients are < 0.1 in magnitude.

    If your coefficients of those periods are more than 0.1 in magnitude, then the approximation is not as good, and instead you should calculate 100*(exp(coefficient)-1), and similarly for the confidence limits. This formula is not an approximation--it gives the exact value. You could also use it in the smaller coefficient scenario if you need more than one decimal place worth of accuracy in the percentage.
    Last edited by Clyde Schechter; 24 Apr 2023, 14:24.

    Comment


    • #3
      I am trying to determine percent change between periods for volume per 10,000. Instead of doing this via regression to obtain expected value of volume between periods, is there a way in Stata to obtain percent changes in the mean values between periods? In this example, and others, I still face the issue where one is positive and one is negative though the formula estimates both as negative values.

      mean mean_volume_per10000, over(ac_drug_oral period)
      Is there something either before or after this that I can use in order to estimate to obtain percent changes with confidence intervals?

      Comment


      • #4
        In this example, and others, I still face the issue where one is positive and one is negative though the formula estimates both as negative values.
        I don't know what you're talking about here.
        Code:
        . * Example generated by -dataex-. For more info, type help dataex
        . clear
        
        . input float ac_drug_oral double volume_per10000 byte period float(monthly ln_volume_per10000)
        
             ac_drug~l  volu~10000    period    monthly  ln_~10000
          1. 2 1260.6831300832241 1 732 7.139409
          2. 2 1121.1703693867348 1 733 7.022129
          3. 2 1297.5034939189118 1 734 7.168197
          4. 2  1244.835560987853 1 735 7.126759
          5. 2 1209.8619960138883 1 736 7.098261
          6. 2 1276.7094465389555 1 737 7.152041
          7. 2 1257.8345016583257 1 738 7.137147
          8. 2 1250.1367395163436 1 739 7.131008
          9. 2 1194.3472777250283 1 740 7.085355
         10. 2  1217.227766272708 1 741 7.104331
         11. 2 1188.4083496816286 1 742  7.08037
         12. 2 1220.8647452373323 1 743 7.107315
         13. 2 1195.1871343100497 2 744 7.086058
         14. 2  1093.872239363099 2 745 6.997479
         15. 2 1217.4365842951077 2 746 7.104503
         16. 2 1155.7952853628883 2 747 7.052544
         17. 2 1183.4685905249155 2 748 7.076205
         18. 2 1180.5756265808982 2 749 7.073758
         19. 2  1148.722932051039 3 750 7.046406
         20. 2  1206.729594179629 3 751 7.095669
         21. 2 1119.5237418002291 3 752 7.020658
         22. 2 1132.7168821291311 3 753 7.032374
         23. 2 1107.2286632215928 3 754 7.009615
         24. 2 1137.4805390050224 3 755 7.036571
         25. end
        
        . format %tm monthly
        
        .
        . mean volume_per10000, over(ac_drug_oral period)
        
        Mean estimation                                                      Number of obs = 24
        
        ---------------------------------------------------------------------------------------
                                              |       Mean   Std. err.     [95% conf. interval]
        --------------------------------------+------------------------------------------------
        c.volume_per10000@ac_drug_oral#period |
                                         2 1  |   1228.299   13.63556      1200.091    1256.506
                                         2 2  |   1171.056   17.48179      1134.892     1207.22
                                         2 3  |   1142.067   14.20789      1112.676    1171.458
        ---------------------------------------------------------------------------------------
        
        .
        end of do-file
        So all three means are positive. And both differences from baseline are negative. Moreover, the means of volume_per100000 must be positive, as much all the values of that variable, or you would not have been able to log-transform them: only positive numbers have logarithms.

        Also, I don't know what "formula" you are talking about.

        Anyway, after that those means, you can follow with
        Code:
        . nlcom 100*(_b[[email protected]_drug_oral#2.period] - _b[[email protected]_drug_oral#1.period]) ///
        >     / _b[[email protected]_drug_oral#1.period]
        
               _nl_1: 100*(_b[[email protected]_drug_oral#2.period] - _b[[email protected]_drug_oral#1.period]) / _b[[email protected]_
        > drug_oral#1.period]
        
        ------------------------------------------------------------------------------
                Mean | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               _nl_1 |  -4.660325   1.773646    -2.63   0.009    -8.136607   -1.184042
        ------------------------------------------------------------------------------
        
        . nlcom 100*(_b[[email protected]_drug_oral#3.period] - _b[[email protected]_drug_oral#1.period]) ///
        >     / _b[[email protected]_drug_oral#1.period]
        
               _nl_1: 100*(_b[[email protected]_drug_oral#3.period] - _b[[email protected]_drug_oral#1.period]) / _b[[email protected]_
        > drug_oral#1.period]
        
        ------------------------------------------------------------------------------
                Mean | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
               _nl_1 |  -7.020407   1.550286    -4.53   0.000    -10.05891   -3.981903
        ------------------------------------------------------------------------------
        to get your percentage changes.

        Added: By the way, this gets you the same results as the regression based approach.

        Comment


        • #5
          Got it; thank you.

          I was looking at a different example than the one I shared which is why I thought one percent change was negative and one was positive. Apologies for the confusion. This is exactly what I was looking to accomplish.

          Comment

          Working...
          X