Top Banner
Computer Tools for Academic Research Fall 2011 Miklós Koren [email protected] https://tools.coauthors.net
31
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Tools for Academic Research

Computer Tools for Academic ResearchFall 2011

Miklós [email protected]

https://tools.coauthors.net

Page 2: Computer Tools for Academic Research

Introduction

Page 3: Computer Tools for Academic Research

The goal of the course

I We use computers all the time in our research.I downloading dataI running regressionsI writing text

I The goal of this course is to make your computer use moreeffective.

1

Page 4: Computer Tools for Academic Research

Learning outcomes

At the end of the courseI you will be 30% more productiveI your coauthors will love you (after some initial struggle)

2

Page 5: Computer Tools for Academic Research

An orderly printing shop

3

Page 6: Computer Tools for Academic Research

Keeping an orderly shop

I We are learning how to keep an orderly shop forI faster, more reliable work

I writing clean codeI easier collaboration with others

I including your future self

4

Page 7: Computer Tools for Academic Research

Outline

1. Programming principles, philosophies and their relevance forthe academic product cycle

2. Version control: keeping your code and other files in check3. Thinking about data: beyond the Excel spreadsheet4. Modular programming in Python5. More Python6. Testing: trying to break your own code

7. NumPy as a Matlab alternative.8. Symbolic math.9. Reference tools.

5

Page 8: Computer Tools for Academic Research

Outline

1. Programming principles, philosophies and their relevance forthe academic product cycle

2. Version control: keeping your code and other files in check3. Thinking about data: beyond the Excel spreadsheet4. Modular programming in Python5. More Python6. Testing: trying to break your own code7. NumPy as a Matlab alternative.8. Symbolic math.9. Reference tools.

5

Page 9: Computer Tools for Academic Research

Example

To illustrate the tools, we will use a sample "research project":I Hypothetical data on friends and whether or not you

downloaded Angry Birds.I We want to test whether friends’ download makes you more

likely to download.I Simple OLS for now, can think of instruments later.

6

Page 10: Computer Tools for Academic Research

7

Page 11: Computer Tools for Academic Research

Data on people

person,angrybirds1,02,13,0

8

Page 12: Computer Tools for Academic Research

Data on friendships

friend1,friend21,21,3

9

Page 13: Computer Tools for Academic Research

The academic product cycle

Page 14: Computer Tools for Academic Research

The academic product cycle

In a typical empirical project, you1. download/get the data2. clean the data3. run many descriptives and checks4. run regressions5. create tables, graphs6. write the paper (always in LATEX)7. write the slides8. submit to journal, present at conferences9. get rejected: go back to 3-6 until published

10. get request for replication code/data

10

Page 15: Computer Tools for Academic Research

Similarities to software development

I Much of this is also done by software developers.1. plan a project2. write code3. rewrite code4. release new version5. get bug reports and feature requests6. go back to 2-4

I These are also done in teams.

I Luckily (good) software developers have nice tools to makethem more productive.

11

Page 16: Computer Tools for Academic Research

Similarities to software development

I Much of this is also done by software developers.1. plan a project2. write code3. rewrite code4. release new version5. get bug reports and feature requests6. go back to 2-4

I These are also done in teams.I Luckily (good) software developers have nice tools to make

them more productive.

11

Page 17: Computer Tools for Academic Research

Programming principles

Page 18: Computer Tools for Academic Research

Programming principles

I Many programming courses are about how to optimizecomputer resources.

I This is about how to optimize human resources.I pragmatic programmingI agile programming

I Your time is more valuable than CPU time.

12

Page 19: Computer Tools for Academic Research

The n commandments

1. Don’t repeat yourself.2. Archive your work.3. Embrace plain text.4. Embrace the command line.5. Write modular code.6. Make no assumptions.

13

Page 20: Computer Tools for Academic Research

The DRY principle

Don’t Repeat Yourself

Ever.Treat this as dogma.

14

Page 21: Computer Tools for Academic Research

The DRY principle

Don’t Repeat YourselfEver.

Treat this as dogma.

14

Page 22: Computer Tools for Academic Research

The DRY principle

Don’t Repeat YourselfEver.Treat this as dogma.

14

Page 23: Computer Tools for Academic Research

The DRY principle

I Every piece of information should have a single authoritativesource.

I Compare:I areg lnwage treatment age, a(firmid)

cluster(firmid)I areg lnwage treatment schooling, a(firmid)

cluster(firmid)I To:

I foreach X in age schooling {I areg lnwage treatment ‘X’, a(firmid)

cluster(firmid)I }

I Why is the second better?

15

Page 24: Computer Tools for Academic Research

Derived principles

I Use version control.I Never send "draft_may_14.doc" by email.

I If it’s worth repeating, it’s worth automating.I Use srcipts to run regressions etc.

16

Page 25: Computer Tools for Academic Research

Programming approaches

We talk about three:1. procedural (Basic, Pascal, Matlab, Stata)2. functional (Haskell)3. object oriented (Java,Python)

17

Page 26: Computer Tools for Academic Research

A procedural code

1. x = loaddata(’file.csv’)2. for i=1:len(x)3. y(i) = 2*x(i)4. save y

I Does what you say in the order you say it. (Great for controlfreaks.)

I But violates principle 5.I Others will have no clue what it does.I Impossible to debug.

18

Page 27: Computer Tools for Academic Research

A procedural code

1. x = loaddata(’file.csv’)2. for i=1:len(x)3. y(i) = 2*x(i)4. save y

I Does what you say in the order you say it. (Great for controlfreaks.)

I But violates principle 5.I Others will have no clue what it does.I Impossible to debug.

18

Page 28: Computer Tools for Academic Research

Functional programming

y = f(x)

I Just implement the function and don’t worry about the rest.I Suits well to math / economics applications.I Conforms with principles 5 and 6.

I But we are often far from this ideal.

19

Page 29: Computer Tools for Academic Research

Functional programming

y = f(x)

I Just implement the function and don’t worry about the rest.I Suits well to math / economics applications.I Conforms with principles 5 and 6.I But we are often far from this ideal.

19

Page 30: Computer Tools for Academic Research

Object orinted programming (OOP)

I Objects have attributes (data) and methods (functions).I regression.yI regression.xI regression.run()

I Useful to collect data and functions that belong together.I Also permits more complicated hieararchies among objects.

I Most modular of the three.

20

Page 31: Computer Tools for Academic Research

Object orinted programming (OOP)

I Objects have attributes (data) and methods (functions).I regression.yI regression.xI regression.run()

I Useful to collect data and functions that belong together.I Also permits more complicated hieararchies among objects.

I Most modular of the three.

20