The below code is try to regress Y1 on x and then Y1 and x and a control. and then the same for another Y2. I then collect everything in outreg2 hoping that the fist results doesnt overwrite the second. I can't get the code to work although it seems to me to be doing it job. Any ideas? Thanks.
clear
set obs 50
* Generate independent variables x1, x2, and control variable c
* Here we use a random normal distribution for illustration
gen x1 = rnormal()
gen x2 = rnormal()
gen c = rnormal()
* Generate dependent variables y1 and y2
* We create some arbitrary linear relationships with random noise
gen y1 = 2 * x1 + 3 * c + rnormal()
gen y2 = -1.5 * x2 + 2 * c + rnormal()
* Define the two sets of independent variables
// local xvars x1 x2
* Define the control variable
// local control c
* Loop over each set of independent variables for Y1
foreach x in x1 x2 {
* Run regression of Y1 on `x`
reg y1 `x'
outreg2 using Y1_table.tex, replace(`x' == x1) ctitle(`x') tex addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
* Run regression of Y1 on `x` and `control`
reg y1 `x' c
outreg2 using Y1_table , append ctitle(`x'_`control') addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
}
* Now repeat the process for Y2
foreach x in x1 x2 {
* Run regression of Y2 on `x`
reg y2 `x`
outreg2 using Y2_table, replace(`x' == "x1") ctitle(`x') addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
* Run regression of Y2 on `x` and `control`
reg y2 `x' c
outreg2 using Y2_table, append ctitle(`x'_`control') addstat(N, r2)
}
clear
set obs 50
* Generate independent variables x1, x2, and control variable c
* Here we use a random normal distribution for illustration
gen x1 = rnormal()
gen x2 = rnormal()
gen c = rnormal()
* Generate dependent variables y1 and y2
* We create some arbitrary linear relationships with random noise
gen y1 = 2 * x1 + 3 * c + rnormal()
gen y2 = -1.5 * x2 + 2 * c + rnormal()
* Define the two sets of independent variables
// local xvars x1 x2
* Define the control variable
// local control c
* Loop over each set of independent variables for Y1
foreach x in x1 x2 {
* Run regression of Y1 on `x`
reg y1 `x'
outreg2 using Y1_table.tex, replace(`x' == x1) ctitle(`x') tex addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
* Run regression of Y1 on `x` and `control`
reg y1 `x' c
outreg2 using Y1_table , append ctitle(`x'_`control') addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
}
* Now repeat the process for Y2
foreach x in x1 x2 {
* Run regression of Y2 on `x`
reg y2 `x`
outreg2 using Y2_table, replace(`x' == "x1") ctitle(`x') addstat(R^2, e(r2), Radj^2, e(r2_a), Log Lik, e(ll), RMSE, e(rmse))
* Run regression of Y2 on `x` and `control`
reg y2 `x' c
outreg2 using Y2_table, append ctitle(`x'_`control') addstat(N, r2)
}
Comment