Announcement

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

  • Rounding age in months to the completed and nearest 0.5 months

    Hi All,

    I am using Stata 13, and I am asking for assistance with what might be a very easy simple solution for one of you.
    Center for Disease Control (CDC) growth charts were published using 1 month intervals at 0.5 see the following example (except it starts at month 24). This is available at the following link http://www.cdc.gov/growthcharts/html_charts/bmiagerev.htm
    Click image for larger version

Name:	Screen Shot 2015-03-03 at 5.46.21 PM.png
Views:	1
Size:	88.9 KB
ID:	953162


    I need to generate child age in months and round down that information to the nearest completed 0.5 month to be able to match the CDC Growth Charts records.

    My sample is more than 1900 below is the code that I've used.
    Code:
     gen child_agemonth=(measurement_date1-chd_b_date)/30.4375
    replace child_agemonth=round(child_agemonth, 0.5)
    This code does not give me what I am looking for. I want the 116 below to show up as 115.5 instead. I obviously don't want to have to manually do that, any suggestions on how I can change those observations? I am aware that rounding to 0.5 means that 66.1 will be rounded as 66, I just could not come up with a better way to write this code. I looked at trunc, floor, ceil and int, and I thought that I can't use them since they return integers.
    Click image for larger version

Name:	Screen Shot 2015-03-03 at 5.55.16 PM.png
Views:	1
Size:	16.6 KB
ID:	953163


    Thank you for your help!

    Patrick

  • #2
    Can you provide an example of the input values you are working with using the input statement? In observation 1472 above, what was 116 before you issued the replace command?

    The following works as I would expect:

    Code:
    clear
    input mon_age
    126.1
    115.7
    110.3
    121.8
    .
    113.5
    116.1
    120.2
    115.5
    119
    end
    
    gen x=round(mon_age, 0.5)
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Unfortunately round(something,0.5) does not round something to the nearest fraction ending in .5 - it rounds it to the nearest integer multiple of 0.5. So round(116.1,0.5) will yield 116. Your 0.5 is usually something like 0.1 for rounding to one decimal place, or 10 for rounding to a multiple of 10, and so forth. I think you're going to have to do something like add 6 months, round to the full month, and then subtract 0.5, if there's no better approach that I'm unaware of.

      Updated: Better yet, compute the child's age in years, then use floor(age_in_years)+0.5 to eliminate the fractional part, if any, and add the 0.5 that you need.
      Last edited by William Lisowski; 03 Mar 2015, 20:06.

      Comment


      • #4
        Hi Carole,

        The first row below is using the replace command, the mild row is the output of the computation of age in month intact, and the last row is using the code that you provided. As you may notice somethings completely changed, this is becoming more and more confusing.

        Click image for larger version

