Programming and coding guidance
As well as making sure you document your code for yourself and others, it is important to keep code structured and organised, so it works reliably and is easy to understand. This is helpful for you, but it is also especially important if you aim to follow open science principles and share your code.
A good exercise to improve your code writing skills is to revisit previous code you have written and think about how you could have improved it to make it more understandable or efficient with fresh eyes.
The links to guidance below are organised by program used.
- UK Data Service: Introductory guides on Stata, SPSS, and R
- The Good Research Code Handbook: a handbook by Patrick Mineault covering good code practices. This is based in Python but the principles are applicable to all programs.
- Code Review as a Simple Trick to Enhance Reproducibility, Accelerate Learning, and Improve the Quality of Your Team’s Research: a journal article by Vable, Diehl and Glymour (2021) which introduces the idea of code review and provides an example style guide for coding, code format guidelines, and variable cleaning conventions.
- SPSS Syntax introduction: guidance on how to use and write syntax in SPSS
- SPSS Programming and Data Management: a textbook by Raynald Levesque covering data management using SPSS syntax as well as programming with SPSS and Python. ISBN: 9781568273907
- Stata tutorial: an online tutorial by Germán Rodríguez which includes data management basics, tables and graphics guidance and an introduction to programming in Stata
- The Workflow of Data Analysis Using Stata: a textbook by J. Scott Long which demonstrates how to design and implement efficient workflows for both individual and team projects in Stata. ISBN: 978-1597180474
- Suggestions on Stata programming style: Stata journal entry by Nick Cox with best-practice guidelines for well-presented and efficient programs.
- Programming with R: an online lesson by Software Carpentry about programming in R through carrying out data analysis. It is suitable for non-programmers and those unfamiliar with R, but you must understand the concepts of files and directories.
- Hands-On Programming with R: a book by Garrett Grolemund about programming in R, with hands-on examples. It is suitable for non-programmers and those unfamiliar with R.
- tidyverse – the tidyverse is a collection of packages in the R programming language that are designed to make data manipulation, visualisation, and analysis easier and more efficient. The packages follow a consistent and coherent set of principles and provides a unified framework for working with data.
- R for Data Science: a book by Hadley Wickham and Garrett Grolemund covering how to do data science with R, particularly using the tidyverse package. It describes how to get your data into R, get it into the most useful structure, transform it, visualise it and model it. It is suited for those who are comfortable with R and have experience programming.
- Building reproducible analytical pipelines with R: an online book by Bruno Rodriques which demonstrates how some of the best practices from software engineering and DevOps can be used to make research projects robust, reliable, and reproducible. The book is suitable for those who are comfortable with R and have experience programming and introduces some complex concepts and procedures.
- Mplus users guide: an online user guide that can also be downloaded as a PDF file. Code for each example can be found in the interactive versions of the chapters.
- Mplus web notes: chapter type descriptions of different statistical methods including measurement invariance and latent variables.
- Mplus discussion forum: a discussion forum (now read-only).