240 likes | 505 Views
Biostat 201: Winter 11. Lab Session 3. SAS/STATA code key. I will use the following convention in these slides: statements : bold keywords : italics options : underlined Variables, or something you specify yourself : courier font . Assignment 3. What do we need to do?.
E N D
Biostat 201: Winter 11 Lab Session 3
SAS/STATA code key • I will use the following convention in these slides: • statements: bold • keywords: italics • options: underlined • Variables, or something you specify yourself: courier font
What do we need to do? • Please refer to the Section XII notes! • Wide versus Long Data • Import data • Descriptive statistics • Repeated Measures • VIA Factorial ANOVA • VIA regression
Wide vs long data Wide Long
How to change data from wide form to long form. SAS (one method) dataleadlong (drop = time0 time1 time4 time6); set lab.lead; lead=time0; time=0; output; lead=time1; time=1; output; lead=time4; time=4; output; lead=time6; time=6; output; label lead = "Blood Lead Level" time = "time" group= "Treatment"; run;
How to change data from wide form to long form. • SAS (another method) dataleadlong; set lab.lead; array y{4} time0 time1 time4 time6; i=0; do time=0, 1, 4, 6; i = i+1; lead=y{i}; output; end; label lead = "Blood Lead Level" time = "time" group= "Treatment"; drop i time0 time1 time4 time6; run;
How to change data from wide form to long form. • STATA reshape long time, i(id) j(t) rename time lead
SAS: Descriptive StatisticsNote: Data is in LONG FORM • proc meansdata=dataset<options>; class grpvar1grpvar2…; var var1var2…;run; • proc meansdata=lead_longmeanstdstderr; class group time; var lead;run;
STATA: Descriptive StatisticsNote: Data is in LONG FORM meanvar1var2…, over(grpvar1grpvar2…) meanlead, over(grouptime)
STATA: Repeated Measures via Factorial ANOVA anova yvargrp / sub|grptgrp#t,repeated(t) anova lead group /id|group time group#time, repeated(t) ** models means - version 11 only ** margins group#t, asbalanced emptycells(reweight) NOTE: Data needs to be in the LONG format.
SAS: Repeated Measures proc mixeddata=dataset;classgrptsub;modelyvar = grptgrp*t / s; repeated / subject=subtype=cs;lsmeans grp*t /diff; run; quit; proc mixed data = leadlong method = reml; class id group time; model lead = group time group*time / s ; repeated time / type=cs subject=id r rcorr ; lsmeans group*time /diff; run; NOTE: Data needs to be in the LONG format.
STATA: Repeated Measures Regression NOTE: Data needs to be in the LONG format. xtregyvargrptgrp#t, i(sub) • xtreg lead i.group i.time i.group#i.time, i(id) xtmixedyvar i.grpt i.grp#t || id:, • xtmixed lead i.group i.time i.group#i.time || id:
Estimates are different from SAS because the reference groups are different
Estimating the means(results same as SAS) • margins i.group#i.t
SAS: Repeated Measures via factorial ANOVA Note: Data needs to be in the WIDE format. • proc glmdata=dataset;classgrp ;modelyvar1 yvar2 .. yvarp =grp; repeated repeated-factor-name #of trials;run; quit; • procglm data =lead_wide; class group; model time0 time1 time4 time6 =group; repeated time 4; lsmeans group / out=means; run; quit