# why is 2SLS with dummys the same as GLS on group means?

I'm reading Mostly Harmless Econometrics (Available here), and on page 100 they say that 2SLS with dummy instruments is the same as GLS on a set of group means. I don't understand why. From the previous chapters, I got how instrumental variables work in general, but im struggling to differentiate between the Wald Estimator, 2SLS and grouped data. My only explanation so far is that when you use a dummy instrument in the first stage regression, you basically group your second stage regressors according to the dummy first stage instruments. But i still dont get how this relates to group means. Can somebody help?

The first stage is a regression of endogenous $x$ on binary $d$, so everyone gets with $d=1$ gets the same $\hat x$, and everyone with $d=0$ gets the same $\hat x$. The two values of $\hat x$ will be different as long as the instrument $d$ is relevant.

The second stage is just a regression of $y$ on $\hat x$. This can be done in two ways. The usual way is to regress $y$ on $\hat x$ for the full sample. But you could also just calculate the mean of $y$ for each of the two values of $\hat x$ and do a weighted regression of that mean on $\hat x$, where the weights are number of observations in each of the two $\hat x$ groups. Weighted least squares is a type of GLS. In this case you just have two observations instead of $N$.

Here's an example showing this in Stata with a toy model:

. sysuse auto, clear
(1978 Automobile Data)

. ivreg2 price (mpg = i.foreign)

IV (2SLS) estimation
--------------------

Estimates efficient for homoskedasticity only
Statistics consistent for homoskedasticity only

Number of obs =       74
F(  1,    72) =     0.15
Prob > F      =   0.6987
Total (centered) SS     =  635065396.1                Centered R2   =  -0.1314
Total (uncentered) SS   =   3447834321                Uncentered R2 =   0.7916
Residual SS             =  718514120.5                Root MSE      =     3116

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg |   63.13609   160.2388     0.39   0.694    -250.9262    377.1984
_cons |   4820.629   3431.824     1.40   0.160    -1905.623    11546.88
------------------------------------------------------------------------------
Underidentification test (Anderson canon. corr. LM statistic):          11.452
Chi-sq(1) P-val =    0.0007
------------------------------------------------------------------------------
Weak identification test (Cragg-Donald Wald F statistic):               13.183
Stock-Yogo weak ID test critical values: 10% maximal IV size             16.38
15% maximal IV size              8.96
20% maximal IV size              6.66
25% maximal IV size              5.53
Source: Stock-Yogo (2005).  Reproduced by permission.
------------------------------------------------------------------------------
Sargan statistic (overidentification test of all instruments):           0.000
(equation exactly identified)
------------------------------------------------------------------------------
Instrumented:         mpg
Excluded instruments: 1.foreign
------------------------------------------------------------------------------

. /* First Stage */
. qui reg mpg i.foreign

. predict double mpg_hat
(option xb assumed; fitted values)

. tab mpg_hat

Fitted |
values |      Freq.     Percent        Cum.
------------+-----------------------------------
19.82692 |         52       70.27       70.27
24.77273 |         22       29.73      100.00
------------+-----------------------------------
Total |         74      100.00

. /* Second Stage */
. reg price mpg_hat

Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(1, 72)        =      0.17
Model |  1507382.66         1  1507382.66   Prob > F        =    0.6802
Residual |   633558013        72  8799416.85   R-squared       =    0.0024
Total |   635065396        73  8699525.97   Root MSE        =    2966.4

------------------------------------------------------------------------------
price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg_hat |   63.13609   152.5432     0.41   0.680    -240.9532    367.2254
_cons |   4820.629   3267.008     1.48   0.144    -1692.032    11333.29
------------------------------------------------------------------------------

. /* Second Stage with WLS/GLS */
. collapse (mean) mean_price = price (count) N = headroom, by(mpg_hat)

. reg mean_price mpg_hat [fweight = N]

Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(1, 72)        =         .
Model |  1507383.12         1  1507383.12   Prob > F        =         .
Residual |           0        72           0   R-squared       =    1.0000
Total |  1507383.12        73  20649.0838   Root MSE        =         0

------------------------------------------------------------------------------
mean_price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg_hat |    63.1361          .        .       .            .           .
_cons |   4820.628          .        .       .            .           .
------------------------------------------------------------------------------


The second regression is just WLS/GLS on this data:

  mpg_hat   mean_price    N
19.826923      6,072.4   52
24.772727      6,384.7   22