Poli 5D Social Science Data Analytics Functions in Excel (2); Intro - - PowerPoint PPT Presentation

poli 5d social science data analytics
SMART_READER_LITE
LIVE PREVIEW

Poli 5D Social Science Data Analytics Functions in Excel (2); Intro - - PowerPoint PPT Presentation

Poli 5D Social Science Data Analytics Functions in Excel (2); Intro to Stata Shane Xinyang Xuan ShaneXuan.com January 26, 2017 ShaneXuan.com 1 / 14 Contact Information Shane Xinyang Xuan xxuan@ucsd.edu The teaching staff is a team!


slide-1
SLIDE 1

Poli 5D Social Science Data Analytics

Functions in Excel (2); Intro to Stata Shane Xinyang Xuan ShaneXuan.com January 26, 2017

ShaneXuan.com 1 / 14

slide-2
SLIDE 2

Contact Information

Shane Xinyang Xuan xxuan@ucsd.edu The teaching staff is a team! Professor Roberts M 1600-1800 (SSB 299) Jason Bigenho Th 1000-1200 (Econ 116) Shane Xuan Th 1200-1400 (SSB 332) Supplemental Materials UCLA STATA starter kit http://www.ats.ucla.edu/stat/stata/sk/ Princeton data analysis http://dss.princeton.edu/training/

ShaneXuan.com 2 / 14

slide-3
SLIDE 3

Road map

Here is what we are going to cover in today’s section: – Logical functions in Excel – Nested IF functions in Excel – Macros in Excel – Introduction to Stata

ShaneXuan.com 3 / 14

slide-4
SLIDE 4

Road map

Here is what we are going to cover in today’s section: – Logical functions in Excel – Nested IF functions in Excel – Macros in Excel – Introduction to Stata Let’s take a poll really quick – in which order do you want me to cover these topics in today’s section?

ShaneXuan.com 3 / 14

slide-5
SLIDE 5

Road map

Here is what we are going to cover in today’s section: – Logical functions in Excel – Nested IF functions in Excel – Macros in Excel – Introduction to Stata Let’s take a poll really quick – in which order do you want me to cover these topics in today’s section? – Should I slow down in the section?

ShaneXuan.com 3 / 14

slide-6
SLIDE 6

Road map

Here is what we are going to cover in today’s section: – Logical functions in Excel – Nested IF functions in Excel – Macros in Excel – Introduction to Stata Let’s take a poll really quick – in which order do you want me to cover these topics in today’s section? – Should I slow down in the section? – Any questions that I can answer (w.r.t lectures, sections, homework, ...)?

ShaneXuan.com 3 / 14

slide-7
SLIDE 7

Logical functions

We are going to go through four examples in the next few slides to wrap up logical functions.

ShaneXuan.com 4 / 14

slide-8
SLIDE 8

Logical functions

ShaneXuan.com 4 / 14

slide-9
SLIDE 9

Logical functions

ShaneXuan.com 4 / 14

slide-10
SLIDE 10

Logical functions

ShaneXuan.com 4 / 14

slide-11
SLIDE 11

Logical functions

ShaneXuan.com 4 / 14

slide-12
SLIDE 12

Nested IF

Scenario: You want to test for multiple outcomes. Solution: A nested IF function is when one IF function is placed inside another IF function to test an additional condition.

ShaneXuan.com 5 / 14

slide-13
SLIDE 13

Macros in Excel

Scenario: We want to perform repetitive tasks consistently Solution: Use macros!

◮ You record a macro ◮ You then apply the macro to other cells

ShaneXuan.com 6 / 14

slide-14
SLIDE 14

Macros in Excel

Record Macro

ShaneXuan.com 6 / 14

slide-15
SLIDE 15

Macros in Excel

Stop Recording

ShaneXuan.com 6 / 14

slide-16
SLIDE 16

Macros in Excel

In a new worksheet, apply Macros