Name:	Screen Shot 2015-03-03 at 7.42.01 PM.png
Views:	1
Size:	20.0 KB
ID:	953669

        Comment


        • #5
          William can you provide me with an example code and data for 4 observations or so?

          Comment


          • #6
            Please use an input statement for the sample data surrounded by the CODE tags (see FAQ). I'd like to help, but I can't copy a picture to input the data in Stata (and I really don't want to spend time typing it in).

            Also, please provide:
            --measurement_date1
            --chd_b_date
            --a new variable EXPECTED indicating what you want/expect the rounded value to be.
            Last edited by Carole J. Wilson; 03 Mar 2015, 21:07. Reason: Additional request
            Stata/MP 14.1 (64-bit x86-64)
            Revision 19 May 2016
            Win 8.1

            Comment


            • #7
              Does this help?

              Code:
              input age_m1 age_month age_m2
              116       115.7921    116
              120.5    120.3438    120.5
              115.5    115.0716    115
              111.5    111.0438    111
              119.5    118.9685    119
              120.5    119.9181    120
              115       114.6787    114.5
              112       111.5677    111.5
              120       119.7871    120
              118.5    118.3463    118.5
              end

              Comment


              • #8
                Yes, thanks. I edited by above post to ask for:
                --measurement_date1
                --chd_b_date
                --a new variable EXPECTED indicating what you want/expect the rounded value to be.

                These would be helpful
                Stata/MP 14.1 (64-bit x86-64)
                Revision 19 May 2016
                Win 8.1

                Comment


                • #9
                  Ok, I re-read the original post again. I think I understand the dilemma now! Ignore my request above.
                  Stata/MP 14.1 (64-bit x86-64)
                  Revision 19 May 2016
                  Win 8.1

                  Comment


                  • #10
                    I think you want

                    Code:
                    gen child_age_cdc = floor(child_age_month +0.5) - 0.5 if age >= 24.5
                    replace child_age_cdc = 24 if age >= 24 & age < 24.5
                    And I don't know how you want to handle ages below 24 months.

                    Comment


                    • #11
                      I've come up with a slightly different approach depending on how you want to "round".
                      Based on Clyde's code, a value of 120.3438 would be rounded to 119.5, but it seems to me that value would be closer to 120.5 (although I may be misreading this post entirely).

                      If this is what you are looking for, then I think the code below will accomplish this:

                      For comparison, I've included Clyde's approach which produces the variable child_age_cdc. My approach produces new_age. I'll let you figure out how you want to handle the values <=24 months.


                      Code:
                      clear
                      input age_month 
                      115.7921
                      120.3438
                      115.0716
                      111.0438
                      118.9685
                      119.9181
                      114.6787
                      111.5677
                      119.7871
                      118.3463
                      end
                      
                      **Clyde's approach
                      gen child_age_cdc = floor(age_month +0.5) - 0.5 if age_month >= 24.5
                      replace child_age_cdc = 24 if age_month >= 24 & age_month < 24.5
                      
                      **Carole's approach
                      gen new_age=.
                      replace new_age=floor(age_month)+0.5 if age_month<floor(age_month+0.5) & age_month>=24.5
                      replace new_age=ceil(age_month)-0.5 if age_month>floor(age_month+0.5) & age_month>=24.5
                      replace new_age = 24 if age_month>=24 & age_month<24.5
                      list

                      Stata/MP 14.1 (64-bit x86-64)
                      Revision 19 May 2016
                      Win 8.1

                      Comment


                      • #12
                        At #3 above, in haste I misunderstood the problem to be in terms of years rather than months. My larger point about round() being unhelpful for this problem still stood, though.

                        My understanding is that Patrick wants to match children to the table by age. In that case, my interpretation of the table is that, for example, ages of at least 30 months but less than 31 months are meant to match to 30.5. It simply is unclear what CDC intended to happen in the vicinity of 24 months. Below I present four different approaches. My preference is to ignore the first row of the table (tblage2). If the first row is used, then I think the ages should be matched to the row they are nearest (tblage3 and tblage4). Since the CDC labels the table as for ages 2-20 years, I think the extension to ages below 24 months (tblage4) is not justified, and the choice of 23.75 months as a lower cutoff is arbitrary in any event.
                        Code:
                        clear
                        input age_month 
                        35.7921
                        30.3438
                        35.0716
                        31.0438
                        38.9685
                        39.9181
                        34.6787
                        31.5677
                        39.7871
                        38.3463
                        23.5
                        23.6
                        23.7
                        23.8
                        23.9
                        24.0
                        24.1
                        24.2
                        24.3
                        24.4
                        24.5
                        end
                        
                        **Carole's approach
                        gen new_age=.
                        replace new_age=floor(age_month)+0.5 if age_month<floor(age_month+0.5) & age_month>=24.5
                        replace new_age=ceil(age_month)-0.5 if age_month>floor(age_month+0.5) & age_month>=24.5
                        replace new_age = 24 if age_month>=24 & age_month<24.5
                        
                        **William's approach
                        generate tblage1 = floor(age_month)+0.5 if age_month>=25
                        generate tblage2 = floor(age_month)+0.5 if age_month>=24
                        generate tblage3 = tblage1
                        replace  tblage3 = 24.5 if age_month>=24.25 & tblage3==.
                        replace  tblage3 = 24   if age_month>=24    & tblage3==.
                        generate tblage4 = tblage1
                        replace  tblage4 = 24.5 if age_month>=24.25 & tblage4==.
                        replace  tblage4 = 24   if age_month>=23.75 & tblage4==.
                        
                        list, clean noobs



                        Comment


                        • #13
                          In my earlier post (#10), I was guided by the original poster's statement of the problem:

                          I need to generate child age in months and round down that information to the nearest completed 0.5 month to be able to match the CDC Growth Charts records.
                          The code I posted there does exactly that. It maps 120.3438 to 119.5 because 119.5 would be the last completed month--though it is not the nearest. Similarly, an age of, say 30.2 months would map down to 29.5, not up to 30.5 because 29.5 would be the last completed age.

                          That said, I don't know how Patrick arrived at that statement of the problem. The link he provided there shows the full table (and a second one similar to it for the other sex), but there are no instructions or explanations about how it is to be used.

                          At any rate, Patrick now has working code for each of several reasonable interpretations about how one might use the table. It is up to him to decide which of these is most sensible for his purposes.

                          Comment


                          • #14
                            Hi All,

                            Thank you so much for all your feedback and help in this. I have plenty of options to use to try and figure out the best solution for my data.

                            I am trying to mimic the computation of percentiles and z scores for child body mass index that an excel file through the following CDC link http://www.cdc.gov/healthyweight/ass...r_schools.html computes.

                            The first time I computed z scores and percentiles I had age in completed years and when I compared my output to the output produced from the CDC calculator I had about 100 children misclassified in body mass index categories (Out of 2000 Children). Subsequently I tried the computation of age in fully completed months and the half months rounding(Which I shared in the beginning of this post), and I still had a handful of misclassified children (5 to 10). It may be a bit crazy to still want to make sure I don't misclassify 5 children out of 2000, but that's what we do we can't accept biases or errors :-) so we keep refining our method until we perfect it (or think we did, and believe that for a couple of days before we realize another new thing).

                            From what I've read, I can't seem to find if I am supposed to round to the nearest 0.5 or to the last completed 0.5 as all of you point out and have noticed. From a logical perspective I almost would be inclined to think that the nearest 0.5 is what I am supposed to use but that would make a child come out as thiner in percentiles and z scores. Similarly, rounding to the last completed 0.5 could potentially make a child look heavier for a slightly lower age than theirs. Keep in mind the changes in z-scores, percentiles and categories will be fairly minimal based on a 2 to 3 weeks period.

                            I have also been directed to the following excel add ins http://www.healthforallchildren.com/?product=lmsgrowth and I plan to compare my results to those as well.

                            Thanks again for all your help I appreciate it!

                            Patrick

                            Comment


                            • #15
                              Late to this party, but no-one seems to have suggested this:

                              1. create a working variable that is double the number of months

                              2. round to the nearest integer

                              3. halve again

                              Do shout this down if I repeated or missed something.

                              Comment

                              Working...
                              X