/****************************************************************************** Factor Analysis and Structural Equation Modeling Session cfa_seminar_2016.do Written by Hun Myoung Park Created on 11/27/2014 Last modified on 02/20/2016 ******************************************************************************/ version 13 set more off cd /Users/kucc625/Downloads infile privtown govtresp compete homosex abortion euthanas using values_full.dat, clear save values_full, replace //################################################# //Exploratory Factor Analysis //################################################# sum * pwcorr privtown-euthanas, sig //factor * factor privtown-euthanas loadingplot screeplot rotate, varimax //rotate, varimax factor(2) // draw a loading plot loadingplot screeplot // compare rotated and unrotated results estat rotatecompare // obtain factor score predict factor1 factor2 sum factor1 factor2 // obtain factor-based score egen f1 = rowmean(privtown govtresp compete) egen f2 = rowmean(homosex abortion euthanas) sum factor1 f1 factor2 f2 // obtain Chronbach Alpha for test reliability alpha privtown govtresp compete, asis item std alpha homosex abortion euthanas, asis item std // compare OLS with factor scores and factor-based scores regress factor1 factor2 regress f1 f2 //################################################# //Confirmatory Factor Analsysis (CFA) //################################################# // *** first model with one factor sem (Values -> privtown govtresp compete homosex abortion euthanas), method(ml) //sem (Values -> privtown govtresp compete homosex abortion euthanas), method(mlmv) // obtain standardized coefficients sem, standardized // obtain R2 estat eqgof // obtain goodness-of-fit measures estat gof, stats(all) // obtain modification indices estat mindices // *** second model with two factors sem (Economic -> privtown govtresp compete) (Morals -> homosex abortion euthanas), method(ml) cov(Economic*Morals) //sem (Economic -> privtown govtresp compete) (Morals -> homosex abortion euthanas), method(mlmv) cov(Economic*Morals) // obtain standardized coefficients sem, standardized // obtain R2 estat eqgof // obtain goodness-of-fit measures estat gof, stats(all) // obtain modification indices estat mindices // *** third model with two factors modified 1 sem (Economic -> privtown govtresp compete) (Morals -> homosex abortion euthanas govtresp), method(ml) cov(Economic*Morals) // obtain standardized coefficients sem, standardized // obtain R2 estat eqgof // obtain goodness-of-fit measures estat gof, stats(all) // obtain modification indices estat mindices // *** third model with two factors modified 2 sem (Economic -> privtown govtresp compete) /// (Morals -> homosex abortion euthanas govtresp), /// method(ml) cov(Economic*Morals e.privtown*e.compete e.govtresp*e.homosex) // obtain standardized coefficients sem, standardized // obtain R2 estat eqgof // obtain goodness-of-fit measures estat gof, stats(all) // obtain modification indices estat mindices // Identify missing values foreach var of varlist privtown-euthanas { replace `var' = . if `var'==-1 } sum privtown-euthanas pwcorr privtown-euthanas, sig // With missing values correction sem (Economic -> privtown govtresp compete) /// (Morals -> homosex abortion euthanas govtresp), /// method(mlmv) cov(Economic*Morals) standardized // obtain standardized coefficients sem, standardized // obtain R2 estat eqgof // obtain goodness-of-fit measures estat gof, stats(all) // obtain modification indices estat mindices /* Some useful commands sem, standardized estat eqgof estat gof, stats(all) estat summarize estat eqtest estat vce, cov estat vce, corr estat residuals estat stdize estat scoretest estat teffects, standardized estat framework, fitted estat mindices */