1 / 39

Stata Intro Mixed Models

Stata Intro Mixed Models. Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/. Why Stata. Pro Aimed at epidemiology Many methods, growing Graphics Structured, Programmable Coming soon to a course near you Con Memory>file size Copy tables. Use. Interface.

virote
Télécharger la présentation

Stata Intro Mixed Models

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 Intro Mixed Models Hein Stigum Presentation, data and programs at: http://folk.uio.no/heins/

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

  3. Use

  4. Interface H.S.

  5. Do Editor • New • Ctrl-8, or: • Run • Mark commands, Ctrl-D to do (execute) H.S.

  6. Do-file example H.S.

  7. Syntax • Syntax [bysort varlist:] command [varlist] [if exp] [in range][, opts] • Examples • mean age • mean age if sex==1 • bysort sex: summarize age • summarize age ,detail H.S.

  8. Data handling

  9. Import data • Using SPSS 14.0 • Save as, Stata Version 8 SE H.S.

  10. Use and save data • Open data • set memory 200m • use “C:\Course\Myfile.dta”, clear • Describe • describe describe all variables • list x1 x2 in 1/20 list obs nr 1 to 20 • Save data • save “C:\Course\Myfile.dta” ,replace H.S.

  11. Age square generate ageSqr=age^2 Young/Old generate old=0 if (age<=50) replace old=1 if (age>50) Observation numbers gen id=_n gen lag=age[ _n-1] Alternatives generate old=(age>50) generate old=(age>50) if age<. Generate, replace H.S.

  12. Missing • Obs!!! • Missing values are large numbers • age>30 will include missing. • age>30 & age<. will not. • Test • replace x=0 if (x==.) • Remove • drop if age==. • Change • replace educ=. if educ==99 H.S.

  13. Calculater • Display • dis 26/3 • dis exp(1.2) • Store results • scalar se=sqrt( 0.8*(1-0.8)/60 ) • dis se H.S.

  14. Help • General • help command • findit keyword search Stata+net • Examples • help table • findit aflogit H.S.

  15. Summing up • Use do files • Mark, Ctrl-D to do (execute) • Syntax • command [varlist] [if exp] [in range] [, options] • Missing • age>30 & age<. • generate old=(age>50) if age<. • Help • help describe H.S.

  16. Books Web: http://www.stata.com/bookstore A Gentle Introduction to Stata by Alan C. Acock A visual guide to Stata graphics by M.N. Mitchell Multilevel and longitudinal modeling using Stata by S. Rabe-Hesketh, A. Skrondal H.S.

  17. Graphics

  18. Twoway density • Syntax • graph twoway (plot1, opts) (plot2, opts), opts • One plot • kdensity x • Two plots, boys and girls compared twoway ( kdensity weight if sex==1, lcolor(blue) ) /// ( kdensity weight if sex==2, lcolor(red) ) H.S.

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

  20. Twoway scatter • Syntax • graph twoway (plot1, opts) (plot2, opts), opts • Examples • scatter y x • twoway (scatter y x) (lfit y x) Fitlines with CI H.S.

  21. twoway (scatter weight gest)(lfitci weight gest) H.S.

  22. Descriptives H.S.

  23. Central tendency and dispersion Mean and standard deviation: Mean with confidence interval: H.S.

  24. Frequency and proportion Frequency: Proportion with CI: H.S.

  25. equal proportions? Crosstables Are boys bullied as much as girls? H.S.

  26. Tables for epidemiologists • Data • Must be 0/1 • Long format. Wide format • Commands • cc Case-control • mcc Matched case-control • Example • cc disease exposed, by(sex) Stratified MH-OR • Calculator (i=immideate) • cci 10 90 5 95 OR H.S.

  27. Logistic regression Being bullied H.S.

  28. Syntax • Estimation • logistic y x1 x2 logistic regression • xi: logistic y x1 i.c1 categorical c1 • Post estimation • predict yf, pr predict probability • Manage models • estimates store m1 save model • est table m1, eform show OR H.S.

  29. Bivariate, dummies Generate dummies gen Island= (country==2) if country<. gen Norway= (country==3) gen Finland= (country==4) gen Denmark= (country==5) H.S.

  30. Model 1: outcome and exposure Alternative commands: xi:logistic bullied i.country use xi: i.var for categorical variables xi:logistic bullied i.country , coef coefs instead of OR's xi:logistic bullied i.country if sex!=. & age!=. do if sex and age not missing H.S.

  31. Estimate associations: m1=m2 Predict: m2 best Model 2: Add confounders H.S.

  32. Model 3: interaction lincom age+1*agesex effect of age for boys lincom age+2*agesex effect of age for girls H.S.

  33. Regression Summary • Estimation • regress y x1 x2 linear regression • logistic y x1 x2 logistic regression • xi:regress y x1 i.x2 categorical x2 • Manage results • estimates store m1 store results • estimates table m1 m2 table of results • estimates stats m1 m2 statistics of results • Post estimation • predict y, xb linear prediction • predict res, resid residuals • lincom b0+2*b3 linear combination • Help • help logistic postestimation H.S.

  34. Mixed ModelsMultilevel modelsPanel dataRepeated measurements Jun-14 H.S. H.S. 34

  35. Long and wide data Wide data reshape wide bp, i(id) j(occ) reshape long bp, i(id) j(occ) Long data H.S.

  36. Correlated measures • Two measures per person: W1 W2 symmetry W1 W2 Measure the same? • Matched Case-Control mcc expCase expContr Matched OR

  37. Multilevel data • Panel data • xt xsectional time data • help xt

  38. Setup and describe • Set panel data • xtset school pupils nested in schools • xtset id time times nested in subjects • Describe panel data • xtdes describe data and missing • xtsum bp summarize bloodpressure • xttab ht tabulate hypertension • xtline bp plot bp versus time for each id • Lag and lead • replace bp=bp[ _n+1] if id==1 H.S.

  39. Logistic regression methods • Fixed effects models • logit y x1 x2, or • Conditional fixed effects models • clogit y x1 x2, group(id) or • Random intercept models • xtlogit y x1 x2, i(id) or • Mixed effects models • xtmelogit y x1 x2 || id: x1 , or • Population average effects • xtgee y x1 x2, i(id) t(time) fam(bin) link(logit) robust eform H.S.

More Related