Announcement

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

  • help for line graph

    hi everyone,


    i have a data, see attachment, i want to get the line graph of variable BMI by different age and group , want to get just like this graph in word .

    Y17-Y25s the range of age from 17-25, the number is BMI
    what is the suitable command ?

    thanks
    group Y17 Y18 Y19 Y20 Y21 Y22 Y23 Y24 Y25
    1 23 25 27 28 29 27 29 31 29
    2 26 25 28 27 30 27 26 28 32
    3 27 26 23 24 27 29 30 32 34
    4 29 28 31 30 32 34 34 35 37
    Attached Files

  • #2
    Hi Jianbo,

    Please see the forum FAQ, specifically section 12.5, which states why you should not post attachments in Word/Excel.

    I can't see how you would like your graph to be, but try this and see if it helps.

    Code:
    clear
    input byte(group y17 y18 y19 y20 y21 y22 y23 y24 y25)
    1 23 25 27 28 29 27 29 31 29
    2 26 25 28 27 30 27 26 28 32
    3 27 26 23 24 27 29 30 32 34
    4 29 28 31 30 32 34 34 35 37
    end
    
    reshape long y, i(group) j(bmi)
    rename bmi years
    rename y bmi
    separate bmi, by(group)
    graph twoway line bmi1 bmi2 bmi3 bmi4 year

    Comment


    • #3
      thanks for your help , my friend Igor.

      I get it.

      best.

      jianbo

      Comment


      • #4
        I added another way below, before separating bmi by group. This alternative doesn't allow different style or color attributes by group, but can be more useful when there are a lot of lines, for example when each line is a subject in a spaghetti plot.


        Code:
        clear
        input byte(group y17 y18 y19 y20 y21 y22 y23 y24 y25)
        1 23 25 27 28 29 27 29 31 29
        2 26 25 28 27 30 27 26 28 32
        3 27 26 23 24 27 29 30 32 34
        4 29 28 31 30 32 34 34 35 37
        end
        
        reshape long y, i(group) j(bmi)
        rename bmi years
        rename y bmi
        sort group years
        graph twoway line bmi years, connected(L) // alternative option
        separate bmi, by(group)
        graph twoway line bmi1 bmi2 bmi3 bmi4 year

        Comment


        • #5
          thanks Dave

          Comment


          • #6
            Hi, everyone , i met a question, how could i plot this graph with 95%CI ,using my data attached
            Attached Files

            Comment


            • #7

              input byte( Group age2 age3 age4 age5 bmi2 bmi3 bmi4 bmi5) 1 4 3.58 1 3 5 5.17 5.28 1 5 3.35 1 3 5 3.27 3.37 1 4 6.77 1 3 5 4.83 4.96 1 5 3.67 1 2 4 5.73 5.87 1 5 4.79 2 5 4.91 2 3 5 2.91 2.96 2 4 3.6 2 4 3.08 2 4 3.23 2 5 2 5 5.48 2 5 3.89 2 2 4 2.85 2.62 3 5 3.43 3 3 5 5.23 5.12 3 5 4.81 3 5 5.5 3 4 2.61 3 4 4.07

              Comment


              • #8
                Hi everyone ,thanks.
                how to caculate the annual change rate of income(maxi_income minus year15_income,then by the year difference )
                id a_year a_income b_year b_income c_year c_income d_year d_income
                1 0 10000 5 15000 10 14000 15 13000
                2 0 15000 5 13000 10 12000 15 11000
                3 0 8000 5 10000 10 15000 15 16000

                Comment

                Working...
                X