I need to do a lot of regression models (differing in weighting and what control variables are included) with four different independent variables. I also want to export the results to excel. For simplicity, lets just say I am interested in the coefficient and standard error of the coefficient:
I then need to put the coefficients and standard error of x2 in coloumn b, x3 goes in coloumn c and x4 goes in coloumn d. Writing:
...does not produce the desired result, because this loop does not change the coloumn, and similarly:
...just puts the results of x1 in different coloumns. I know I could just put the results of the other x'es in the rows below, but I need to do a lot of different models (e.g. 'reg y x1 z1', 'reg y x1 z2', 'reg y x1 z1 z2' and so on), and for analysis it would be very convenient to have the results of the different x'es in coloumns next to each other.
Is there a way where I can tell my loop to BOTH go from 1 to 2 AND a to b, and so forth every iteration? Or any other solution?
Code:
putexcel set results, sheet(reg) modify reg y x1 putexcel a1 = _b[x1] putexcel a2 = _se[x1]
Code:
putexcel set results, sheet(reg) modify
forval k = 1/4{
reg y x`k'
putexcel a1 = _b[x`k']
putexcel a2 = _se[x`k']
}
Code:
putexcel set results, sheet(reg) modify
foreach k = a b c d{
reg y x1
putexcel `k'1 = _b[x1]
putexcel `k'2 = _se[x1]
}
Is there a way where I can tell my loop to BOTH go from 1 to 2 AND a to b, and so forth every iteration? Or any other solution?

Comment