*! 06jul2012 by Chuck Huber // THIS PROGRAM RUNS THE ANALYSIS FOR THE 2012 SUGM IN SAN DIEGO clear set more off set seed 12345 use "Huber_2012SanDiego_Pilot.dta", clear // DATA CHECKING // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= // DESCRIBE AND SUMARIZE THE DATA describe id qu1_t1-qu20_t1 summ qu1_t1-qu20_t1 // TAB QUESTION 1 tab qu1_t1 // CREATE A TEMPORARY VARIABLE CALLED "one" FOR USE IN THE GRAPHS BELOW gen one = 1 // CREATE A SINGLE GRAPH OF QUESTION 1 local GraphTitle : variable label qu1_t1 graph hbar (count) one, over(qu1_t1) bar(1, fcolor(blue) lcolor(black)) /// title("Q1: My statistical software makes me...", size(medium) color(black) justification(left)) /// subtitle("`GraphTitle'", size(medium) color(black) justification(right)) /// ytitle(Number of Respondents) /// scheme(s1color) graph export .\graphs\Figure0.png, as(png) replace graph export .\graphs\Figure0.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure0.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // CREATE A SINGLE GRAPH OF QUESTION 2 local GraphTitle : variable label qu2_t1 graph hbar (count) one, over(qu2_t1) bar(1, fcolor(blue) lcolor(black)) /// title("Q2: My statistical software makes me...", size(medium) color(black) justification(left)) /// subtitle("`GraphTitle'", size(medium) color(black) justification(right)) /// ytitle(Number of Respondents) /// scheme(s1color) // GRAPH EACH OF QUESTIONS 1-20 FOR THE COMBO GRAPH forvalues i = 1(1)20 { local GraphTitle : variable label qu`i'_t1 graph hbar (count) one, over(qu`i'_t1, relabel(1 SD 2 D 3 N 4 A 5 SA)) bar(1, fcolor(blue) lcolor(black)) /// title("Q`i': `GraphTitle'", size(medsmall) color(black)) /// ytitle(" ") ylabel(0(10)60) ymtick(0(10)60) /// scheme(s1color) /// name(qu`i'_t1, replace) } // COMBINE THE GRAPHS OF EACH QUESTION INTO A SINGLE GRAPH graph combine qu1_t1 qu2_t1 qu3_t1 qu4_t1 qu5_t1 qu6_t1 qu7_t1 qu8_t1 qu9_t1 qu10_t1 /// qu11_t1 qu12_t1 qu13_t1 qu14_t1 qu15_t1 qu16_t1 qu17_t1 qu18_t1 qu19_t1 qu20_t1, /// rows(4) cols(5) /// title("My statistical software makes me...") /// subtitle(`"SD="Stongly Disagree", D="Disagree", N="Neutral", A="Agree", SA="Strongly Agree""', size(vsmall) color(black)) /// b1title(Number of Respondents) /// scheme(s1color) graph export .\graphs\Figure1.png, as(png) replace graph export .\graphs\Figure1.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure1.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // REMOVE THE "ONE" VARIABLE drop one // ITEM RESPONSE THEORY // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= use "Huber_2012SanDiego_Pilot.dta", clear drop qu*_t2 // CREATE DICHOTOMOUS VARIABLES FOR EACH QUESTION WHERE (1,2,3 = 0 AND 4,5 = 1) forvalues i = 1(1)20 { recode qu`i'_t1 (1/3=0 "No") (4/5=1 "Yes"), gen(qu`i'_t1_bin) local TempLabel : variable label qu`i'_t1 label var qu`i'_t1_bin "`TempLabel' (binary)" } tab qu1_t1 qu1_t1_bin // SUM THE 20 BINARY QUESTIONS egen TotalBinary = rowtotal(qu1_t1_bin - qu20_t1_bin) label var TotalBinary "Sum of all 20 binary question scores" // DISPLAY THE RESULTS FOR PERSON 1 disp "Responses for Participant #1 disp _dup(50) "-" forvalues i = 1(1)20 { local TempLabel : variable label qu`i'_t1_bin local TempResponse = qu`i'_t1_bin[1] disp "`TempLabel' = " _col(50) `TempResponse' } disp _dup(50) "-" local TempLabel : variable label TotalBinary disp "`TempLabel' = " _col(50) TotalBinary[1] // CREATE A CENTERED AND SCALED egen StdScore = std(TotalBinary) label var StdScore "TotalBinary centered and scaled to N(0,1)" // HISTOGRAM OF RAW TEST SCORES (SUM OF BINARY ITEMS) // =============================================================== histogram TotalBinary, fcolor(green) lcolor(black) lwidth(thin) lpattern(solid) /// normal normopts(lcolor(blue) lwidth(medium) lpattern(solid) connect(direct)) /// title("Distribution of the Total Test Scores") /// xtitle("Raw Sum of All Binary Items") /// scheme(s1color) graph export .\graphs\Figure2.png, as(png) replace graph export .\graphs\Figure2.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure2.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // HISTOGRAM OF STANDARDIZED TEST SCORES // ===================================== histogram StdScore, fcolor(green) lcolor(black) lwidth(thin) lpattern(solid) /// normal normopts(lcolor(blue) lwidth(medium) lpattern(solid) connect(direct)) /// title("Distribution of the Standardized Test Scores") /// xtitle("Standardized Sum of All Binary Items (Theta)") /// xscale(range(-3 3)) xlabel(-3(1)3) xmtick(-3(1)3) /// scheme(s1color) graph export .\graphs\Figure3.png, as(png) replace graph export .\graphs\Figure3.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure3.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // CREATE AN ITEM RESPONSE CURVE FOR QUESTION 1 // ============================================ logistic qu1_t1_bin StdScore predict p local GraphTitle : variable label qu1_t1 twoway (line p StdScore, sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)), /// title(Response Curve for Question 1) /// subtitle("`GraphTitle'", size(medsmall) color(black)) /// ytitle("P(Response=1 | Theta)") yscale(range(1 0)) ylabel(0(0.2)1) ymtick(0(0.2)1) /// xtitle("Standardized Test Score (Theta)") xscale(range(-3 3)) xlabel(-3(1)3) xmtick(-3(1)3) /// scheme(s1color) graph export .\graphs\Figure4.png, as(png) replace graph export .\graphs\Figure4.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure4.eps, as(eps) mag(160) logo(off) orientation(landscape) replace drop p // GRAPH EACH OF QUESTIONS 1-20 FOR THE COMBO GRAPH // ================================================ forvalues i = 1(1)20 { local GraphTitle : variable label qu`i'_t1 logistic qu`i'_t1_bin StdScore predict p twoway (line p StdScore, sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)), /// title("Q`i': `GraphTitle'", size(medsmall) color(black)) /// ytitle("") yscale(range(1 0)) ylabel(0(0.2)1) ymtick(0(0.2)1) /// xtitle("") xscale(range(-3 3)) xlabel(-3(1)3) xmtick(-3(1)3) /// scheme(s1color) /// name(qu`i'_t1, replace) drop p } // COMBINE THE GRAPHS OF EACH QUESTION INTO A SINGLE GRAPH // ======================================================= graph combine qu1_t1 qu2_t1 qu3_t1 qu4_t1 qu5_t1 qu6_t1 qu7_t1 qu8_t1 qu9_t1 qu10_t1 qu11_t1 qu12_t1 qu13_t1 qu14_t1 qu15_t1 qu16_t1 qu17_t1 qu18_t1 qu19_t1 qu20_t1, /// rows(4) cols(5) /// title("Response Curves") /// subtitle(`"My statistical software makes me..."', size(vsmall) color(black)) /// b1title("Standardized Test Score (Theta)") /// l1title("P(Response=1 | Theta)") /// scheme(s1color) /// saving(ItemCharacteristicCurves, replace) graph export .\graphs\Figure5.png, as(png) replace graph export .\graphs\Figure5.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure5.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // USING STATA TO FIT THE RASCH MODEL // http://www.stata.com/support/faqs/statistics/rasch-model/ // SET UP THE DATA FOR THE RASCH MODEL // =================================== list id qu1_t1_bin-qu10_t1_bin if id==1, nolabel reshape long qu@_t1_bin, i(id) j(question) list id question qu_t1_bin if id==1, nolab // We now have to generate the predictor variables for the thetas: forvalues num =1/20{ gen Delta`num' = -(question==`num') } * set format to compress the output of list format qu_t1_bin question Delta* %4.0f * sort within subj_id on the identifier item of the math problem. sort id question * invoke list with options that improve readability. list id qu_t1_bin question Delta1-Delta10 if id==1, nodisplay noobs nolabel list id qu_t1_bin question Delta* if id==2, nodisplay noobs nolabel // CHUCK NOTE: COULD DO THE SAME THING WITH -xtmelogit- xtmelogit qu_t1_bin Delta1-Delta20, noconstant || id:, covariance(independent) predict p // COMMAND TO DO THIS WITH "raschtest" BEFORE CONVERTING THE DATA TO LONG FORMAT // raschtestv7 qu1_t1_bin-qu20_t1_bin, method(mml) // raschtestv7 qu1_t1_bin-qu20_t1_bin, method(gee) // GRAPH THE PREDICTIONS FOR EACH QUESTION (NOTE THE "IF" IN THE GRAPH COMMAND) twoway (line p StdScore if question==1, sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)), /// title(Item Characteristic Curve for Question 1) /// ytitle("P(Response=1 | Theta)") yscale(range(1 0)) ylabel(0(0.2)1) ymtick(0(0.2)1) /// xtitle("Standardized Test Score (Theta)") xscale(range(-3 3)) xlabel(-3(1)3) xmtick(-3(1)3) /// scheme(s1color) graph export .\graphs\Figure6.png, as(png) replace graph export .\graphs\Figure6.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure6.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // GRAPH EACH OF QUESTIONS 1-20 FOR THE COMBO GRAPH // ================================================ forvalues i = 1(1)20 { local GraphTitle : variable label qu`i'_t1 twoway (line p StdScore if question==`i', sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)), /// title("Q`i': `GraphTitle'", size(medsmall) color(black)) /// ytitle("") yscale(range(1 0)) ylabel(0(0.2)1) ymtick(0(0.2)1) /// xtitle("") xscale(range(-3 3)) xlabel(-3(1)3) xmtick(-3(1)3) /// scheme(s1color) /// name(qu`i'_t1, replace) } // COMBINE THE GRAPHS OF EACH QUESTION INTO A SINGLE GRAPH // ======================================================= graph combine qu1_t1 qu2_t1 qu3_t1 qu4_t1 qu5_t1 qu6_t1 qu7_t1 qu8_t1 qu9_t1 qu10_t1 qu11_t1 qu12_t1 qu13_t1 qu14_t1 qu15_t1 qu16_t1 qu17_t1 qu18_t1 qu19_t1 qu20_t1, /// rows(4) cols(5) /// title("Item Characteristic Curves") /// subtitle(`"My statistical software makes me..."', size(vsmall) color(black)) /// b1title("Standardized Test Score (Theta)") /// l1title("P(Response=1 | Theta)") /// scheme(s1color) /// saving(ItemCharacteristicCurves_RaschModel, replace) graph export .\graphs\Figure7.png, as(png) replace graph export .\graphs\Figure7.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure7.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // MENTION "opentirt" BY TRISTAN TZAJONC // ======================================== // help openirt // net install http://www.people.fas.harvard.edu/~tzajonc/stata/openirt/openirt // http://www.people.fas.harvard.edu/~tzajonc/openirt.html // RELIABILITY // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= // INTRACLASS CORRELATION COEFFICIENT // ================================== use "Huber_2012SanDiego_Pilot.dta", clear // HOW CORRELATED IS THE FIRST TEST WITH THE SECOND TEST? canon (qu1_t1-qu20_t1) (qu1_t2-qu20_t2), lc(1) rename TotalScore TotalScore_t1 list id qu1_t1 qu1_t2 qu2_t1 qu2_t2 qu3_t1 qu3_t2 in 1/5, nolabel // RESHAPE THE DATA SO THAT THE ICC CAN BE COMPUTED // ================================================ reshape long qu1_t qu2_t qu3_t qu4_t qu5_t qu6_t qu7_t qu8_t qu9_t qu10_t /// qu11_t qu12_t qu13_t qu14_t qu15_t qu16_t qu17_t qu18_t qu19_t qu20_t, i(id) j(time) sort id time list id time qu1_t qu2_t qu3_t qu4_t qu5_t qu6_t in 1/6, sepby(id) nolabel // COULD COMPUTE THIS MANUALLY USING xtmixed: xtmixed qu1_t, || id:, covariance(independent) variance estat icc disp .346975 / (.346975 + .415) icc qu1_t id time forvalues i = 1(1)20 { quietly icc qu`i'_t id time di as text "The ICC for Question `i' = " _col(30) as result %5.4f r(icc_i) } //icc TotalScore_t id time // SPLIT-HALF AND THE SPEARMAN-BROWN FORMULA // ========================================= use "Huber_2012SanDiego_Pilot.dta", clear egen TotalEven = rowtotal(qu2_t1 qu4_t1 qu6_t1 qu8_t1 qu10_t1 qu12_t1 qu14_t1 qu16_t1 qu18_t1 qu20_t1) egen TotalOdd = rowtotal(qu1_t1 qu3_t1 qu5_t1 qu7_t1 qu9_t1 qu11_t1 qu13_t1 qu15_t1 qu17_t1 qu19_t1) corr TotalEven TotalOdd local sbpf = 2*r(rho) / (1+r(rho)) disp "The Spearman-Brown Prophesy Reliability Estimate = " as result %5.4f `sbpf' // CHECK CHRONBACH'S ALPHA FOR THE ENTIRE GROUP OF QUESTIONS // ========================================================= alpha qu1_t1-qu20_t1 alpha qu1_t1-qu20_t1, std item // VALIDITY // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= // INTER-RATER AGREEMENT // ========================================= use "Huber_2012SanDiego_Pilot.dta", clear // KAPPA STATISTIC // =============== // Also, two prerecorded weights are available. // wgt(w) specifies weights 1-|i-j|/(k-1), where i and j index the rows and // columns of the ratings by the two raters and k is the maximum number of possible ratings. // wgt(w2) specifies weights 1 - {(i-j)/(k-1)}^2. replace DrLector = 1 if id<10 & DrCrane<3 tab DrLector DrCrane tab DrLector DrCrane, missing kap DrLector DrCrane, tab kapwgt MyWeight 1 \ .8 1 \ 0 0 1 \ 0 0 .8 1 // (define matrix) kapwgt MyWeight kap DrLector DrCrane, wgt(MyWeight) kap DrLector DrCrane, tab wgt(w) kap DrLector DrCrane, tab wgt(w) tab qu1_t1 qu1_t2 corr qu1_t1 qu1_t2 kap qu1_t1 qu1_t2 // POINT-BISERIAL CORRELATION // =========================== // use "Huber_2012SanDiego_Pilot.dta", clear drop diagnosis label drop diagnosis tab DrLector DrCrane gen diagnosis = 0 replace diagnosis = 1 if DrLector>=3 | DrCrane>=3 label var diagnosis "Diagnosis based on Drs Lector and Crane" label define diagnosis 0 "NotDepressed" 1 "Depressed" label values diagnosis diagnosis tab qu1_t1 diagnosis, all exact // ANDERSON'S POINT-BISERIAL CORRELATION COMMAND: // pbis diagnosis qu1_t1 // FROM PAGE 149 OF "A GENTLE INTRODUCTION TO STATA" BY ALAN ACOCK ttest qu1_t1, by(diagnosis) local rsquared = (r(t)^2) / ((r(t)^2)+r(df_t)) // disp as text "The R-Squared based on the t-test = " as result %5.4f `rsquared' disp as text "The Point-Biserial Correlation based on the t-test = " as result %5.4f sqrt(`rsquared') // WE COULD JUST COMPUTE THIS DIRECTLY IN STATA WITH THE REGRESS COMMAND: regress qu1_t1 diagnosis disp "The R-Squared based on regress = `e(r2)'" local pointbs = sqrt(e(r2)) disp as text "The Point-Biserial Correlation coefficient = " as result %5.4f `pointbs' // TETRACHORIC CORRELATION COEFFICIENT // =================================== // CREATE DICHOTOMOUS VARIABLES FOR EACH QUESTION WHERE (1,2,3 = 0 AND 4,5 = 1) forvalues i = 1(1)20 { forvalues j = 1(1)2 { recode qu`i'_t`j' (1/3=0 "NotDepressed") (4/5=1 "Depressed"), gen(qu`i'_t`j'_bin) label var qu`i'_t`j'_bin "Question `i', Time `j' Coded as Binary" } } tab qu1_t1_bin diagnosis // COMPUTE THE TETRACHORIC CORRELATION COEFFICIENT BETWEEN THE BINARY VARIABLES: tetrachoric qu1_t1_bin diagnosis // WHICH IS EQUIVALENT TO THE BIVARIATE PROBIT MODEL WITHOUT PREDICTOR VARIABLES: biprobit qu1_t1_bin diagnosis // COMPUTE THE PEARSON CORRELATION BETWEEN THE CONTINUOUS VARIABLES: corr qu1_t1 qu1_t2 // COMPUTE THE PEARSON CORRELATION BETWEEN THE BINARY VARIABLES: corr qu1_t1_bin qu1_t2_bin disp _col(4) "Question" _col(20) "Pearson" _col(30) "Biserial" _col(40) "Tetrachoric" disp _dup(60) "-" forvalues i = 1(1)20 { quietly corr qu`i'_t1 diagnosis local pearson = r(rho) quietly regress qu`i'_t1 diagnosis local pointbs = sqrt(e(r2)) quietly tetrachoric qu`i'_t1_bin diagnosis local tetra = r(rho) disp _col(4) "Question `i'" _col(20) %5.4f `pearson' _col(30) %5.4f `pointbs' _col(40) %5.4f `tetra' } // CALCULATE BASIC SUMMARY STATISTICS, CORRELATIONS AND CHECK NORMALITY // ============================================================================= tabstat qu1_t1-qu20_t1, columns(statistics) stat(n min max median mean sd) tabstat qu1_t1-qu20_t1, columns(statistics) stat(p5 p10 p25 p50 p75 p90 p95) // TABLES AND TESTS OF ASSOCIATION tab qu1_t1 qu2_t1, all exact // CREATE SCATTERPLOT MATRICES FOR THE QUESTIONS: // ================================================ // QUESTIONS 1-5 WITH NO JITTER graph matrix qu1_t1-qu5_t1, mfcolor(blue) mlcolor(blue) jitter(0) jitterseed(1234) /// title(My statistical software makes me...) scheme(s1color) graph export .\graphs\Figure8.png, as(png) replace graph export .\graphs\Figure8.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure8.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // QUESTIONS 1-5 WITH SOME JITTER graph matrix qu1_t1-qu5_t1, mfcolor(blue) mlcolor(blue) jitter(1) jitterseed(1234) /// title(My statistical software makes me...) scheme(s1color) graph export .\graphs\Figure9.png, as(png) replace graph export .\graphs\Figure9.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure9.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // QUESTIONS 1-10 graph matrix qu1_t1-qu10_t1, mfcolor(blue) mlcolor(blue) jitter(1) jitterseed(1234) /// title(My statistical software makes me...) scheme(s1color) graph export .\graphs\Figure10.png, as(png) replace graph export .\graphs\Figure10.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure10.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // QUESTOINS 11-20 graph matrix qu11_t1-qu20_t1, mfcolor(blue) mlcolor(blue) jitter(1) jitterseed(1234) /// title(My statistical software makes me...) scheme(s1color) graph export .\graphs\Figure11.png, as(png) replace graph export .\graphs\Figure11.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure11.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // QUESTIONS 1-20 graph matrix qu1_t1-qu20_t1, mfcolor(blue) mlcolor(blue) jitter(1) jitterseed(1234) /// title(My statistical software makes me...) scheme(s1color) graph export .\graphs\Figure12.png, as(png) replace graph export .\graphs\Figure12.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure12.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // SPEARMAN CORRELATION COEFFICIENT // =================================== quietly spearman qu1_t1-qu20_t1 matrix list r(Rho), format(%4.2f) nonames noheader spearman qu11_t1-qu20_t1 // KENDALL'S TAU-A RANK CORRELATION COEFFICIENT // =================================== quietly ktau qu1_t1-qu20_t1, stats(taua) matrix list r(Tau_a), format(%4.2f) nonames noheader // KENDALL'S TAU-B RANK CORRELATION COEFFICIENT // =================================== quietly ktau qu1_t1-qu20_t1, stats(taub) matrix list r(Tau_b), format(%4.2f) nonames noheader // COVARIANCE // ========== quietly corr qu1_t1-qu20_t1, cov means matrix list r(C), format(%4.2f) nonames noheader // PEARSON CORRELATION COEFFICIENTS // ================================ quietly corr qu1_t1-qu20_t1 matrix list r(C), format(%4.2f) nonames noheader // UNIVARIATE TESTS OF NORMALITY swilk qu1_t1-qu20_t1 sfrancia qu1_t1-qu20_t1 // SKEWNESS-KURTOSIS TEST OF UNIVARIATE NORMALITY sktest qu1_t1-qu20_t1 // TESTS FOR MULTIVARIATE NORMALITY mvtest normality qu1_t1-qu20_t1, all // TEST THE SPHERICITY OF THE COVARIANCE MATRIX mvtest covariances qu1_t1-qu20_t1, spherical mvtest covariances qu1_t1-qu10_t1, spherical mvtest covariances qu10_t1-qu20_t1, spherical // Test that the correlation matrix is compound symmetric (that is, that all correlations are equal) mvtest correlations qu1_t1-qu20_t1, compound // Test that the covariance matrix is block diagonal corr qu1_t1-qu20_t1 matrix list r(C), format(%4.2f) nonames noheader mvtest covariances qu1_t1-qu20_t1, block(qu1_t1-qu10_t1 || qu11_t1-qu20_t1) // EXPLORATORY FACTOR ANALYSIS // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= use "Huber_2012SanDiego_Pilot.dta", clear // PEARSON CORRELATION COEFFICIENTS // ================================ quietly corr qu1_t1-qu20_t1 matrix QuesCorr = r(C) matrix list QuesCorr, format(%4.2f) nonames noheader // CHECK CHRONBACH'S ALPHA FOR THE ENTIRE GROUP OF QUESTIONS alpha qu1_t1-qu20_t1, std //alpha qu1_t1-qu20_t1, std item detail // SET CORRELATIONS EQUAL TO MISSING IF THEY ARE LESS THAN 0.2: quietly corr qu1_t1-qu20_t1 matrix QuesCorr = r(C) local MatDim = rowsof(QuesCorr) forvalues i = 1(1)`MatDim' { forvalues j = 1(1)`MatDim' { if QuesCorr[`i',`j'] < 0.2 { matrix QuesCorr[`i',`j'] = . } } } matrix list QuesCorr, format(%4.2f) nonames noheader // SET CORRELATIONS EQUAL TO MISSING IF THEY ARE LESS THAN 0.3: quietly corr qu1_t1-qu20_t1 matrix QuesCorr = r(C) local MatDim = rowsof(QuesCorr) forvalues i = 1(1)`MatDim' { forvalues j = 1(1)`MatDim' { if QuesCorr[`i',`j'] < 0.3 { matrix QuesCorr[`i',`j'] = . } } } matrix list QuesCorr, format(%4.2f) nonames noheader // SET CORRELATIONS EQUAL TO MISSING IF THEY ARE LESS THAN 0.4: quietly corr qu1_t1-qu20_t1 matrix QuesCorr = r(C) local MatDim = rowsof(QuesCorr) forvalues i = 1(1)`MatDim' { forvalues j = 1(1)`MatDim' { if QuesCorr[`i',`j'] < 0.4 { matrix QuesCorr[`i',`j'] = . } } } matrix list QuesCorr, format(%4.2f) nonames noheader // SET CORRELATIONS EQUAL TO MISSING IF THEY ARE LESS THAN 0.5: quietly corr qu1_t1-qu20_t1 matrix QuesCorr = r(C) local MatDim = rowsof(QuesCorr) forvalues i = 1(1)`MatDim' { forvalues j = 1(1)`MatDim' { if QuesCorr[`i',`j'] < 0.5 { matrix QuesCorr[`i',`j'] = . } } } matrix list QuesCorr, format(%4.2f) nonames noheader // FACTOR ANALYSIS RETAINING THE FIRST 10 FACTORS factor qu1_t1-qu20_t1, factors(10) ml nolog // CREATE A SCREE PLOT screeplot, mcolor(blue) msize(medium) msymbol(point) lcolor(blue) lwidth(thick) lpattern(solid) connect(direct) /// ylabel(0(1)8) ymtick(0(1)8) /// xlabel(0(1)20) xmtick(1(1)20) /// scheme(s1color) graph export .\graphs\Figure13.png, as(png) replace graph export .\graphs\Figure13.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure13.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // FACTOR ANALYSIS RETAINING ONLY FACTORS WITH AN EIGENVALUE >1 // THIS RULE IS DESCRIBED ON PAGE 32 OF BRUCE THOMPSON'S BOOK // IT IS DUE TO GUTTMAN (1954) BUT SOMETIMES MISTAKENLY CALLED THE "K1" RULE AFTER Kaiser factor qu1_t1-qu20_t1, mineigen(1) blanks(0.5) ml nolog // CALCULATE THE AIC AND BIC FOR EACH NUMBER OF FACTORS FROM 1-10: // NOTE THAT THE SMALLEST AIC IS AT 2 FACTORS estat factors factor qu1_t1-qu20_t1, factors(2) ml nolog // USE BRUCE THOMPSON'S "SEQUENTIAL FACTOR EXTRACTION" SELECTION METHOD (PAGES 22-23) factor qu1_t1-qu20_t1, factors(1) ml estat residuals // MANY RESIDUALS ARE NON-ZERO factor qu1_t1-qu20_t1, factors(2) ml estat residuals factor qu1_t1-qu20_t1, factors(3) ml estat residuals //factor qu1_t1-qu20_t1, factors(10) ml //matrix C = e(C) //matrix F1 = e(L) //matrix F1 = F1[1...,1] //matrix F1F1 = F1*F1' //matrix list F1F1 //matrix R = C - F1F1 //matrix list R // estat structure displays the factor structure, that is, the // correlations between the variables and the common factors. factor qu1_t1-qu20_t1, factors(2) ml nolog loadingplot, mcolor(blue) msize(medium) mlabsize(medium) mlabcolor(blue) scheme(s1color) graph export .\graphs\Figure14.png, as(png) replace graph export .\graphs\Figure14.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure14.eps, as(eps) mag(160) logo(off) orientation(landscape) replace estat structure // TRY A COUPLE OF ROTATIONS factor qu1_t1-qu20_t1, factors(2) ml loadingplot, mcolor(blue) msize(medium) mlabsize(medium) mlabcolor(blue) scheme(s1color) graph export .\graphs\Figure15.png, as(png) replace graph export .\graphs\Figure15.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure15.eps, as(eps) mag(160) logo(off) orientation(landscape) replace rotate, varimax loadingplot, mcolor(blue) msize(medium) mlabsize(medium) mlabcolor(blue) scheme(s1color) graph export .\graphs\Figure16.png, as(png) replace graph export .\graphs\Figure16.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure16.eps, as(eps) mag(160) logo(off) orientation(landscape) replace rotate, promax loadingplot, mcolor(blue) msize(medium) mlabsize(medium) mlabcolor(blue) scheme(s1color) graph export .\graphs\Figure17.png, as(png) replace graph export .\graphs\Figure17.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure17.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // CREATE TWO VARIABLES FROM OUR FACTORS factor qu1_t1-qu20_t1, factors(2) ml rotate, promax predict Factor1 Factor2, regression corr Factor1 Factor2 // END OF PILOT DATA ANALYSIS // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= // BEGIN ANALYSIS OF FULL DATA // CONFIRMATORY FACTOR ANALYSIS // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= // USE THE DATASET FOR THE LARGE SAMPLE use Huber_2012SanDiego, clear describe summ // CONFIRMATORY FACTOR ANALYSIS USING SEM (BASED ON BOLLEN SLIDES) sem (Affective -> qu1-qu10) /// (Physical -> qu11-qu20), stand est store full // TEST THAT THE COVARIANCE BETWEEN THE LATENT VARIABLES IS ZERO: forced by cov(...@0) sem (Affective -> qu1-qu10) /// (Physical -> qu11-qu20), /// cov(Affective*Physical@0) stand estat scoretests est store reduced lrtest full reduced // THE COVARIANCE IS DEFINITELY NOT ZERO // CONFIRMATORY FACTOR ANALYSIS USING SEM (BASED ON BOLLEN SLIDES) sem (Affective -> qu1-qu10) /// (Physical -> qu11-qu20), stand est store full estat gof, stats(all) estat eqgof estat mindices // CREATE VARIABLES FOR THE LATENT VARIABLES predict F1 F2, latent(Affective Physical) label var F1 "Factor 1 (Affective)" label var F2 "Factor 2 (Physical)" // SUMMARY AND CORRELATION tabstat F1 F2, columns(statistics) stat(n min max median mean sd) corr F1 F2 // UNIVARIATE TESTS OF NORMALITY sktest F1 F2 // TESTS FOR MULTIVARIATE NORMALITY mvtest normality F1 F2, all // EXAMINE F1 AND F2 BY SEX // ============================================================================================================================= ttest F1, by(sex) graph box F1, over(sex) /// box(1, fcolor(green) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(green) msize(small) msymbol(circle)) /// title(Factor 1 by Sex, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure18.png, as(png) replace graph export .\graphs\Figure18.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure18.eps, as(eps) mag(160) logo(off) orientation(landscape) replace ttest F2, by(sex) graph box F2, over(sex) /// box(1, fcolor(blue) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(blue) msize(small) msymbol(circle)) /// title(Factor 2 by Sex, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure19.png, as(png) replace graph export .\graphs\Figure19.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure19.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // HOTELLING'S T-SQUARED hotelling F1 F2, by(sex) graph box F1 F2, over(sex) /// box(1, fcolor(green) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// box(2, fcolor(blue) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(green) msize(small) msymbol(circle)) /// marker(2, mcolor(blue) msize(small) msymbol(circle)) /// title(Factors 1 and 2 by Sex, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1 and Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure20.png, as(png) replace graph export .\graphs\Figure20.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure20.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // EXAMINE F1 AND F2 BY RACE // ============================================================================================================================= anova F1 race graph box F1, over(race) /// box(1, fcolor(green) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(green) msize(small) msymbol(circle)) /// title(Factor 1 by Race, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure21.png, as(png) replace graph export .\graphs\Figure21.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure21.eps, as(eps) mag(160) logo(off) orientation(landscape) replace anova F2 race graph box F2, over(race) /// box(1, fcolor(blue) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(blue) msize(small) msymbol(circle)) /// title(Factor 2 by Race, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure22.png, as(png) replace graph export .\graphs\Figure22.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure22.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // MANOVA manova F1 F2 = race graph box F1 F2, over(race) /// box(1, fcolor(green) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// box(2, fcolor(blue) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(green) msize(small) msymbol(circle)) /// marker(2, mcolor(blue) msize(small) msymbol(circle)) /// title(Factors 1 and 2 by Race, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1 and Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure23.png, as(png) replace graph export .\graphs\Figure23.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure23.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // USE SOME BUILT-IN CONTRASTS: // ============================== // r. differences from a reference (base) level; the default contrast r.race // WHICH IS EQUIVALENT TO: contrast {race -1 1 0} /// {race -1 0 1}, equation(F1) contrast r.race, equation(F2) // a. differences from the next level (adjacent contrasts) contrast a.race contrast {race 1 -1 0} /// {race 0 1 -1}, equation(F1) // ar. differences from the previous level (reverse adjacent contrasts) contrast a.race contrast {race -1 1 0} /// {race 0 -1 1}, equation(F1) // g. differences from the balanced grand mean contrast g.race contrast {race -0.6666 0.3333 0.3333} /// {race 0.3333 -0.6666 0.3333} /// {race 0.3333 0.3333 -0.6666}, equation(F1) // h. differences from the balanced mean of subsequent levels (Helmert contrasts) contrast h.race contrast {race -1 0.5 0.5} /// {race 0 1.0 -1.0}, equation(F1) // j. differences from the balanced mean of previous levels (reverse Helmert contrasts) contrast j.race contrast {race -1.0 1.0 0} /// {race -0.5 -0.5 1}, equation(F1) // p. orthogonal polynomial in the level values contrast p.race // q. orthogonal polynomial in the level sequence contrast q.race // PAIRWISE MEANS USING TUKEY pwcompare race, equation(F1) effects mcompare(tukey) pwcompare race, equation(F2) effects mcompare(tukey) // PAIRWISE MEANS USING BONFERRONI pwcompare race, equation(F1) effects mcompare(bonf) // PAIRWISE MEANS USING STUDENT-NEWMAN-KEULS' METHOD: pwcompare race, equation(F1) effects mcompare(snk) // EXAMINE F1 AND F2 BY AGE // ============================================================================================================================= regress F1 age predict pred_F1, xb label var pred_F1 "Predicted F1" twoway (scatter F1 age, sort mcolor(green) msize(small) msymbol(circle) mfcolor(green) mlcolor(green) mlwidth(medium)) /// (line pred_F1 age, sort lcolor(green) lwidth(thick) lpattern(solid) connect(direct)) , /// title(Factor 1 by Age, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// xtitle("Age (years)") xscale(range(20 60)) xlabel(20(10)60) xmtick(20(10)60) /// ytitle(Factor 1) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure24.png, as(png) replace graph export .\graphs\Figure24.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure24.eps, as(eps) mag(160) logo(off) orientation(landscape) replace drop pred_F1 regress F2 age predict pred_F2, xb label var pred_F2 "Predicted F2" twoway (scatter F2 age, sort mcolor(blue) msize(small) msymbol(circle) mfcolor(blue) mlcolor(blue)) /// (line pred_F2 age, sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)) , /// title(Factors 1 and 2 by Age, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1 and Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure25.png, as(png) replace graph export .\graphs\Figure25.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure25.eps, as(eps) mag(160) logo(off) orientation(landscape) replace drop pred_F2 // MULTIVARIATE REGRESSION mvreg F1 F2 = age predict pred_F1, xb equation(F1) predict pred_F2, xb equation(F2) label var pred_F1 "Predicted F1" label var pred_F2 "Predicted F2" twoway (scatter F1 age, sort mcolor(green) msize(vsmall) msymbol(circle) mfcolor(green) mlcolor(green) mlwidth(medium)) /// (scatter F2 age, sort mcolor(blue) msize(vsmall) msymbol(circle) mfcolor(blue) mlcolor(blue)) /// (line pred_F1 age, sort lcolor(green) lwidth(thick) lpattern(solid) connect(direct)) /// (line pred_F2 age, sort lcolor(blue) lwidth(thick) lpattern(solid) connect(direct)) , /// title(Factors 1 and 2 by Age, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1 and Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure26.png, as(png) replace graph export .\graphs\Figure26.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure26.eps, as(eps) mag(160) logo(off) orientation(landscape) replace drop pred_F1 drop pred_F2 // BOXPLOTS, MANOVA, MVREG, CONTRASTS, PWCOMPARE, MARGINS AND MARGINSPLOT // ========================================================================================================= // /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ // ========================================================================================================= * BOXPLOTS, MANOVA, CONTRASTS, MARGINS AND MARGINSPLOT FOR SEX AND RACE * ======================================================================================================================================= table sex race, c(mean F1 mean F2) format(%9.3f) center graph box F1 F2, over(sex) over(race) /// box(1, fcolor(green) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// box(2, fcolor(blue) fintensity(inten100) lcolor(black) lwidth(thin) lpattern(solid)) /// marker(1, mcolor(green) msize(small) msymbol(circle)) /// marker(2, mcolor(blue) msize(small) msymbol(circle)) /// title(Factors 1 and 2 by Race and Sex, size(medlarge) color(black) position(12) orientation(horizontal) margin(small)) /// ytitle(Factor 1 and Factor 2) ytitle(, size(medium) color(black) orientation(vertical) margin(small)) /// ylabel(, labels labsize(small) labcolor(black) angle(horizontal) format(%9.0g) labgap(small)) /// yscale(range(-2.5 2.5)) ylab(-2.5(.5)2.5 , angle(horizontal) grid gmax gmin glwidth(vvvthin) glcolor(black) glpattern(solid) nogextend) /// legend(cols(2) size(medsmall) color(black) position(12)) /// scheme(s1color) graph export .\graphs\Figure27.png, as(png) replace graph export .\graphs\Figure27.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure27.eps, as(eps) mag(160) logo(off) orientation(landscape) replace // MANOVA manova F1 F2 = sex##race contrast sex##race margins i.race##i.sex, predict(equation(F1)) margins , over(race sex) predict(equation(F1)) marginsplot graph export .\graphs\Figure28.png, as(png) replace graph export .\graphs\Figure28.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure28.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins i.sex##i.race, predict(equation(F2)) marginsplot graph export .\graphs\Figure29.png, as(png) replace graph export .\graphs\Figure29.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure29.eps, as(eps) mag(160) logo(off) orientation(landscape) replace * MVREG, CONTRASTS, PWCOMPARE, MARGINS AND MARGINSPLOT FOR AGE, SEX AND RACE * ======================================================================================================================================= table sex race, c(mean F1 mean F2) format(%9.3f) center mvreg F1 F2 = age i.sex##i.race margins , at(age=(20(10)60)) predict(equation(F1)) vsquish marginsplot, scheme(s1color) graph export .\graphs\Figure30.png, as(png) replace graph export .\graphs\Figure30.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure30.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish marginsplot, scheme(s1color) graph export .\graphs\Figure31.png, as(png) replace graph export .\graphs\Figure31.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure31.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish // MARGINS OVER SEX AND AGE margins , over(sex) at(age=(20(10)60)) predict(equation(F1)) marginsplot, legend(cols(2) size(medsmall) position(12)) scheme(s1color) graph export .\graphs\Figure32.png, as(png) replace graph export .\graphs\Figure32.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure32.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish // MARGINAL EFFECTS OF SEX OVER AGE margins , at(age=(20(10)60)) predict(equation(F1)) dydx(sex) marginsplot, scheme(s1color) graph export .\graphs\Figure33.png, as(png) replace graph export .\graphs\Figure33.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure33.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish // MARGINS OVER RACE AND AGE margins , over(race) at(age=(20(10)60)) predict(equation(F1)) marginsplot, legend(cols(3) position(12)) scheme(s1color) // MARGINAL EFFECTS OF RACE OVER AGE margins , at(age=(20(10)60)) predict(equation(F1)) dydx(race) marginsplot, legend(cols(2) position(12)) scheme(s1color) graph export .\graphs\Figure34.png, as(png) replace graph export .\graphs\Figure34.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure34.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish // MARGINS OVER SEX, RACE AND AGE margins , over(race sex) at(age=(20(10)60)) predict(equation(F1)) marginsplot, legend(cols(3) size(small) position(12)) scheme(s1color) graph export .\graphs\Figure35.png, as(png) replace graph export .\graphs\Figure35.ps, as(ps) mag(160) logo(off) orientation(landscape) replace graph export .\graphs\Figure35.eps, as(eps) mag(160) logo(off) orientation(landscape) replace margins , at(age=(20(10)60)) predict(equation(F2)) vsquish pwcompare sex pwcompare race, mcompare(tukey) pwcompare sex#race, mcompare(tukey) /* COMMENTS ON MULTIPLE COMPARISONS: noadjust do not adjust for multiple comparisons; the default bonferroni [adjustall] Bonferroni's method; adjust across all terms sidak [adjustall] Sidak's method; adjust across all terms scheffe Scheffe's method + tukey Tukey's method + snk Student-Newman-Keuls' method + duncan Duncan's method + dunnett Dunnett's method + tukey, snk, duncan, and dunnett are only allowed with results from anova, manova, regress, and mvreg. */ contrast sex#i.race // CUSTOM CONTRASTS contrast {sex#race -1 0 0 0 0 1}, noeffects equation(F1) contrast {sex#race -1 0 0 0 0 1}, noeffects equation(F2) tab sex race // COMPARE HISPANIC FEMALES TO WHITE FEMALES contrast {sex#race -1 0 1 /// 0 0 0}, noeffects asobserved // COMPARE HISPANIC FEMALES TO WHITE MALES contrast {sex#race -1 0 0 /// 0 0 1}, noeffects asobserved /* operators (op.) Description r. differences from a reference (base) level; the default a. differences from the next level (adjacent contrasts) ar. differences from the previous level (reverse adjacent contrasts) Asbalanced operators g. differences from the balanced grand mean h. differences from the balanced mean of subsequent levels (Helmert contrasts) j. differences from the balanced mean of previous levels (reverse Helmertccontrasts) p. orthogonal polynomial in the level values q. orthogonal polynomial in the level sequence Asobserved operators gw. differences from the observation-weighted grand mean hw. differences from the observation-weighted mean of subsequent levels jw. differences from the observation-weighted mean of previous levels pw. observation-weighted orthogonal polynomial in the level values qw. observation-weighted orthogonal polynomial in the level sequence Custom contrasts Description {A numlist} user-defined contrast on the levels of factor A {A#B numlist} user-defined contrast on the levels of the interaction between A and B Custom contrasts may be part of a term, such as {A numlist}#B, {A numlist}@B, {A numlist}|B, {A#B numlist}, and {A numlist}#{B numlist}. The same is true of higher-order custom contrasts, such as {A#B numlist}@C, {A#B numlist}#r.C, and {A#B numlist}#c.x. Higher-order interactions with at most eight factor variables are allowed with custom contrasts. */ // SEM Model // ============================================================================== tab race, gen(race) rename race1 Hispanic rename race2 Black rename race3 White sem (Affective -> qu1-qu10) (Physical -> qu11-qu20) /// (age -> Affective Physical) (sex -> Affective Physical) /// (Black -> Affective Physical) (Hispanic -> Affective Physical), /// latent(Affective Physical) cov(e.Affective*e.Physical) nocapslatent