worldbank / ietoolkit

Stata commands designed for Impact Evaluations in particular, but also data work in general
https://worldbank.github.io/ietoolkit/
MIT License
216 stars 77 forks source link

`iedorep`: runs of do-files in commented out lines are reported in results #322

Closed luisesanmartin closed 1 year ago

luisesanmartin commented 1 year ago

This do-file (dofile.do):


foreach letter in a b c {
  display "`letter'"
}

//  do "${do_tables}/table_1.do"
//  do "${do_tables}/table_2.do"
//  do "${do_tables}/table_3.do"
//  do "${do_tables}/table_4.do"
//  do "${do_tables}/table_5.do"    
//  do "${do_tables}/table_6.do"    
//  do "${do_tables}/table_7.do"
//  do "${do_tables}/table_b1.do"   

has the following output for iedorep dofile.do:

. iedorep dofile.do

Processing: dofile.do
Entering dofile.do run....
Done with dofile.do!

  +----------------------------------------------------+
  | Line | Depth | Loop | Data | Seed | Sort | Subfile |
  |------+-------+------+------+------+------+---------|
  |    6 |     0 |    1 |      |      |      |     Yes |
  |    7 |     0 |    1 |      |      |      |     Yes |
  |    8 |     0 |    1 |      |      |      |     Yes |
  |    9 |     0 |    1 |      |      |      |     Yes |
  |   10 |     0 |    1 |      |      |      |     Yes |
  |------+-------+------+------+------+------+---------|
  |   11 |     0 |    1 |      |      |      |     Yes |
  |   12 |     0 |    1 |      |      |      |     Yes |
  |   13 |     0 |    1 |      |      |      |     Yes |
  +----------------------------------------------------+

. 

I think this is possibly a bug given that these lines are commented out. Note that I tried this in the current development version, not in the stable one.

bbdaniels commented 1 year ago

There is no deep parsing of line contents here -- it simply recognizes that do is part of the line as it copies it over and flags that as a subfile. These will never return errors though since they will not be executed. I don't have the regex skills to parse out that // is the first non-blank characters, but that would be a potential solution here. Can you try it with /* */ instead and see what it does as well?

luisesanmartin commented 1 year ago

Do-file:


foreach letter in a b c {
  display "`letter'"
}

/*
do "${do_tables}/table_1.do"
do "${do_tables}/table_2.do"
do "${do_tables}/table_3.do"
do "${do_tables}/table_4.do"
do "${do_tables}/table_5.do"    
do "${do_tables}/table_6.do"    
do "${do_tables}/table_7.do"
do "${do_tables}/table_b1.do"
*/

Output:

. iedorep dofile.do

Processing: dofile.do
Entering dofile.do run....
Done with dofile.do!

. 

It seems to work correctly

luisesanmartin commented 1 year ago

But when /* ... */ are in the same line, it shows the same output as before:


foreach letter in a b c {
  display "`letter'"
}

/* do "${do_tables}/table_1.do" */

output:

. iedorep dofile.do

Processing: dofile.do
Entering dofile.do run....
Done with dofile.do!

  +----------------------------------------------------+
  | Line | Depth | Loop | Data | Seed | Sort | Subfile |
  |------+-------+------+------+------+------+---------|
  |    6 |     0 |    1 |      |      |      |     Yes |
  +----------------------------------------------------+

.