---
title: "Elementary Path Models in Stata"
author: "Doug Hemken"
date: "October 2015"
---
    ```{r setup, echo=FALSE, message=FALSE}
source("../StataMDsetup.r")
```
# Elementary Path Models
[Stata notes](../stata.html)

We follow Kline (2011) in specifying models with two and three
observed variables and direct effects among the variables.

With two observed variables we have two means and three
variance/covariances.
With three observed variables we have three means and six
variance/covariances.  Keeping track of how many
\"observations\" (pieces of information) we start with
is helpful in understanding when a model is *saturated*.

## Bivariate Regression (\"Single Cause\")
Continuing with our example data.

In our model output we will see one mean (\"x2 <- _cons\"), one variance
(the error variance, \"var(e.x2\"), and one regression path
(\"x2 <- x1\").  Not shown in our output are the mean and variance
of the exogenous variable, x1. Having used all our degrees of
freedom, this model is saturated:  it perfectly predicts the
observed covariance matrix and the observed means.

```{r bivariate, collectcode=TRUE}
infile x1-x3 using "Z:\PUBLIC_WEB\MPlus\Basics\Sample stats\ex3.1.dat"
sem (x1 -> x2)
```

A similar example, but note here the parameter estimates are
not significant - x2 does *not* predict x3.  (But in terms of
overall model fit, this is still an example of a saturated model.)

```{r bivariate-notsig}
sem (x2 -> x3)
```

## Multiple Regression (\"Correlated Causes\")
Here x1 and x3 are correlated exogenous variables.
```{r multireg}
sem (x1 x3 -> x2)
```

We note that this is also a saturated model.  Although the output
only reports three parameters related to the variance/covariances,
three more are assumed among the exogenous variables, x1 and x3:
we have two more variances and a covariance.  They are not reported
because they are assumed to be equal to the observed values, that
is, they are part of the model but they are not estimated.

If we want variances, covariances, and means of exogenous variables
to be reported, we must ask for them.

```{r multireg-all}
sem (x1 x3 -> x2), variance(x1 x3) covariance(x1*x3) means(x1 x3)
```

As a shortcut, it is possible to ask for any one of the variance/covariances
and any one of the means, and all will be reported.

Notice that the keywords `variance` and `covariance` are singular, never
plural, and are often abreviated as `var` and `cov`.  Another potentially
confusing shortcut is that `var` and `cov` may be used interchangeably,
that is, a model could specify `var(x1*x2)` or `cov(x1)`.  The only
abreviation for `means` is `mean`.

## Multiple Outcomes (Multiple Response)
This model is *not* saturated, we have three variances and two
regression paths.
```{r multiout}
sem (x1 -> x2 x3)
```

A saturated version of this model would have correlated error terms.
```{r multiout-corr}
sem (x1 -> x2 x3), cov(e.x2*e.x3)
```

## Indirect Effects
This model, with both direct effects and an indirect effect, is saturated.
```{r multistage}
sem (x1 -> x2 x3)(x2 -> x3)
```

Previous: [Covariance models](Covmodel.html)
Next: [Confirmatory Factor Analysis](CFA.html)
```{r cleanup, engine="R", echo=FALSE}
    unlink("profile.do")
```