Announcement

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

  • Plot where mean HRQoL is shown for age for males and females.

    Hello,

    I have a quick question I guess: I want to make a plot for mean health related quality of life (HRQoL) for age (each year) shown in two different plots for males and females. I use a data set with all these variables included and am interested in the HRQoL over the years:
    Code:
    tab HRQoL age gender
    egen mhrqol = mean(HRQoL), by(age)
    twoway (line mhrqol age, sort), by(gender)
    The problem is: this gives exactly the same plot for males and females.
    What am I doing wrong? How can I get the correct plot where it represents the mean HRQoL over the years for males and females correctly?
    Last edited by Florian Maissan; 25 Nov 2015, 06:40.

  • #2
    your syntax is incorrect and Stata (and I) will be confused by the extra comma; try
    Code:
    two-way line mhrqol age, sort by(gender)
    if you want side-by-side graphs

    if you want two lines on the same graph, try
    Code:
    twoway (line mhrqol age if gender==0, sort) (line mhrqol age if gender==1, sort)
    note that I have assumed that gender is coded 0/1 - change the code if you use some other coding scheme

    Comment


    • #3
      Rich missed the earlier problem:

      Code:
      egen mhrqol = mean(HRQoL), by(age)
      does exactly what is being complained about, namely ignore gender. Try

      Code:
      egen mhrqol = mean(HRQoL), by(age gender)
      This is another way to do the graph:

      Code:
      separate mhrqol, by(gender) veryshortlabel
      twoway line mhrqol? age, sort
      See also sepscatter (SSC) and mentions on this forum.

      Comment


      • #4
        Hi Rich,

        Thank you very much for your reply. When I use:
        Code:
        twoway (line mhrqol age if gender==1, sort) (line mhrqol age if gender==2, sort)
        I get the same graph as when using:
        Code:
        twoway (line mhrqol age, sort), by(gender)
        Only in your graph it is shown that two lines are predicted in one plot (which is what i want!) but they lie exactly over eachother. Only one line is shown representing both males and females while the mean HRQoL is different for males and females! Did I do something wrong with the egen command where I generated the mean of HrQoL?

        Thank you very much for your fast respond!

        Comment


        • #5
          #3 is a reply to #4: they crossed.

          Comment


          • #6
            Hi Nick,

            Thanks for the respond! You wrote exactly what I responded to Rich, that was my point! You are amazing this is exactly what i needed when i use your code:
            Code:
            egen mhrqol = mean(HRQoL), by(age gender)
            twoway (line mhrqol age, sort), by(gender)
            I get two different plots for males and females which is what i wanted to see, quick follow up question if i can be so rude; Is there a way to combine these two lines into one plot so that i get 1 graph showing 2 plots for males and females. When i use the 'combine' function stata tells me this is not allowed in the twoway graph!?

            Thanks again guys, really appreciate it!

            Comment


            • #7
              #3 is a reply to #6..

              Comment


              • #8
                I'm really sorry Nick, did not yet use your second command. Thank you very much with this code, now I get exactly what i need!!

                Comment


                • #9
                  No need to apologise. Usually I am the one accused of being rude!

                  Comment

                  Working...
                  X