/************ syntax 11.2 ************/ /************************************************************* Power Analysis: sampsi -- Sample size and power determination *************************************************************/ /***Example 1: one-sample test of proportion***/ sampsi .5 .35, power(.8) onesample /*the default alpha is .05*/ sampsi .5 .35,n(20) onesample /***Example 2: two-sample test of proportion***/ sampsi .3 .2, alpha(.05) power(.8) sampsi .3 .2,n1(300) n2(250) alpha(.01) /***Example 3: one-sample test of mean***/ sampsi 0 -10,sd(6) a(.01) onesided p(.95) onesample sampsi 0 -10,sd(6) a(.01) onesided n(10) onesample /***Example 4: two-sample test of mean***/ sysuse auto,clear bysort foreign:sum weight sampsi 2300 3300,sd1(430) sd2(700) r(2) p(.99) sampsi 2300 3300,sd1(430) sd2(700) n1(10) n2(10) /***chi-square test of independence***/ sysuse auto,clear gen mpg1=mpg>21.3 tab mpg1 foreign,chi2 /****** ANOVA ******/ /***one-way ANOVA***/ sysuse auto,clear oneway mpg foreign anova mpg foreign anova mpg foreign price weight anova mpg foreign price weight,cont(price weight) anova mpg foreign price weight,cont(price weight) reg reg mpg foreign price weight /***How to plot ANOVA cell means in Stata***/ use http://www.ats.ucla.edu/stat/stata/faq/crf24,clear anova y a b a*b predict yhat sort a b graph twoway scatter yhat b, connect(L) /***or***/ net install gr0009.pkg anovaplot b a anovaplot b a,scatter(msym(i)) /***use option "scatter(ms(i))" to suppress plotting of response data***/ /***How to do ANOVA contrasts in Stata?***/ net install anovacontrast.pkg sysuse auto,clear keep if rep78>2&rep78<. /***anovacontrast gives incorrect and misleading results if there are missing or empty cells***/ anova mpg rep78 table rep78,contents(mean mpg) anovacontrast rep78, values(-1 0 1) /***group 1 versus group 3***values(numlist) specifies the weights for the contrast and is not optional***/ anovacontrast rep78, values(0 -1 1) /***group 2 versus group 3***/ anovacontrast rep78, values(-1 1 0) /***group 1 versus group 2***/