Stata Introduction, Short v2

1 / 32

# Stata Introduction, Short v2 - PowerPoint PPT Presentation

Stata Introduction, Short v2. Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/ courses. Nov-14. H.S. 1. Stata introduction. General use Interface and menu Do-files and syntax Data handling Analysis Descriptive Graphs Bivariate. Why Stata. Pro

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'Stata Introduction, Short v2' - amos-baker

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### Stata Introduction, Shortv2

Hein Stigum

Presentation, data and programs at:

http://folk.uio.no/heins/

courses

Nov-14

H.S.

H.S.

1

Stata introduction
• General use
• Interface and menu
• Do-files and syntax
• Data handling
• Analysis
• Descriptive
• Graphs
• Bivariate

H.S.

Why Stata
• Pro
• Aimed at epidemiology
• Many methods, growing
• Graphics
• Structured, Programmable
• Coming soon to a course near you
• Con
• Memory>file size

Nov-14

H.S.

H.S.

3

### Interface

Interface Stata 9

Nov-14

H.S.

H.S.

5

Interface Stata 12

Do

file

Data

edit

H.S.

Nov-14

H.S.

H.S.

7

Do-file example

New do-file: icon or Ctrl-9

Run: Mark, Ctrl-D

Nov-14

H.S.

H.S.

8

Syntax
• Syntax

[bysort varlist:] command [varlist] [if exp] [in range][, opts]

• Examples
• meanage
• meanageif sex==1
• bysort sex: summarizeage
• summarizeage,detail

Nov-14

H.S.

H.S.

9

### Data handling

Import data
• Using SPSS 14.0-17.0
• Save as, Stata Version 8 SE

Nov-14

H.S.

H.S.

11

Use and save data
• Open data
• use “C:\Course\Myfile.dta”, clear
• Describe
• describe describe all variables
• listx1 x2 in 1/20 list obs nr 1 to 20
• Save data
• save “C:\Course\Myfile.dta” ,replace

Nov-14

H.S.

H.S.

12

Use data from web
• webuse “file” use data from Stata homepage
• webuse set “http://www.med.uio.no/forskning/doktorgrad-karriere/forskerutdanning/kurs/biostatistikk/mf9510-logistisk-regresjon-overlevelsesanalyse-cox/”

set homepage

• webuse “birth1” data for exercise 1

Nov-14

H.S.

H.S.

13

Index

generate index=0

replaceindex=1 if sex==1 & age<30

Young/Old

generate old=(age>50)

Serial numbers, lags

generate id=_n

generate age1=age[ _n-1]

Generate, replace

if age<.

Nov-14

H.S.

H.S.

14

Dates
• From numeric to date

ex: m=12, d=2, y=1987

generatebirth=mdy(m,d,y)

formatbirth %td

• From string to date

ex: bstr=“01.12.1987”

generatebirth=date(bstr,”DMY”)

formatbirth %td

Nov-14

H.S.

H.S.

15

Missing
• Obs!!!
• Represented as ”.”
• Missing values are large numbers
• age>30 will include missing.
• age>30 if age<. will not.
• Test
• replace age=0 if (age==.)
• Remove
• drop if age==.
• Change
• replace educ=. if educ==99

Nov-14

H.S.

H.S.

16

Summarize variables

Missing in tables

Describe missing

summarize id bullied sex

tab bullied sex, missing

misstable summarize bullied sex new command

Nov-14

H.S.

H.S.

17

Help
• General
• helpcommand
• finditkeyword search Stata+net
• Examples
• help table
• findit aflogit

Nov-14

H.S.

H.S.

18

Summing up
• Use do files
• Run: Mark, Ctrl-D
• Syntax
• command [varlist] [if exp] [in range] [, options]
• Missing
• age>30 if age<.
• generateold=(age>50) if age<.
• Help
• help describe

Nov-14

H.S.

H.S.

19

### Descriptive

Descriptive
• Continuous

summarize weight

summarize weight, details fractiles ++

• Categorical

tabulate bullied

tabulate bullied,nolab show coding

H.S.

Other descriptives

tabstatmAge, stat( N min p50 mean max) by(parity)

Nov-14

H.S.

H.S.

22

### Graphics

H.S.

Twoway plots
• Syntax
• twoway (plot1, opts) (plot2, opts), opts
• One plot
• kdensity bw
• scatter bw gest

Nov-14

H.S.

H.S.

24

twoway ( kdensitybwif sex==1, lcolor(blue) ) ///

• ( kdensitybwif sex==2, lcolor(red ) )

Nov-14

H.S.

H.S.

25

line fit

scatter

twoway(scatterbw gest) (fpfitcibw gest) (lfitbw gest)

smooth with CI

Nov-14

H.S.

H.S.

26

Titles

scatterbw gest, title("title") subtitle("subtitle") ///

xtitle("xtitle") ytitle("ytitle") note("note")

Nov-14

H.S.

H.S.

27

### Bivariate analysis

2 independent samples

Do boys and girls have the same mean birth weight?

• twoway ( kdensity weight if sex==1, lcolor(blue) ) ///
• ( kdensity weight if sex==2, lcolor(red) )

Equal means?

Equal variance?

Nov-14

H.S.

H.S.

29

2 independent samples test

ttest weight, by(sex) 2-sample T-test

ttest weight, by(sex) unequal

ttest w1 w2, paired

Nov-14

H.S.

H.S.

30

equal proportions?

Crosstables

Are boys bullied as much as girls?

tabulate bullied sex, col chi2 nofreq

Nov-14

H.S.

H.S.

31

Summing up

Descriptive

summarizeweight

tabulatesex

Graphs

twoway (plot1, opts) (plot2, opts), opts

Bivariate

ttest weight, by(sex)

tabulatebullied sex, chi2

Nov-14

H.S.

H.S.

32