Announcement

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

  • How to change lines' color in the plot region with a loop in xtline?

    Hi all, I'm using xtline to make a graph of predicted rate of change over time and I have 134 lines (id) altogether, whose color need to be changed into black instead of motley fashion. Since the options have exceeded the assumed upper limit of 70, I can't make that with
    "xtline ... if ..., t(time) i(id) overlay plot1(lc(black)) ///
    plot2(lc(black)) plot3(lc(black)) plot4(lc(black)) plot5(lc(black)) ///
    plot6(lc(black)) plot7(lc(black)) plot8(lc(black)) plot9(lc(black)) ///"
    .

    I tried "xtline ... if ..., t(time) i(id) overlay forv i =1/134 {
    ploti(lc(black))
    } ". However, forv is not allowed as an option for xtline.


    So, could you please tell me how to realize it with a loop? Many thanks in advance.

  • #2
    The easiest way is not to use xtline, but just twoway line with the connect(J) option, something like:

    Code:
    xtset id time
    twoway line var time, connect(J)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thanks, Maarten. But the graph after "twoway line predictedrnfl time if PROG_OD==4 | PROG_OD==5, connect (direct) lc(black)" is like this:
      ,
      which is not what I want.
      Can I make it look like:
      ?
      Thanks again.
      Attached Files

      Comment


      • #4
        try sorting the data by id and time before you graph it

        Comment


        • #5
          Yes, I've sorted id and time before that.

          Comment


          • #6
            Have you considered modifying a graph scheme to achieve this?

            For instance, you could save your own scheme file in your ado folder such as 'myscheme.scheme' and then call this option when you produce your graph.

            Your scheme code might look something like this:
            Code:
            #include s2color
            color p black
            color p1 black
            color p2 black
            color p3 black
            color p4 black
            color p5 black
            color p6 black
            color p7 black
            color p8 black
            color p9 black
            color p10 black
            color p11 black
            color p12 black
            color p13 black
            color p14 black
            color p15 black

            Comment


            • #7
              You really don't need to define a scheme to do this. I suspect what Ting is missing most is the possibility of connect(L)

              Code:
              webuse grunfeld
              xtset
              twoway line mvalue year, ysc(log) c(L)
              If the default colour is not black, then add lcolor(black).

              An important side-effect of xtset is to restore the sort order you want for this kind of graph, should it have been lost somehow.

              (I don't know why Maarten recommended c(J); knowing him, I'd suspect he remembered that the default c(l) is insufficient here, but remembered the wrong alternative.)
              Last edited by Nick Cox; 30 May 2014, 03:42.

              Comment


              • #8
                Originally posted by Nick Cox View Post
                (I don't know why Maarten recommended c(J); knowing him, I'd suspect he remembered that the default c(l) is insufficient here, but remembered the wrong alternative.)
                Nick's assumption is correct.
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment


                • #9
                  I repeatedly made Maarten's mistake until I learned that instead of connect(L), I can write connect(ascending).

                  Svend

                  Comment


                  • #10
                    Thanks a lot for all of you guys. "twoway line y x, ysc(log) c(ascending) lcolor(black)" really works now.

                    Comment

                    Working...
                    X