Data Analysis Workflow


Data Analysis Workflow

Corey
Welcome to this episode on the data analysis workflow. The central idea is simple but important: a workflow is the whole process from conceiving a research idea through to publication, or, for a student, through to an MSc dissertation or PhD thesis.

Anna
And this matters because many researchers have experienced workflow problems firsthand. Maybe you've lost a file, wondered whether you accidentally deleted one, collaborated on different versions, or struggled to tell apart files with names like chapter1_2019.dat and chap1_2019.dat.

Corey
Exactly. Those problems are signs that the research process could be better organized. A typical workflow might begin by downloading data from an archive, then using software such as SPSS or Stata, or a programming language such as R or Python, to wrangle the data. After that comes exploratory data analysis, formal statistical analysis or modeling, writing up the results, and finally submitting the work for peer review and possible publication.

Anna
But the workflow should not be something we improvise piece by piece. The presentation compares analyzing data without a planned workflow to drinking and driving: even if you are careful, the situation is still highly likely to end in a wreck. So the warning is strong—serious data analysis needs a systematic process.

Corey
A useful way to conceptualize that process is: plan, organize, compute, and document. Those stages form a cycle rather than a rigid one-way path. You may begin with raw data, transform it into an analytical data set, explore it, fit formal models, and then discover that you need to return to exploratory analysis or even go back to data wrangling.

Anna
Let's focus on data wrangling first. One of the strongest recommendations is: do not use drop-down menus. If you perform transformations through a graphical user interface, you may not have an audit trail showing what happened.

Corey
An audit trail is essentially a line of breadcrumbs leading back to where you started. Instead of relying on menu clicks, write your data-wrangling commands in syntax or code. Then every action that transforms the raw data into the analytical data set can be traced and repeated.

Anna
What kinds of actions are we talking about? First, selecting variables. Surveys often contain a very large number of variables, while a particular research question may require only a small subset. We also need to operationalize measures—for example, deciding whether the relevant income measure is net income, gross income, or household income.

Corey
Then there may be recoding, so variables are in the format required for the analysis. Researchers may also select cases, such as focusing only on married couples or households containing people from particular ethnic minority backgrounds. And because every data set is likely to contain missing information, the workflow must record how missing data are handled.

Anna
The key question throughout is: can this action be traced in my audit trail? Even a minor decision during data wrangling can have major consequences later, so the trail should cover every transformation from raw data to analytical data.

Corey
The same principle applies during formal analysis. Researchers need to record which cases were included, how variables were formatted, how missing data were treated, and which estimation method was chosen. For example, a model might require a decision between maximum likelihood estimation and generalized least squares.

Anna
Other decisions can be easy to overlook. You might need to choose weights that fit the analysis or represent the structure of a survey. If you use bootstrapping, you should record the seed used to generate random numbers. With a random-effects model, you may need to document the number of quadrature points, rather than silently accepting or changing the default.

Corey
And in R or Python, the audit trail should include which library or package was used and which version of that software package was installed. These details may seem technical, but they are still part of the analysis and can affect whether someone else gets the same result.

Anna
That brings us to the four pillars of a planned workflow: accuracy, programming efficiency, transparency, and reproducibility. Accuracy means minimizing information loss and errors in the analysis and its outputs.

Corey
Programming efficiency means using the capabilities of the software instead of repeating work manually. For instance, if you need to perform the same task across ten waves of data, you could write a loop rather than carry out the task ten separate times.

Anna
Transparency means being able to show what you did, why you did it, when you did it, and how you did it. Reproducibility goes one step further: can the same result be obtained every time, by different people, or on different machines, such as your laptop and a university network computer?

Corey
Reproducibility becomes especially valuable when research has to be revised. You may need to rewrite a thesis chapter, undertake additional analyses, or respond to reviewers' comments long after the original analysis. A clear workflow lets you return to the project and pick up where you left off.

Anna
Documentation is central to that. J. Scott Long's advice is that it is always easier to document today than tomorrow. Nobody likes writing documentation, but nobody regrets having written it, and the point is that research files are unlikely to be considered too well documented.

Corey
So write comments while you work, even if they are brief. Imagine it is late on a Friday afternoon and you want to leave. It is tempting to save the file and promise to add comments on Monday, but Monday may bring emails, students, and other demands. The comments may never get written, so document the decisions at the time.

