Learning to code

Here is some tip and advice on how to learn coding.

Big picture

A well respected resource that introduces thinking about coding for data analysis is Code and Data for the Social Sciences: A Practitioner’s Guide by Matthew Gentzkow and Jesse M. Shapiro. They talk about issues like replication, organization of a project, or version control.

Learning to code for data analysis

R

There are two popular toungues (beyond base) in R, called data.table and tidyverse. We use tidyverse.
There are great many resources, to learn R for data analysis. Here are some ideas:

  1. To learn tidyverse, you may start with the wonderful book by Hadley Wickham and Garrett Grolemund R for Data Science.
  2. A wonderful intro, with a focus on starting R and data wrangling, is by Jenny Briant’s Data wrangling, exploration, and analysis with R course, aka STAT545.
  3. U Cincinatti has a very nice guide with discussions on basics, workflow, manipulation in R Programming Guide.
  4. At CMU, Alexandra Chouldechova has a nice programming in R materials.
  5. A great online course is by Roger Peng, Jeff Leek and Brian Caffo R programming onCoursera
  6. At Data Carpentry, François Michonneau and Auriel Fournier has a fantastic content –Data Analysis and Visualization in R for Ecologists.
  7. Grant McDermott has a more advanced lecture series with amazing content Data Science for Economists.
  8. Working with time series is hard. A great resource by Hansjörg Neth: Data Science for Psychologists Chapter 10 Dates and times.
  9. What They Forgot to Teach You About R, awesome material by Jennifer Bryan and Jim Hester. workshop material.
  10. Great style guide with suggestions on coding by Sean Higgins. R guide.
  11. Nice, dplyr focused intro into called An introductory workshop on modern data analyses and workflows by folks at Aarhus, available as Reproducible Research in R
  12. A list of useful stuff: Hacks,
  13. Very nice intro to R is the R introduction by Hans H. Sievertsen in Bristol, UK. Coolness in shinyapps!

Stata

There are many great materials, here is some we like:

  1. UCLA extensive material at UCLA IDRE Stats.
  2. Amazing two part series by Kurt Schmidheiny Part 1 Part 2
  3. At Data Carpentry, CEU’s Miklós Koren and Arieda Muco are developing a Stata course for Economist.
  4. A Stata cheatsheat.
  5. One of the greatest, coolest somewhat advanced Stata resource is the Medium site of Asjad Naqvi The Stata Guide that includes pearls like Stata and Github integration

Python

Python is a general purpose language, used for many applications beyond data science/statistics. There are great many resources, to learn Python for data analysis. Here are some ideas:

  1. Very nice courses are available widely, for instance on Datacamp, and Codeacademy.
  2. A set of very nice lessons at Python for Everybody.
  3. NYU has a great group also offering a Python cours by QuanEcon.
  4. Great style guide with suggestions on coding by Sean Higgins. Python guide.
  5. Great intro book and material by Allen B. Downey to Think Python –How to Think Like a Computer Scientist
  6. A great online book by Arthur Turrell Coding for Economists – a guide for (not only for) economists on what programming is, why it’s useful, and how to do it.
  7. Al Sweigart, 2019 (2nd ed) Automate the Boring Stuff with Python, 2nd Edition

Learning a second language

Some people have experience using one language but would now learn a second one. Some ideas we found useful:

Check out the texbook’s Github and compare

Check out the codebase for the textbook at Gabors Data Analysis Github page
Take an example: management quality and firm size, descriptive statistics

  • in R with tidyverse/dplyr, modelsummary and ggplot
  • in Stata with tabstat, twoway scatter
  • in Python with pandas and plotnine/ggplot

Github

R for Stata users

In Economics and many other social sciences, we use Stata for research, and learnt R or Python as a second language. Here are some links and tutorials we found useful.

  1. Matthieu Gomez has a wonderful intro to R for Stata users . For instance the bit on regressions is pretty useful, I come back to it regularly.
  2. John Ricco has a short intro to basics of data wrangling
  3. Nick Huntington-Klein, Grant McDermott and Kyle Butts collaborate for a new (2021) and superb transition resource From Stata to R, like check this out on cleaning. A key position I love is building with a few pacakges only!

R to/from Python

For this textbook, Stata and R code were developed early on, and we started to work on Python code set only after the proof was ready. Some ideas we (and our RAs) found useful

  1. GGplot for Python by Monash
  2. Pandas and tidyverse
  3. A new textbook, Foundations of Statistics for Data Scientists by Alan Agresti and Maria Kateri has a very expansive code support in R, Python

Python for Stata users

  1. Adam Ross Nelson (2020) Going From Stata to Pandas – a longer post on Medium

More translations

  • To even more translations across languages, check out Library of Statistical Techniques – LOST is a publicly-editable website with the goal of making it easy to execute statistical techniques in statistical software. This is a project by Nick Huntington-Klein but we can all contribute now, as many people has done. Furthermore check out the Github page for Nick’s excellent causality book, also on all three languages.

More resources

  • Great list of data tools by the UC Berkeley Library and Research IT run Research Data Management (RDM) Program
  • Oxford University’s Center for the Study of African Economies runs Coders Corner - a collection of coding help on many topics. Mostly Stata, but some R, Python (and Matlab)

Help us expand this bit

So if you are here, you have scrolled through. Maybe you thought, why don’t you have X. Well, please share ideas with HERE. Cheers.

Also, check out the book that holds up the code!

Use to hold your laptop