introduction to stata & applying quantitative methods to ...* if you have data formatted for...

18
Introduction to Stata & Applying Quantitative Methods to Your Research Ideas Su Li Center for the Study of Law and Society School of Law University of California, Berkeley 4/9/2015 1

Upload: others

Post on 17-Jul-2020

11 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Introduction to Stata & Applying Quantitative Methods to

Your Research Ideas

Su Li

Center for the Study of Law and Society School of Law

University of California, Berkeley 4/9/2015

1

Page 2: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Workshop Overview

I. Applying Quantitative Methods A. What is quantitative empirical research B. Overview of quantitative empirical research procedures

II. Introduction to Stata A. Stata Layout B. Basic Commands C. Importing Data D. Do files E. Analyzing Data F. Graphing Capabilities

III. Discussion

2

Page 3: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Overview of quantitative empirical research

• What is empirical research?

Research that is based on observations of the world, data, which is a term for facts about the world.

• Qualitative Data vs. Quantitative Data

• What is quantitative empirical research?

3

Page 4: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Example research question:

Do the poor have political power?

Do political representatives vote for the poor?

What factors correlate with representatives’ likelihood of voting for poverty-oriented population?

*voting roll call data

*congressional district demographic characteristics data

*representatives demographic data

4

Page 5: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Overview of quantitative empirical research (stepwise procedures)

1. Research Question

2. Hypothesis construction

3. Research design: concepts quantification (variables)

4. Data collection/Data finding (data coding and cleaning)

5. Data analysis (model construction)

6. Results interpretation

5

Page 6: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Secondary Data Resources Some public/restricted quantitative data resources • The Interuniversity Consortium for Political and Social Research (ICPSR):

http://www.icpsr.umich.edu/icpsrweb/ICPSR/access/index.jsp • The Roper Center Public Opinion Archive: http://www.ropercenter.uconn.edu/data_access/data/search_for_datasets.html • The Social Science Electronic Data Library (SSEDL data archives

http://www.socio.com/members/memonly.htm • Minnesota Population Center Integrated Public Use Microdata Series( IMPUS): http://www.ipums.org/ • Wharton Research Data Services (WRDS): http://wrds.wharton.upenn.edu/ • The Census Bureau: http://www.census.gov/ • American Bar Foundation After the J.D. (AJD )data

http://www.americanbarfoundation.org/publications/AftertheJD/AJD_Data_Access.html • The U.S. Supreme Court Database http://supremecourtdatabase.org/ UC Berkeley resources: • CSLS BELS data link http://www.law.berkeley.edu/4501.htm • Immigration topics data (Irene Bloemraad):

http://www.popcenter.berkeley.edu/resources/migration_data_sets/intro.shtml. • U.C. Data: http://ucdata.berkeley.edu/; California Census Research Data Center (public and restricted

census data) • Berkeley Library Data lab: http://sunsite.berkeley.edu/wikis/datalab/Main/HomePage

6

Page 7: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Data analysis using Stata

A. Stata Layout

B. Basic Commands

C. Importing Data

D. Do files

E. Analyzing Data

- Univariate Analysis

- Bivariate Analysis

F. Graphing module

7

Page 8: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Get familiar with the layout

• Commands window

• Results window

• Review window

• Variables window

• Properties window

• Do file

• Data editor

8

Page 9: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Basic Commands & Stata Syntax

• Most important Stata commands: help summarize

findit regression

display 3+3-1 (functions as calculator)

• Keep in mind, Stata commands are case sensitive (typing Display will not work)

• Commands can be abbreviated:

Typing summarize is the same as typing summ

9

Page 10: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Basic Commands & Stata Syntax

• First, find out what directory Stata is using:

pwd (stands for present working directory)

• To change the directory:

cd C:\folder (in Windows)

• To open a dataset within Stata:

use filename.dta (.dta indicates a Stata file)

• To keep Stata open, but clear all contents:

clear

• To save Stata files:

save filename / save filename, replace

• To exit Stata:

exit / exit, clear

10

Page 11: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Importing Data into Stata

* If the data are in a format that your software can read, then use the read data command.

use filename.dta insheet using filename.csv import using filename.xlsx (only available in stata 12) * Sometimes the data is in a fixed-format ASCII file infix var xx-yy using filename.txt * If you have data formatted for SPSS, SAS, or other software

programs, it is possible to transfer the data into Stata format. Stat Transfer (be careful with case with missing values)

11

Page 12: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Do Files

• A Do file is a set of Stata commands in a plain text file. Do files have the extension “filename.do”

• Stata has a built-in Do-file editor, but you can also use editors such as notepad. Remember to save the file using the extension “filename.do”

• Using Do files is important for replication and modification purposes.

12

Page 13: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Example do file template

capture log close log using statademo.log, replace //default .smcl is not easy to open in other editors *do file name: *by your name _date_ version 11 clear all macro drop _all set linesize 80 * set up the work diretory cd C:\... *********************your commands log close exit, clear

13

Page 14: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Univariate Analysis

• One-way Tabulation – contains information on frequencies/proportions of categories

tab var • Pie Chart – visual representation of either qualitative or

quantitative data graph pie, var • Bar Graph – visual representation of category frequencies

of a qualitative variable graph bar, var • Histogram – visual representation of the spread of values

for a quantitative variable hist var

14

Page 15: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Bivariate Analysis

• Crosstabulation: explores the relationship between two qualitative/categorical variables

tab var1 var2 pwcorr var1 var2 regress var1 var2 • Boxplot: explores the relationship between a categorical & a

quantitative variable (or between two quantitative variables): graph box var • Scatterplot: explores the relationship between two quantitative

variables scatter var1 var2 • Fitting Lines: fits a linear line to two quantitative variables graph twoway (lifit var1 var2) (scatter var1 var2)

15

Page 16: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

How to get your own copy of stata

16

Page 17: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

• end

17

Page 18: Introduction to Stata & Applying Quantitative Methods to ...* If you have data formatted for SPSS, SAS, or other software programs, it is possible to transfer the data into Stata format

Data Verification

Verify data conversion • Compare descriptive statistics • Examine the distribution of missing values Verify variables: values, missing data etc. Verifications and cross-checking should be done at

every step of a research project.

18