+ All Categories
Home > Documents > infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited...

infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited...

Date post: 05-Jun-2020
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
50
Surviving Stata Workshop infoguides.gmu.edu/software/stata dsc.gmu.edu/software Please open Stata 1
Transcript
Page 1: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Surviving Stata Workshop

infoguides.gmu.edu/software/stata

dsc.gmu.edu/software

Please open Stata

1

Page 2: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Statistical SoftwareSPSS Stata

Easy to start, limited capability

Best for those with basic needs or who analyze experiments

Easy flexible syntax, extensible

Best for academics, especially in economics & public policy

R

Hard to learn, highly capable

Best for managing huge and/or complex data (govt, financial)

Improving, highly extensible

Best for those who program and are comfortable with data

Page 3: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Submitting Stata Commands1. Click in the Command Window 2. Type:

log using workshop.log

3. Press Enter

Page 4: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Stata Window

4

Results

Review

Single Click =

Put it back in

Command box

Variables

Command

Page 5: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Opening Files

5

Those participating in the workshop will be provided the data file.

The following instructions enable others to get and open the file.

Page 6: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Getting the Data

1. Register for an account at https://www.pewsocialtrends.org/profile/registration/

2. Download the datafile from:https://www.pewsocialtrends.org/2007/11/09/family-bonds-data/

3. Unzip the folder to a location you can find again

4. Open Stata

5. Paste or type the following inthe Command box; press Enter

net from http://radyakin.org/transfer/usespss/beta

net install usespss

usespss

6

Page 7: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Select the File

Press "Browse…"in the dialog box

Find and selectthe data file (.sav)

Press OK

7

Page 8: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Stata Vocabulary

8

log using workshop.log

use https://dsc.gmu.edu/files/pew.dtause https://dsc.gmu.edu/files/pew.dta

Page 9: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

9

use https://dsc.gmu.edu/files/pew.dta

Page 10: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Looking at Data

browse

Pew Research Center. (2007). Pew Social Trends [Data file]. Retrieved from

http://www.pewsocialtrends.org/category/datasets/?download=5753

10

Page 11: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

browse

11

Responses to one question(variable)

Responses from one person(observation)

A single response (value)

Page 12: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

12

Navigating Variables

Double-Click

Type "see"

Page 13: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Values

13

Numbers

Strings

Numbers with Labels

Page 14: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

14

Variables

Numbers:byteintlongfloatdouble

Page 15: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Interface & Windows

Close the browse window

15

Page 16: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Main Window

16

Variables

Properties

codebook

Page 17: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Results

17

ResultsReview

Single Click =

Put in Command

box

Double Click =

Put in box &

Press Enter

Page 18: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

codebook pvote04a

Single Click =

Put in Command

type "vote" to find pvote04a& double click

Using the Windows

Page 19: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

codebook pvote04a age

Single Click =

Put in Command

Using the Windows

Page 20: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Interpreting the Codebook

20

#1: Black, Red, or Blue?

Storage Type

Label Assigned

#2: Category or Measure?

# of Unique Values

# of Values Labeled

#3: Missing Values?

True Missing

Researcher

#1

#2

#3

Page 21: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Other Variable Types

21

Black:Numeric,

no label

Red:String

Page 22: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Syntax Structure

22

Page 23: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

command varlist qualifiers, options

histogram age

tabulate age

label list AGE

generate yrborn = 2005 - age

histogram yrborn if (age < 99), normal

Syntax

23

, normal width(1)

if (age < 99)

Page 24: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

order burger if (price < 3), plain mustard

order burger, meat(2) cheese(American)

order burger if (place != "Carls Jr"), nomayo

order burger if (price < 3), plain mustard

order burger, meat(2) cheese(American)

order burger if (place != "Carls Jr"), nomayo

Structure

24

Page 25: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Abbreviations

histogram age, normal width(1)

hist age, norm w(1)

tabulate yrborn

tab yrborn

tab yrb

ta y

25

Wildcards? = One* = Multiple

Page 26: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Keeping Track

26

Page 27: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Do Files & Logs

27

Review≈

Do File

Results≈

Log File

Page 28: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Menu Bar

28

Browse& Edit

Do Files

Logsbegin/close

More/Break

Graphsuse names to have multiple windows

Variables Manageredit labels & properties

Viewerhelp & smcl logs

Page 29: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Log File Types

.log

Unformatted Log

Open in Notepad

.smcl

Formatted Log

Requires Stata

29

Page 30: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

30

.smcl

.log

Page 31: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Do- Files

31

1. Select syntax2. Press Ctrl-D

(D for Do)

**************** Make Comments* with asterisks***************

Page 32: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

32

.do file in

Do File Editor

.do file in

Notepad

Page 33: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Using help

33

Page 34: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Why Use Syntax?

34

log cd use save clear drop keep

recode encode generate egen replace rename

tabulate summarize ttest logistic regress estimates

Most people do the same few things over and over again.

Page 35: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Getting to Help

35

help tabsumor help tab then click tabulate, summarize()

Page 36: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

The Help Viewer

36

help tabsumor help tab then click tabulate, summarize()

Page 37: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

must type

replace me

click here

not needed

Syntax

Underline Blue [Brackets] Italics

37

must type

replace me

click here

[not needed]

italics only

Page 38: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

generate [type] newvar[:lblname] =exp [if] [in]

generate newvar =exp

38

Simplifying Syntax

Page 39: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Practice with Options

help histogram

39

Page 40: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

More Options

40

Page 41: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

41

Quick Start - NEW!

Page 42: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

More on Syntax

42

Page 43: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Great Tutorial

43

https://www.ssc.wisc.edu/sscc/pubs/stat.htm

Page 44: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

44see the bottom of http://infoguides.gmu.edu/software/stata

Page 45: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Save & Close

45see the bottom of http://infoguides.gmu.edu/software/stata

Page 46: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Review

46

Page 47: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Review

What are the 4 parts of Stata Syntax, in order?

command varlist qualifiers, options

What do [brackets] mean in Stata Syntax Help?

not needed / optional element

What does italics mean in Stata Syntax Help?

replace with your own word(s) or value(s)

47

Page 48: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Syntax

command varlist qualifiers, options

command 1, 2, or 3 words specifying the task

varlist 0, 1, 2 or more variables

= exp A math or logical statement to set a value

if exp A logical statement to limit cases

, options A word or selector to alter the command

48

Page 49: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

Qualifiers

=exp expression (math or logical)generate yrborn = 2005 - agegenerate youth = ( age < 30 )

[if] logical statementhistogram age if ( age != 99 )replace youth = . if ( age == 99 )

[in] range of case numberstabulate pvote04a in 1/100

… names or labelslabel yrborn "Year of Birth"label list AGE

49

Logical Operators

| or

& and

== is equal to

!= not equal to

< less than

<= less than or equal to

Page 50: infoguides.gmu.edu/software/stata dsc.gmu.edu/software ...SPSS Stata Easy to start, limited capability Best for those with basic needs or who analyze experiments Easy flexible syntax,

EndFor these workshop slides:

https://dsc.gmu.edu/workshops/stata

For more resources on Stata:

https://infoguides.gmu.edu/software/stata

For help with 511:

https://infoguides.gmu.edu/statsclass

To provide feedback about this workshop:

https://dsc.gmu.edu/workshops/feedback

Debby Kermer [email protected]


Recommended