bbdaniels / sumstats

Stata module to generate tables of summary statistics
http://bbdaniels.github.io/stata-code/sumstats
MIT License
3 stars 0 forks source link

error when having condition in parenthasis #3

Closed kbjarkefur closed 5 years ago

kbjarkefur commented 5 years ago

Hi @bbdaniels ,

Not impossible that this is the same issue as in #2 but I'm posting separately in case it is not. I am updating the Stata track 1 lab with the style guides we added in the book and find something strange when using if conditions in sumStats.

This works:

sumStats ///
    (`controls' `outcome1' `outcome2' if treatment == 0) ///
    (`controls' `outcome1' `outcome2' if treatment == 1) ///
    using "${ST1_outRaw}/sumstats_2.xls"                        ///
  , replace stats(N mean median sd min max)

but this does not work:

sumStats ///
    (`controls' `outcome1' `outcome2' (if treatment == 0)) ///
    (`controls' `outcome1' `outcome2' (if treatment == 1)) ///
    using "${ST1_outRaw}/sumstats_2.xls"                          ///
  , replace stats(N mean median sd min max)

This code can be found here in case you want to play with it.

bbdaniels commented 5 years ago

Good point. The issue is that it is relying on the parentheses to separate the commands. This must be fixable by writing a better parser as other commands have similar functionality (twoway for example) but I am perhaps not that skilled... Need to think about it. If you know how, let me know. Also the command should not be capitalized in the SSC version? Please check. Thanks!

bbdaniels commented 5 years ago

Fixed in 542d9615e3bdbe2bd4330a67c5f9016369dc405e. You may also be interested in using the implementation elsewhere, I did it as a subroutine so that it is easy to copy out.

kbjarkefur commented 5 years ago

Cabin fever already on your vacation? :)

More seriously, I will test on the code that caused my original error next week and let you know.

bbdaniels commented 5 years ago

hahah well I'm getting the new computer up and running (it is wonderful) and figured I'd clear some backlog 😜 also as you heard my dad is just out of surgery so I'm here at the house and he is asleep