--- title: "Latent Variables - CFA" author: "Doug Hemken" date: "October 2015" --- ```{r setup, echo=FALSE, message=FALSE} source("../StataMDsetup.r") ``` # Confirmatory Factor Analysis Suppose we want to estimate this model: ![CFA](CFA_files/CFA.png) ```{r cfa, collectcode=TRUE} use "U:\Stata\Stata SEM\hsdata.dta" sem (Verbal -> general paragraph sentence wordc wordm) ``` Note that Verbal is a latent variable, it does not appear in our data set. The capitalization here is important - it tells Stata that this is a latent variable, and not some kind of mistake! Without capitalization, Stata thinks `verbal` is just a variable that is somehow missing from the data, a mistake. ```{r nocaps} sem (verbal -> general paragraph sentence wordc wordm) ``` Ordinarily, Stata will assume that variable names that begin with capitalization represent latent variables, while lower-case names represent variables that should be in our data set. If there are manifest variables with capitalized names, we can turn off this interpretation with a `nocapslatent` option. If we do this, then any latent variable will have to be declared with a `latent()` option, and this is also how we can have uncapitalized latent variable names. ```{r lower-latent} sem (verbal -> general paragraph sentence wordc wordm), latent(verbal) ``` ## Identifying Constraints ```{r moveanchor} sem (Verbal -> general paragraph@1 sentence wordc wordm) ``` ```{r varanchor} sem (Verbal -> general paragraph sentence wordc wordm), var(Verbal@1) ``` ```{r cleanup, engine="R", echo=FALSE} unlink("profile.do") ```