Announcement

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

  • Comment out lines when long code separated by "///"-break

    I have the following code to produce graphs:
    HTML Code:
    twoway     ///
    ||         rcap upper lower  `x' if `t'==1 , lc(`col1') lpattern(dash)  /// 
    ||         rcap upper lower  `x' if `t'==0 , lc(`col2') lpattern(dash)    /// 
    ||         bar `y'_count `x' if `t'==1, yaxis(2) lcolor(`col3') barwidth(0.8) lwidth(vvthin) fcolor(none) ///
    ||        bar `y'_count `x' if `t'==0, yaxis(2) lcolor(`col3') barwidth(0.8) lwidth(vvthin) fcolor(none) ///
    ||         scatter `y'_mean  `x' if `t'==1 , mc(`col1') msymbol(square) /// 
    ||         scatter `y'_mean  `x' if `t'==0 , mc(`col2') msymbol(T) ///
        ||  lfit     `y'_mean `x'    if `x'< 60 & `t'==1 , lc(`col1') /// 
        ||  lfit     `y'_mean `x'    if `x'< 60 & `t'==0 , lc(`col2') /// 
        ||  lfit     `y'_mean `x'    if `x'>=60 & `t'==1 , lc(`col1') /// 
        ||  lfit     `y'_mean `x'    if `x'>=60 & `t'==0 , lc(`col2') /// 
    legend(order(3 "`tlabel1'" 4 "`tlabel0'" ///
    ...
    I want to comment out the indented "lfit" lines because I do not need it this time, but I would like to keep the lines there.
    I tried using "//" on every line, and "/**/" on the whole sub-block. However, this gives an error that sees "legend..." already as a new command (i.e. as a new line that is no longer connected to the previous part).

    How can I comment out the indented part without deleting it?

  • #2
    You can do it with /* */, but you have to be very careful about where you put them. In particular, the newline characters (which are not directly visible) after the last /// before the -lfit-s begin and the one preceding -legend(...)- must be contained within them. Here's an example using the auto.dta:
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    .
    . gen junk = price ///
    >         + mpg ///
    >         + rep78 ///
    >         + headroom ///
    > /*
    >         + trunk ///
    >         - weight ///
    >         - length ///
    >         - turn ///
    > */       + displacement ///
    >         + gear_ratio ///
    >         + foreign
    (5 missing values generated)

    Comment


    • #3
      Alternatively, you can place the /// at the start of each line you want to skip but still have Stata interpret the entire command as one. The manual tells us anything following /// is ignored.

      Comment

      Working...
      X