Announcement

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

  • Calculating mean value to percentage of recommendation

    Hello

    I am quite new to stata. I have searched answer, but I haven´t found right one yet.

    I have data that has values of various micronutrient intake and i would like to compare mean value with recommendation value so that i can show results "% of recommendation" in order to compare these percentages between two age groups. Also i have two different groups with different recommendation values (pregnant and non pregnant).

    Example:

    Mean value of intake of phosporos in pregnant women total is 900 mg. 18-30 years age group has mean intake 800 mg , 31-35 years age group has mean intake 1000mg. Recommendation value for pregnant woman is 700mg/day.
    I need to show data like that: 18-30 years old have intake 114% of recommendation, 31-35 years old have intake 143% of recommendation and all pregnant women 129% of recommendation.
    Next step would be to find statistical differences between these age groups percentages of recommendation.
    I would like to repeat this with non pregnant woman also, who has different recommendation value - 600mg/day.


    Which would be the easiest way to do it in stata?

    Kind regards,
    Miinni


  • #2
    Miini:
    welcome to this forum.
    The easiest way is to share an example/excerpt of them via -dataex-. Thanks.
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Sorry, i hope this helps.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(P_mg agegr pregn)
         880 1 1
         770 1 1
        2000 1 1
       876.5 1 1
      1060.5 1 1
        1300 1 1
        1004 1 1
        1087 1 1
        1200 1 1
         900 1 1
      1234.8 1 1
         789 1 1
         901 1 1
         675 1 1
         890 1 1
       898.5 1 1
         678 1 1
        1289 1 1
         700 1 1
        1188 2 1
         890 1 1
         731 1 1
        1067 1 1
         817 1 1
         812 1 1
         400 1 1
         605 1 1
         801 1 1
        1212 2 1
         909 1 1
         800 1 1
        1111 1 1
        1222 1 1
      1010.5 1 1
         897 1 1
        1211 1 1
         987 1 1
         456 1 1
         767 1 1
         910 1 1
        1234 1 1
         999 1 1
        1390 1 1
        1008 1 1
        1112 1 1
         999 1 1
         981 1 1
        1044 2 1
       877.5 1 1
        1200 1 1
        1111 1 1
         909 1 1
         677 1 1
        1200 1 2
        1111 1 2
      1235.5 1 1
         809 1 2
        1000 2 1
         989 1 1
        1398 1 1
         988 1 1
        1111 1 1
      1267.5 1 2
        1123 1 1
        1125 1 1
       990.5 1 2
        1009 1 1
        1111 1 1
         900 2 1
         786 1 1
         943 1 1
         600 1 1
         709 1 1
         899 1 1
         877 1 1
        1390 1 1
         788 1 1
         714 1 1
       781.5 1 1
         789 1 1
        1117 2 1
         944 1 1
         734 1 1
         871 1 1
         500 1 1
         608 1 2
        1409 1 1
         781 1 1
        1601 1 1
         666 1 1
         754 1 1
      1011.5 1 1
         679 1 1
         409 1 1
        1090 1 1
         127 1 1
        1098 1 1
         598 1 2
         588 1 1
        1277 1 2
      end
      Last edited by Miinni Paalo; 28 Apr 2019, 07:43.

      Comment


      • #4
        Miinni (sorry for miswriting your name in my previuous reply):
        do you mean something along the following lines?
        Code:
        . g reference_phos=900
        
        . g over_under_reference_phos= P_mg/ reference_phos
        
        . regress over_under_reference_phos i.agegr##i.pregn
        note: 2.agegr#2.pregn identifies no observations in the sample
        
              Source |       SS           df       MS      Number of obs   =       100
        -------------+----------------------------------   F(2, 97)        =      0.80
               Model |  .145113725         2  .072556862   Prob > F        =    0.4522
            Residual |  8.79680943        97  .090688757   R-squared       =    0.0162
        -------------+----------------------------------   Adj R-squared   =   -0.0041
               Total |  8.94192315        99  .090322456   Root MSE        =    .30115
        
        ------------------------------------------------------------------------------
        over_under~s |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
             2.agegr |   .1543265   .1271586     1.21   0.228    -.0980482    .4067011
             2.pregn |   .0496505   .1113131     0.45   0.657    -.1712753    .2705763
                     |
         agegr#pregn |
                2 2  |          0  (empty)
                     |
               _cons |   1.042155   .0324734    32.09   0.000     .9777044    1.106606
        ------------------------------------------------------------------------------
        
        .
        Kind regards,
        Carlo
        (StataNow 18.5)

        Comment


        • #5
          Thank you! I have some clue now.
          When i would like to show percentages, is it wrong to use code like this?

          Code:
          . g reference_phos=900 if pregn==1
          (153 missing values generated)
          
          . g over_under_reference_phos= P_mg / reference_phos*100
          (153 missing values generated)
          
          . mean over_under_reference_phos, over(agegr)
          
          Mean estimation                     Number of obs    =     720
          
                      1: agegr = 1
                      2: agegr = 2
          
          ---------------------------------------------------------------------------
                               Over |       Mean   Std. Err.     [95% Conf. Interval]
          --------------------------+------------------------------------------------
          over_under_reference_phos |
                                  1 |   101.1612   1.359148      98.49283    103.8296
                                  2 |    118.681   2.271092      114.2223    123.1398
          ---------------------------------------------------------------------------
          So interpretation is that pregnant women from age group 18-30 have 101% of recommended phosphor intake and pregnant woman from age group 31-35 have 119% of recommended phospor intake.

          Lets assume that even if this kind of approach is somehow correct to show percentages, still how to run correct statistical test to compare these two percentages (because these values are still continuous)?


          Comment


          • #6
            Miinni:
            1) descriptice statistics. I would go a bit different, as your code is, in fact, inferential:
            Code:
            bysort agegr: tabstat over_under_reference_phos, stat(count mean sd p50 min max)
            2) -regress- with interactions between -pregnant- status and -agegr- is the way to go to test what you've in mind.
            However, if you're interested in a simple OLS (ie, with -agegr- onloy as a predictor), you can type:
            Code:
            regress over_under_reference_phos i.agegr
            Please note that, with one predictor only, your regression model may be misspecified (see -estat ovtest-) and, regradless the number of predictors, may be affected by heteroskedastcity (see -estat hettest).

            Eventually, another option is -ttest- with unequal variance (see -help ttest-) or a bootstrapped -ttest- (see -help bootstrap- and example under related entry in Stata .pdf manual).
            Kind regards,
            Carlo
            (StataNow 18.5)

            Comment


            • #7
              Thank you !

              One tiny problem more..

              When i´m trying to make reference value which has decimals it gives me error:

              Code:
               . g reference_B1_mg2 =0,6
              option 6 not allowed

              Comment


              • #8
                Miini:
                if the issue comes from separators format, try:
                Code:
                g reference_B1_mg=0.6
                Otherwise, remove the space before -=- sign and try again.
                Kind regards,
                Carlo
                (StataNow 18.5)

                Comment


                • #9
                  Changing separator format to . helped.

                  Thank you for being very helpful!

                  Comment

                  Working...
                  X