Anna
The workflow should also fit the researcher. It should support how you work rather than impose an extremely rigid system that you cannot maintain. A practical workflow is better than a supposedly perfect but regimental one that gets abandoned.

Corey
Fortunately, improving a workflow can require only a modest amount of effort. Someone beginning a project can start with good practices immediately. An experienced researcher can make a similar commitment by deciding that every new project from tomorrow onward will follow a better system.

Anna
One practical strategy is to use a standard directory structure. A suggested structure might include folders for codebooks, clean data, raw data, Stata do-files or other analysis scripts, documents, figures, logs, tables, temporary files, trash, and working files.

Corey
The purpose is to give each type of material a predictable home. Raw data can remain distinct from cleaned data, temporary material can be kept separate from permanent outputs, and day-to-day working files do not have to be confused with files that have been deliberately stored.

Anna
File-naming conventions are just as important. A useful name can include an eye-readable description, the date, the depositor's initials, the version, and the file type. For example, a file based on the British Household Panel Study wave A individual response data could indicate the study and file contents, followed by a date written year-month-day, the initials VG, version 1, and a Stata file extension.

Corey
Writing the date as year, month, and day helps files sort sensibly, especially when many files are created over several years. Including the version is also essential for tracking changes. A naming protocol may seem like a small investment, but it can save time, anxiety, and stress when you are searching for files from an earlier stage of a dissertation or project.

Anna
The analysis file depends on the software. In SPSS it may be a syntax file, in Stata a do-file, in R an R script or an R Markdown document, and in Python perhaps a Jupyter notebook. The specific tool can vary, but the principle does not: use a system that stores the commands for both data wrangling and data analysis.

Corey
It is also useful to place general project information at the top of the file. That could include the author, project, sub-project, date of the next meeting or supervision, the latest update, and a record of previous updates. Put the next actions near the top too, so you do not have to scroll through a thousand lines of code to remember what needs to happen next.

Anna
Variable naming deserves attention as well. Many well-curated data providers use readable conventions. For example, the Understanding Society survey uses names such as a_sex for a sex variable in wave A and b_sex in the next wave. A Youth Cohort Study variable such as t0schtyp can also communicate the survey time and the subject of the variable.

Corey
But not every data set is equally readable. A survey item about whether school helped someone gain confidence might appear under an opaque name such as dx11_a. When variable names are not self-explanatory, researchers need to rely on codebooks and should consider their own clear naming protocols when creating derived variables.

Anna
There is also a practical lesson about estimating work time. The presentation describes the Gale-Lambert constant: work often takes about five times longer than people initially estimate, even with a good workflow. So an hour may become five hours, a day may become five days, and a week may become five weeks.

Corey
That estimate matters for planning your own work, setting expectations with supervisors, writing grant proposals, and costing consultancy or data-analysis projects. A poor workflow can make the work take even longer, so the five-times estimate should be treated as a realistic planning habit rather than an excuse to avoid organizing.

Anna
Let's collect the broader benefits. A good workflow limits duplication of effort: once you have analyzed one wave of a panel study systematically, later waves can often be handled without repeating as much work. Systematic processes also minimize errors and help you detect them.

Corey
They support editing and revision, help collaborators understand and modify one another's work, and speed up outputs in teams, interdisciplinary projects, or international collaborations. A well-documented workflow also supports future research that follows directly from the project or draws on its data and code.

Anna
So the practical checklist is: always maintain an audit trail; avoid drop-down menus and graphical interfaces for analytical transformations; write commands for wrangling and analysis; use a systematic directory structure; establish conventions for file and variable names; track versions; plan rather than work ad hoc; and write plenty of comments.

Corey
And the final principle ties everything together: all serious work must be reproducible, and there must be an audit trail. A planned workflow improves accuracy, efficiency, transparency, and reproducibility, while also helping your future self return to the project with less confusion and less duplicated effort.

Anna
For further guidance, the presentation points to J. Scott Long's book, The Workflow of Data Analysis Using Stata, as a major resource, along with a related PDF talk. It also mentions a practical guide by Vernon Gale and Paul Lambert on producing accurate, efficient, transparent, and reproducible social survey data analysis.

Corey
That is the data analysis workflow in practice: plan the work, organize the files and decisions, compute through recorded commands, and document continuously. If you start tomorrow with an audit trail, clear names, sensible folders, version control, and comments, you will be helping not only your current project but also your future self and anyone who needs to reproduce the research.

Ask anything
We've read this whole study set, so questions about it get the best answers.