Announcement

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

  • How to recode catagorised variable

    hello everyone,
    I have 5 year age categories as (0-4,5-9,10-14,15-19,20-24,25-29,30-34,35-39,40-44,45-49,50-54,55-59,60-64,65-69,70-74,75-80,80-84,+85).
    Now, I would like to have broad categories as 0-19,20-39,40-59,60-79,80+
    How could I do this? Any help please

    Thank you in advance

  • #2

    Mithila:
    you may want to consider to -replace- your previous age categories.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      hei Carlo,
      i do not have continuous age group
      I have done like it before
      Code:
      gen AgeGroup=1 if age_group==4
      replace AgeGroup=2 if age_group==59
      replace AgeGroup=3 if age_group==1014
      replace AgeGroup=4 if age_group==1519 
      replace AgeGroup=16 if age_group==7579
      replace AgeGroup=17 if age_group==8084
      replace AgeGroup=18 if age_group==85
      and then
      Code:
      label define AgeCat 1 "0-4" 2 "5-9" 3 "10-14" 4 "15-19" 5 "20-24" 6 "25-29" 7 "30-34" 8 "35-39" 9 "40-44" 10 "45-49" 11 "50-54" 12 "55-59" 13 "60-64" 14 "65-69" 15 "70-74" 16 "75-79" 17 "80-84" 18 "85+"
      I am not able to replace in other wide categories.

      Comment


      • #4
        So perhaps you mean
        Code:
        gen NewAgeGroup = 1 if inlist(AgeGroup, 1, 2)
        replace NewAgeGroup = 2 if inlist(AgeGroup, 3, 4)
        //etc.
        YOu will also need to define and apply a new label for this NewAgeGroup variableo

        Comment


        • #5
          Thank you so much Clyde.
          It was a great help.

          Comment


          • #6
            hello all,
            Now I have 5 different age categories.I want to calculate the number of cases for each age group.

            Code:
            tabulate glioma AgeCat
            
             Number of |
                glioma |               Age categories in 20 years
                 cases |         1          2          3          4          5 |     Total
            -----------+-------------------------------------------------------+----------
                     0 |        26          2          0          9         80 |       117 
                     1 |        83         15          0         15         37 |       150 
                     2 |        59         32          4         12         20 |       127 
                     3 |        62         37          9         23         16 |       147 
                     4 |        49         49         15         21          9 |       143 
                     5 |        39         37         17         20          7 |       120 
                     6 |        15         36         27         26          3 |       107 
                     7 |        10         30         29         26          2 |        97
            above I can see 83 cases in Agecat1, 59*2 cases in same Agecat1.
            How could I find all cases for Agecat1?

            Thank you

            Comment


            • #7
              Originally posted by Mithila shrestja View Post
              How could I find all cases for Agecat1?
              Code:
              list if AgeCat==1

              Comment


              • #8
                if I list, it gives me
                Code:
                list if Agecat==1
                
                      +-------------------------------------------------------+
                      | dg_y   AgeGroup      sex   allgli~a      pop   Agecat |
                      |-------------------------------------------------------|
                   1. | 1970        0-4   Female          6   166273        1 |
                   2. | 1970        5-9   Female          6   186729        1 |
                   3. | 1970      10-14   Female          4   194975        1 |
                   4. | 1970      15-19   Female          1   205481        1 |
                  19. | 1971        0-4   Female          3   160437        1 |
                      |-------------------------------------------------------|
                  20. | 1971        5-9   Female          6   184936        1 |
                  21. | 1971      10-14   Female          3   191684        1 |
                  22. | 1971      15-19   Female          2   206166        1 |
                Do I need then myself? it is so long data so i was wondering if I have some ways to add them all

                Comment


                • #9
                  Originally posted by Mithila shrestja View Post
                  ...
                  Now I have 5 different age categories.I want to calculate the number of cases for each age group...
                  Mihila:
                  you may want to consider:
                  Code:
                  tab Agecat
                  Kind regards,
                  Carlo
                  (Stata 19.0)

                  Comment


                  • #10
                    hello Carlo,
                    tab Agecat do not give me what I want.
                    Code:
                     tab Agecat
                    
                      Age group |
                     in 20years |      Freq.     Percent        Cum.
                    ------------+-----------------------------------
                              1 |        352       22.22       22.22
                              2 |        352       22.22       44.44
                              3 |        352       22.22       66.67
                              4 |        352       22.22       88.89
                              5 |        176       11.11      100.00
                    ------------+-----------------------------------
                          Total |      1,584      100.00
                    I have total of 10893 instead.

                    Comment


                    • #11
                      Thank you all
                      I have found the way.
                      by
                      Code:
                      total if Agecat1==1

                      Comment

                      Working...
                      X