On Wed, 7 Sep 2016, Gmail wrote: > I've got a big issue to solve. I must implement an event study on a sample > of 100 firms. > > In order to avoid to implement 100 regressions I try to use a loop: > > "list ylist = 1 3 5 7 9 \ > > 11 13 15 17 19 \ [...] > 191 193 195 > > > > list xlist = 2 4 6 8 \ > > 10 12 14 16 18 \ > > 20 22 24 26 28 \ [...] > 190 192 194 196 > > loop foreach i ylist --progressive > loop foreach j xlist --progressive > ols ylist.$i const xlist.$j > genr alpha = $coeff(0) > genr beta = $coeff(xlist.$j) > store vectors.gdt alpha beta > endloop > endloop > > open vectors.gdt > > ylist and xlist are the lists that contain my independent variables. > > Unfortunately, such code regress the first dependent variable on the other > 100, then the second on the same 100 and so on and so forth. > > How I can write a loop that only regress the variable 1 on the variable 2, > the variable 3 on the 4 etc? > > How I can store the coefficients?
Something like this: <hansl> scalar N = 100 # adjust as needed matrix B = zeros(N, 2) loop k=1..N --quiet j = 2*k i = j-1 list L = i 0 j ols L --quiet B[k,] = $coeff' endloop print B </hansl> The matrix B will hold the coeff vectors as rows. Allin Cottrell