Announcement

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

  • .How to plot graph with many lines?

    Dear all, I have 25 variables and I want to plot line graph.I want the first line to be solid and line color is red.The other 24 lines to be dash and line color are all gs10.
    But I get an error "too many arguments".
    Code:
    #d ;
    line te te1-te24 time ,lp(solid dash dash dash dash dash dash dash dash dash dash 
                 dash dash dash dash dash dash dash dash dash dash dash dash dash dash) 
                 lc(red gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10
                 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10 gs10)  
                 lw(*2) xline(`=tq(2003q4)',lp(dash) lc(black)) yline(0,lp(dash) 
                 lc(black)) ylabel(-0.15(0.05)0.1,angle(h) labs(*0.7) format(%9.1fc)) xtitle("")
                 tlab(1993q1(4)2008q1,labsize(*0.7)) tscale(range(1993q1 2008q1)) 
                 legend(order(1 "Treated" 2 "Controls") ring(0) pos(11) col(1)
                 region(fcolor(none) lp(blank)));
    # d cr     
    
    p21(line(color(gs10)) area(linestyle(color(gs10)))):  too many arguments
    r(103);
    Many thanks in advance.
    Best regards.

    Raymond Zhang
    Stata 17.0,MP

  • #2
    Something more like

    Code:
     
     line te time ,lp(solid) lc(red) lw(*2) || line te1-te24 time, lp(dash ..) lc(gs10 ..)                xline(`=tq(2003q4)',lp(dash) lc(black)) yline(0,lp(dash)               lc(black)) ylabel(-0.15(0.05)0.1,angle(h) labs(*0.7) format(%9.1fc)) xtitle("")              tlab(1993q1(4)2008q1,labsize(*0.7)) tscale(range(1993q1 2008q1))               legend(order(1 "Treated" 2 "Controls") ring(0) pos(11) col(1)              region(fcolor(none) lp(blank)));

    Comment


    • #3
      Dear @Nick Cox ,it still gets an error
      . line te time,lp(solid) lc(red) lw(*2) || line te1-te24 time, lp(dash ..) lc(gs10 ..)
      p21(line(color(gs10)) area(linestyle(color(gs10)))): too many arguments
      Best regards.

      Raymond Zhang
      Stata 17.0,MP

      Comment


      • #4
        Perhaps you can build off the following technique of splitting your line calls with twoway such as twoway (line ......) (line ....)

        Code:
        clear 
        set obs 30
        set seed 12345
        
        
        gen te = (abs(rnormal()-1))^.3 + 1
        
        forvalues x = 1/24 {
            gen te`x' = abs(rnormal() * `x')^.3 
        }
        
        gen t = tq(2007-4) + _n 
        
        twoway (line te te1-te18  t, lcolor(red gs10%20 ..) lwidth(thick thin ..) leg(off)) ///
               (line te19-te24 t,  xlab(, format(%tq))   lcolor(gs10%20 ..)    xtitle("") lwidth(thin ..) leg(off))

        Comment


        • #5
          Justin Niakamal Thanks a lot,It works very well.I split the line calls .
          Code:
          #d ;
              line te1-te12 time ,lp(dash ..) lc(gs10 ..)  || 
              line te13-te24 time ,lp(dash ..) lc(gs10 ..) || 
              line te time,lp(solid) lc(red) lw(*2) 
                       ,xline(`=tq(2003q4)',lp(dash) lc(black)) yline(0,lp(dash) lc(black)) 
                       ylabel(-0.15(0.05)0.1,angle(h) labs(*0.7) format(%9.2fc)) xtitle("") ytitle("") 
                       tlab(1993q1(4)2008q1,labsize(*0.7)) tscale(range(1993q1 2008q1)) 
                       legend(order(25 "Treated" 2 "Controls") ring(0) pos(11) col(1) region(fcolor(none) lp(blank)));
          #d cr
          Best regards.

          Raymond Zhang
          Stata 17.0,MP

          Comment

          Working...
          X