# Standard error for coefficient on dummy with no variation

Say I have a dummy variable $$X$$ (e.g., gender) and that units are divided into groups. I want to compute the average value of $$X$$ in each group. To achieve this, we can estimate the following linear model via OLS:

$$X_i = \sum_{g = 1}^G Group_{i, g} \, \beta_g + \epsilon$$

with $$Group_{i, g}$$ a dummy variable equal to one if the $$i$$-th unit belongs to the $$g$$-th group, and $$G$$ the number of groups. One can show that $$\beta_g$$ corresponds to the mean of $$X$$ in the $$g$$-th group. So, the advantage of this approach consists of getting standard errors for the average values in each group.

Suppose that my $$X$$ has no variation in one of the groups, and assume that this happens for the first group without loss of generality. Is this a problem for my linear model? The point estimate should be fine, but what about the standard error? Can I interpret it conventionally, i.e., measuring the sampling uncertainty of my estimated coefficient? I am getting a hard time thinking about this, though I may be simply overthinking. How should I think about this sampling uncertainty, if there is no variation of $$X$$ in the first group?

Follows a toy example to make the point, where I code $$X$$ as x2 and $$Groups$$ as groups:

## Generate data.
set.seed(1986)

n <- 1000

groups <- factor(sample(c(1, 2, 3), n, replace = TRUE))

x1 <- rnorm(n)
x2 <- rbinom(n, size = 1, prob = ifelse(groups == 1, 0, 0.5))

dta <- data.frame(x1, x2, groups)

## Dummy variable is always 0 in the first group.
sd(x2[groups == 1])
#> [1] 0

## Regressing x2 on groups to get group means and standard errors.
model <- lm(x2 ~ 0 + groups, data = dta)
summary(model)
#>
#> Call:
#> lm(formula = x2 ~ 0 + groups, data = dta)
#>
#> Residuals:
#>     Min      1Q  Median      3Q     Max
#> -0.5000 -0.4414  0.0000  0.5000  0.5586
#>
#> Coefficients:
#>         Estimate Std. Error t value Pr(>|t|)
#> groups1  0.00000    0.02174    0.00        1
#> groups2  0.50000    0.02251   22.22   <2e-16 ***
#> groups3  0.44144    0.02213   19.95   <2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> Residual standard error: 0.4039 on 997 degrees of freedom
#> Multiple R-squared:  0.4721, Adjusted R-squared:  0.4705
#> F-statistic: 297.1 on 3 and 997 DF,  p-value: < 2.2e-16

• Why did you include x1, betas, and y in this example if you are only asking about x2 and groups? Just want to make sure I'm interpreting your question correctly and that those are indeed extraneous.
– Noah
Commented Nov 11, 2022 at 6:01
• Oh, you are right. I just adapted an old example I had. I will edit the question. Commented Nov 11, 2022 at 10:08

There is a violation of the assumption of homoscedasticity required for the usual OLS standard errors to be valid. It is violated in two ways: for the groups other than 1, homoscedasticity is always violated for binary outcomes. For group 1, the residual variance is 0, which is different from the residual variances of the other two groups. If you use a heteroscedasticity-consistent standard error, the lack of variability in group 1 becomes apparent and invalidates any inferences:

> lmtest::coeftest(model, vcov = sandwich::vcovHC)

t test of coefficients:

Estimate Std. Error t value  Pr(>|t|)
groups1 0.000000   0.000000     NaN       NaN
groups2 0.500000   0.027951  17.889 < 2.2e-16 ***
groups3 0.441441   0.027293  16.174 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


The standard error is 0, so the t-statistic cannot be computed, which is what you would expect.

• Is the inference invalidate only for the first group? Commented Nov 11, 2022 at 10:12
• @PlasticMan Using a HC SE makes the inferences for the other two groups valid. It should be about the same as if you had simple not included group 1 in the analysis.
– Noah
Commented Nov 11, 2022 at 19:06