Announcement

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

  • Two line of the same graph in stata

    Hi there

    I did the following two graph and I was wondering if there was a command that could enable me to have these two line on the same graph?

    Code:
    preserve
    keep if  X==1
    twoway (line Y year)
    restore
    
    preserve
    keep if  X==0
    twoway (line Y year)
    restore


    Thanks a lot!

    Best,

    JD

  • #2
    How about something like this:
    Code:
    twoway (line Y year if X==1) (​(line Y year if X==0)
    Best,
    Alan

    Comment


    • #3
      Hi Alan

      Thanks for your reply
      This command doesn't work as I actually do:

      Code:
       preserve
      keep if  X==1
      collapse (mean) Y, by(year)
      twoway (line Y year)
      restore  
      
      preserve
      keep if  X==0
      collapse (mean) Y , by(year)
      twoway (line Y year)
      restore
      Hence
      twoway (line Y year if X==1) (​(line Y year if X==0) doesn't work.



      Is there another way of doing it?


      Thanks a lot!


      Best Regards,


      JD

      Comment


      • #4
        Don't do that then!

        Code:
        preserve
        keep if  X==1 | X == 0  
        collapse (mean) Y, by(year X)
        twoway (line Y year if X==1) (​(line Y year if X==0)
        restore

        Comment

        Working...
        X