Stata condition batch/interactive mode

When using large register data it can be worth testing out pieces of code before you run it on a batch server using the full sample. I do this usually by inserting a local such as which I then include in the use command: I used to add a local local testing=”” whenever I sent…

When using large register data it can be worth testing out pieces of code before you run it on a batch server using the full sample. I do this usually by inserting a local such as

local testing="in 1/10000 using"

which I then include in the use command:

use `testing' ${data_folder}/data.dta

I used to add a local local testing="" whenever I sent the file to the batch server, i.e. to include all observations available.

But there is an easy way to automate that by using the c(mode) which returns batch if the code runs on a batch server. So I can use this information:

if "`c(mode)'"=="batch" {
local testing=""
}
else local testing="in 1/10000 using"

Thanks to Raymond Guiteras for pointing out an improvement of the code!