1 / 32

Stata Introduction, Short v2

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

amos-baker
Download Presentation

Stata Introduction, Short v2

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Stata Introduction, Shortv2 Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/ courses Nov-14 H.S. H.S. 1

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

  3. 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

  4. Interface

  5. Interface Stata 9 Nov-14 H.S. H.S. 5

  6. Interface Stata 12 Do file Data edit H.S.

  7. Menu Nov-14 H.S. H.S. 7

  8. Do-file example New do-file: icon or Ctrl-9 Run: Mark, Ctrl-D Nov-14 H.S. H.S. 8

  9. 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

  10. Data handling

  11. Import data • Using SPSS 14.0-17.0 • Save as, Stata Version 8 SE Nov-14 H.S. H.S. 11

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. 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

  18. Help • General • helpcommand • finditkeyword search Stata+net • Examples • help table • findit aflogit Nov-14 H.S. H.S. 18

  19. 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

  20. Descriptive

  21. Descriptive • Continuous summarize weight summarize weight, details fractiles ++ • Categorical tabulate bullied tabulate bullied,nolab show coding H.S.

  22. Other descriptives tabstatmAge, stat( N min p50 mean max) by(parity) Nov-14 H.S. H.S. 22

  23. Graphics H.S.

  24. Twoway plots • Syntax • twoway (plot1, opts) (plot2, opts), opts • One plot • kdensity bw • scatter bw gest Nov-14 H.S. H.S. 24

  25. twoway ( kdensitybwif sex==1, lcolor(blue) ) /// • ( kdensitybwif sex==2, lcolor(red ) ) Nov-14 H.S. H.S. 25

  26. line fit scatter twoway(scatterbw gest) (fpfitcibw gest) (lfitbw gest) smooth with CI Nov-14 H.S. H.S. 26

  27. Titles scatterbw gest, title("title") subtitle("subtitle") /// xtitle("xtitle") ytitle("ytitle") note("note") Nov-14 H.S. H.S. 27

  28. Bivariate analysis

  29. 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

  30. 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

  31. equal proportions? Crosstables Are boys bullied as much as girls? tabulate bullied sex, col chi2 nofreq Nov-14 H.S. H.S. 31

  32. 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

More Related