Hi all,
I'd like to be able to create a local or global "switch" that I can use to comment out large blocks of code in long dofiles. I understand that can simply put in /* and */ manually. But, often, I have several sections of a dofile that I think of as parts (e.g. variable recoding, first set of regressions, second set of regressions, table generation, etc...).
I would love to be able to have a list of locals at the top of the dofile that lets me toggle any section on or off without having to look for all of the "/*"'s in the file. For shorter bits of code, I often create a global as:
global save_graphs_off "*"
which I can put in front of any set of lines I don't want to run. For exmaple, if I don't want to re-save all of the figures in a dofile, I leave the asterisk in the global:
$save_graphs_off graph save "graph1.gph", replace
$save_graphs_off graph save "graph2.gph", replace
$save_graphs_off graph save "graph3.gph", replace
...
And to re-save all the graphs, I just remove the asterisk. But it's too much trouble to do this for every line of a BLOCK of code. And it's also time consuming to keep putting in and taking out /* ... */ when I want to comment out a bunch of noncontiguous sections throughout the dofile. For example, if I could get this to work as I'd like, it would look something like the following:
* BEGIN DOFILE
#delimit ;
use "data.dta" ;
* NOW I WANT TO WRITE CODE THAT WOULD ALLOW ME TO COMMENT OUT ANY/EACH BLOCK OF COMMANDS ;
* TO COMMENT OUT ANY BLOCK, PUT "/*" IN LOCAL ;
* TO RUN ANY BLOCK, PUT " " IN LOCAL ;
local begin_comment_blk1 " " ;
local end_comment_blk1 " " ;
local begin_comment_blk2 "/*" ;
local end_comment_blk2 "*/" ;
local begin_comment_blk3 " " ;
local end_comment_blk3 " " ;
* 1ST BLOCK OF COMMANDS;
`begin_comment_blk1'
reg y x;
sum x;
... (many lines of code here)
sum y;
`end_comment_blk1'
* 2ND BLOCK OF COMMANDS;
`begin_comment_blk2'
reg y2 x2;
sum x2;
... (many lines of code here)
sum y2;
`end_comment_blk2'
* 3RD BLOCK OF COMMANDS ;
`begin_comment_blk3'
reg y3 x3;
sum x3;
... (many lines of code here)
sum y3;
`begin_comment_blk3'
* END PROGRAM ;
The problem is that this doesn't work. Wondering if anyone has suggestions.
Thanks,
- Dan
I'd like to be able to create a local or global "switch" that I can use to comment out large blocks of code in long dofiles. I understand that can simply put in /* and */ manually. But, often, I have several sections of a dofile that I think of as parts (e.g. variable recoding, first set of regressions, second set of regressions, table generation, etc...).
I would love to be able to have a list of locals at the top of the dofile that lets me toggle any section on or off without having to look for all of the "/*"'s in the file. For shorter bits of code, I often create a global as:
global save_graphs_off "*"
which I can put in front of any set of lines I don't want to run. For exmaple, if I don't want to re-save all of the figures in a dofile, I leave the asterisk in the global:
$save_graphs_off graph save "graph1.gph", replace
$save_graphs_off graph save "graph2.gph", replace
$save_graphs_off graph save "graph3.gph", replace
...
And to re-save all the graphs, I just remove the asterisk. But it's too much trouble to do this for every line of a BLOCK of code. And it's also time consuming to keep putting in and taking out /* ... */ when I want to comment out a bunch of noncontiguous sections throughout the dofile. For example, if I could get this to work as I'd like, it would look something like the following:
* BEGIN DOFILE
#delimit ;
use "data.dta" ;
* NOW I WANT TO WRITE CODE THAT WOULD ALLOW ME TO COMMENT OUT ANY/EACH BLOCK OF COMMANDS ;
* TO COMMENT OUT ANY BLOCK, PUT "/*" IN LOCAL ;
* TO RUN ANY BLOCK, PUT " " IN LOCAL ;
local begin_comment_blk1 " " ;
local end_comment_blk1 " " ;
local begin_comment_blk2 "/*" ;
local end_comment_blk2 "*/" ;
local begin_comment_blk3 " " ;
local end_comment_blk3 " " ;
* 1ST BLOCK OF COMMANDS;
`begin_comment_blk1'
reg y x;
sum x;
... (many lines of code here)
sum y;
`end_comment_blk1'
* 2ND BLOCK OF COMMANDS;
`begin_comment_blk2'
reg y2 x2;
sum x2;
... (many lines of code here)
sum y2;
`end_comment_blk2'
* 3RD BLOCK OF COMMANDS ;
`begin_comment_blk3'
reg y3 x3;
sum x3;
... (many lines of code here)
sum y3;
`begin_comment_blk3'
* END PROGRAM ;
The problem is that this doesn't work. Wondering if anyone has suggestions.
Thanks,
- Dan
Comment