and, for each output it creates, explicitly loads data before analyzing them. This setup encourages data manipulation to be done earlier in the workflow (that is, in separate cleaning and construction scripts). It also prevents the common problem of having analysis scripts that depend on other analysis scripts being run before them. Such dependencies tend to require manual instructions so that all necessary chunks of code are run in the right order. Coding each task so that it is completely independent of all other code, except for the master script, is recommended. It is possible to go so far as to code every output in a separate script, but the key is to make sure that it is clear which data sets are used for each output and which code chunks implement each piece of analysis (see box 6.5 for an example of an analysis script structured like this). BOX 6.5 WRITING ANALYSIS CODE: A CASE STUDY FROM THE DEMAND FOR SAFE SPACES PROJECT The Demand for Safe Spaces team split the analysis scripts into one script per output and reloaded the analysis data before each output. This process ensured that the final exhibits could be generated independently from the analysis data. No variables were constructed in the analysis scripts: the only transformation performed was to subset the data or aggregate them to a higher unit of observation. This transformation guaranteed that the same data were used across all analysis scripts. The following is an example of a short analysis do-file: 1 /**************************************************************************************** 2 *
Demand for "Safe Spaces": Avoiding Harassment and Stigma
*
3 ***************************************************************************************** 4
OUTLINE:
PART 1: Load data
5
PART 2: Run regressions
6
PART 3: Export table
7
REQUIRES: ${dt_final}/platform_survey_constructed.dta
8
CREATES:
9
WRITEN BY:
${out_tables}/priming.tex Luiza Andrade
10 11 ***************************************************************************************** 12 *
PART 1: Load data
13 ****************************************************************************************/ 14 15
use "${dt_final}/platform_survey_constructed.dta", clear
16 17 /**************************************************************************************** 18 *
PART 2: Run regressions
19 ****************************************************************************************/ 20 21
reg scorereputation i.q_group, robust
22
est sto priming1
23
(Box continues on next page)
CHAPTER 6: CONSTRUCTING AND ANALYZING RESEARCH DATA
137