Announcement

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

  • Plot by groups

    Hello I have a very basic problem, unfortunately the forum posts could not help me. so thank you in advance if anyone can help me.

    I run a regression as follows:


    foreach x of numlist 1 2 3 4 {
    reg sport time if group==`x'
    }

    sport is the duration of sports per week in hours
    group is a categorial variable because i want to see if people of different groups differ

    so i want to see the development of hours of sports across time in different groups (i do not want to incude interaction effects but use the if command, i hope it is possible like that)

    I would like to have a graph of this:
    y-achsis: hours of sports
    x-achsis: time
    and then i would like to have for each of the groups one line in the graph.

    does this work with twoway connected?
    sorry i dont get it :-(

    maybe one can help?
    thank you so much!!!

    best

  • #2
    Do you mean something like this?

    Code:
    sysuse nlsw88, clear
    
    twoway (lfit wage age if race == 1) ///
           (lfit wage age if race == 2) ///
           (lfit wage age if race == 3), ///
           legend(label(1 White) label(2 Black) label(3 Other) cols(3))
    Using connected to plot the regression line would first require saving the predicted values:

    Code:
    foreach x in 1 2 3{
        quietly reg wage age if race == `x'
        predict yhat`x'
    }
    
    twoway (connected yhat1 age if race == 1) ///
           (connected yhat2 age if race == 2) ///
           (connected yhat3 age if race == 3), ///
           legend(label(1 White) label(2 Black) label(3 Other) cols(3))

    Comment


    • #3
      YES!
      Exactly what i meant. thats perfect. you are the heroe of my day!!!!
      i very much appreciate your answer.

      perfect

      Comment

      Working...
      X