Adding error code checking to state batch

I got some code to check whether Stata exited with error. Somehow,
Stata does not automatically report error codes back to the shell when
it exits, so we were not being informed about failures of build_data.do.