Difference between random effetcs and dummy coding of a categorical variable I'm a bit confused with the definition of random effects and why it couldn't be rephrased in terms of dummy coding of a categorical variable.
Assume the model is linear with one dependent variable $Y$ and two independent variables:


*

*a continuous variable $A$ (playing the role of a fixed effect variable)

*a categorical variable $B$ with possible values $1,2,3$. $B$ is typically the population the person belongs to.


Dummy coding ($B_i$ means $1_{B=i}$) in linear regression is writing:


*

*$Y=\alpha+\beta A+\gamma_2 B_2 + \gamma_3 B_3+\epsilon$ 

*or $Y=\beta A+\gamma_1 B_1+ \gamma_2 B_2 + \gamma_1 B_3+\epsilon$


How does it differ from a mixed model where $A$ would be a fixed effect and $B$ a random effect? Is it that, unlike dummy coding, the variance of the noise is allowed to vary with $B$?
 A: Fixed effects work mainly through the mean but random effects work mainly through the variance.  In particular fixed effects are non-random whereas random effects are random variables with mean 0.
Means
The means of the models are different so the models are not the same.  Suppose that $Y_i$ is in group 2. Then for the fixed effects model we have:
$E(Y_i) = A_i\beta + \gamma_2$
but for the mixed effect model we have the following since the mean of the $\gamma$ variables is 0 by assumption.
$E(Y_i) = A_i\beta$
so the means are different and so they cannot be the same model.
Variances
Also the covariances between two Y's in the same group are different.
If $Y_i$ and $Y_j$ are observations such that $i$ and $j$ are not equal, i.e. they are for different observations, and both are in group 2, say, then for fixed effects we must have zero covariance since the assumption is that all observations are independent.
$cov(Y_i, Y_j) = 0$
Now consider the mixed effects case. For simplicity let us assume $A$ is $0$.  Then we can expand the covariance as shown below and using bilinearity of the covariance and that all distinct terms are independent and have mean $0$ by assumption the cross terms vanish and we are left with the variance shown:
$cov(Y_i, Y_j) = cov(\gamma_2 + \epsilon_i, \gamma_2 + \epsilon_j) = var({\gamma}_2) > 0$
Thus the models are not the same.  The covariance between two distinct Y's in group 2 is 0 for the fixed effect model but is positive for the mixed effects model.
A: You have probably long moved past this, but I figured I would clarify what the difference is between categorical variables for fixed and random effects. To keep things simple, I'll use less mathematical names for the equations so its more straight forward. A normal regression with a categorical predictor would look like the following:
$\text{Y} = \text{Fixed Intercept} + \text{Categorical Predictor} + \text{Error}$
For our example, we can make a model predicting the influence of occupation on average income, expressed so:
$\text{Income} = \text{Grand Mean of Income} + \text{Change in Grand Mean Due to Occupation} + \text{Error}$
This equation assumes that the fixed effect of categories predicts a grand mean. So conditional upon whatever the category is, the "y" here should equal the mean outcome plus or minus whatever fixed effects are in the equation. If the reference criterion for occupation is a janitor and their average income is 40k USD, it would be used as the fixed intercept, and every other dummy coding of occupation would add the fixed effect on the grand mean based off each multiplication of the dummy code.
Random effects models, depending on how they're formulated, add an additional layer with random effect intercepts and random effect slopes. I will just use random intercepts as an example. If we are interested in occupation as a fixed effect but we aren't interested in the corporation they work for, this may be a good time to use it as a random effect (which by the way should almost always be categorical). We would simply add the random intercepts, or conditional grand means, of each corporation to the model.
$ \begin{aligned}
\text{Income} = \text{Grand Mean of Income} + \text{Occupation} + \text{Error}
\\ \text{+/- Change in Grand Mean from Corporation 1}
\\ \text{+/- Change in Grand Mean from Corporation 2}
\\ \text{+/- Change in Grand Mean from Corporation ..}
\end{aligned}
$
This essentially accomplishes the major goal in separating the equation into two separate parts. One part is a predictable fixed effect that you can estimate independent from the random effects. The other part is the actual random effect which you can look at to see how much "noise" it brings if it were to be added back into the fixed effect equation. The selection of a categorical predictor is therefore theoretical...its important to know why you think it predicts an outcome or if it is just unnecessarily confounding your estimate.
