Following the empirical example in Duflo, Dupas, and Kremer (2011), we are interested in estimating the following regression model \[
Y_{ij} = \alpha T_j + \boldsymbol X'_{ij} \boldsymbol \beta + e_{ij} \quad i = 1, \ldots, n_j \quad j = 1, \ldots, J,
\tag{1}\] where \(Y_{ij}\) is the test score of student \(i\) in school \(j\), \(T_j\) is a binary variable indicating whether or not school \(j\) was tracking, and \(\boldsymbol X'_{ij}\) is a \(d_x \times 1\) vector that includes a constant and other student and school control variables.
The schools record each student’s score on \(d_y\) separate sections of the test. Suppose we are interested in estimating separate regressions of the form in Equation 1 for each of these test scores. Let \(\boldsymbol Y_{ij} \equiv \begin{bmatrix} Y_{ij1}, \ldots, Y_{ijd_y} \end{bmatrix}'\) , \(\boldsymbol \alpha \equiv \begin{bmatrix} \alpha_1, \ldots, \alpha_{d_y} \end{bmatrix}'\), \(\mathbf{B} \equiv \begin{bmatrix} \beta_1', \ldots, \beta_{d_y}' \end{bmatrix}'\), \(\boldsymbol e_{ij} \equiv \begin{bmatrix} e_{ij1} \ldots, e_{ijd_y} \end{bmatrix}'\). Then we can write the system of \(d_y\) regressions as \[
\boldsymbol Y_{ij} = \boldsymbol \alpha T_j + \boldsymbol X'_{ij} \mathbf{B} + \boldsymbol e_{ij} \quad i = 1, \ldots, n_j \quad j = 1, \ldots, J.
\]
Code
* Load the dataglobaldata"~/Git/vigneshsomjit.github.io/hasen-econometrics-datasets/DDK2011"use"$data/DDK2011.dta", clear* Store variables in macroslocal outcomes wordscore sentscore letterscore spellscore additions_score substractions_score multiplications_scorelocal controls agetest girl bottomhalf etpteacher lowstreamlocal treatment tracking* Loop over outcomes foreachyoflocal outcomes { * Store inverse ofSDof control groupquietlysum`y'if`treatment' == 0localscale = 1/r(sd) * Estimate the regression and scale the coefficientquietlyreg`y'`treatment'`controls', vce(cluster schoolid)quietlylincom`treatment' * `scale' * Store the results local b = r(estimate)local se = r(se)local t = r(t)localp = r(p) * Append to matrixmatrixeffects = nullmat(effects) \ (`b', `se', `t', `p')}*Label matrixmatrixcolnameseffects = coef se t pmatrixrownameseffects = `outcomes'matrixlisteffects