April 22, 2018

Stopping midway while running a do-file

If you're like me who always use a do-file even when running short analyses (e.g. just one chart! -- it helps if you always have a record of what you're doing; I even put a time stamp on mine), more often than not you want to see ONLY the result of some codes found in the middle of a do-file. For instance, in the middle of the do-file, you have codes for running a regression. If you just want to see the regression results without seeing the output, you have several options.

If you have more patience than me, you can just highlight only the set of codes you want to see the results of (the regression codes for instance) and then type Ctrl+D to run the codes. But maybe this is cumbersome because before running the regression, you may need to prepare the data first, and maybe generate new variables. So you would need to go back further and highlight a few more lines of codes.

An alternative would be not to highlight anything and just simply click Ctrl+D. Of course, this would run the whole do-file so an additional step for you is to look at the results window and search for the regression results. But with all the output of other analyses included in the do-file also presented in the results window, I'm sure you will soon start to think there should be an easier way to do this.

And that easier way is to use "/*". Putting these two characters after the codes for the analysis you want to see (the regression codes in my example) would suppress the results of the rest of the analyses in the do-file. Yes, you'll still see the results of the analyses at the earlier portion of the do-file (before the regression analysis in my example), but at least all you need to do is just look for the start of where the results are suppressed, and before that you will find the analysis you want to see (i.e., the regression results).

Then again, if you're like me, I hate that I have to scroll back up, especially if the do-file is horribly long.

This brings us to what I think is the best and simplest solution. Just use "exit". Write this command after the codes you want to see and when you type Ctrl+D without highlighting any codes, the do-file will run and end immediately after the output you are looking for is presented in the results window. No need for scrolling up and down. Simple as that.

exit