ShaneXuan.com 6 / 14

slide-17
SLIDE 17

Macros in Excel

What’s under the hood?

ShaneXuan.com 6 / 14

slide-18
SLIDE 18

We are done with Excel!

We are done with Excel! What to do next?

◮ Check out VBA if you want know more about Excel ◮ We are going to move on to Stata and R for the rest of the

quarter

ShaneXuan.com 7 / 14

slide-19
SLIDE 19

We are done with Excel!

We are done with Excel! What to do next?

◮ Check out VBA if you want know more about Excel ◮ We are going to move on to Stata and R for the rest of the

quarter Before then, let’s take attendance.

ShaneXuan.com 7 / 14

slide-20
SLIDE 20

Introduction to Stata

◮ Change CD (cd “/Users/Shane/Dropbox/Poli5D/psets/”) ◮ Import data ◮ Summarize variable ◮ IF statement in Stata ◮ Lookup function in Stata ◮ Help command ◮ Sort command ◮ Create .log files

ShaneXuan.com 8 / 14

slide-21
SLIDE 21

Import data in Stata

ShaneXuan.com 9 / 14

slide-22
SLIDE 22

Import data in Stata

Example: import excel “h1 fams data.xlsx”, sheet(“Families”) firstrow clear

ShaneXuan.com 9 / 14

slide-23
SLIDE 23

Import data in Stata

Example: import excel “h1 fams data.xlsx”, sheet(“Families”) firstrow clear

◮ import data

ShaneXuan.com 9 / 14

slide-24
SLIDE 24

Import data in Stata

Example: import excel “h1 fams data.xlsx”, sheet(“Families”) firstrow clear

◮ specify sheet name

ShaneXuan.com 9 / 14

slide-25
SLIDE 25

Import data in Stata

Example: import excel “h1 fams data.xlsx”, sheet(“Families”) firstrow clear

◮ Make the first row to be variable names

ShaneXuan.com 9 / 14

slide-26
SLIDE 26

Import data in Stata

Your data look like:

ShaneXuan.com 9 / 14

slide-27
SLIDE 27

Summarize variables in Stata

Example:

ShaneXuan.com 10 / 14

slide-28
SLIDE 28

Summarize variables in Stata

Example:

ShaneXuan.com 10 / 14

slide-29
SLIDE 29

Summarize variables in Stata

Example:

ShaneXuan.com 10 / 14

slide-30
SLIDE 30

IF statements in Stata

Example: Syntax:

◮ Count if (variable == value) ◮ Other operations: ! =

> < <= >= Note: In Stata, the single equal (=) is used as a set equal

  • perator; the double equals (==) is used to test for equality;

exclamation mark (!) means “NOT”

ShaneXuan.com 11 / 14

slide-31
SLIDE 31

IF statements in Stata

Example: Note: In Stata, & means “AND”, and | means “OR”

ShaneXuan.com 11 / 14

slide-32
SLIDE 32

IF statements in Stata

Example: Note: In Stata, the single equal (=) is used as a set equal

  • perator; the double equals (==) is used to test for equality

ShaneXuan.com 11 / 14

slide-33
SLIDE 33

Others

◮ Lookup function:

list if (variable) == (value) & (variable) != .

◮ Help command: help tabulate ◮ Sort command: sort (variable) ◮ .log file:

– log using “log example”, text – clear more . . . ←(your code here) – log close

ShaneXuan.com 12 / 14

slide-34
SLIDE 34

Save your .do file!

ShaneXuan.com 13 / 14

slide-35
SLIDE 35

Concluding Remarks

We covered many things (but definitely not everything) that are related to your Problem Set 2. Make sure that you

  • 1. Do the readings (!!)
  • 2. Read lecture slides and section slides
  • 3. Learn through trial and error

Be ready to put in hard work while doing the second problem set. Start early, because I hold office hours the day after the due date.

ShaneXuan.com 14 / 14