Hi. In the code below, I run regressions for four outcome variables using five different sets of covariates for each. Basically 4 outcomes x 5 covariate lists = 20 regressions. All regressions include week fixed effects (i.weeknum).
I would the results to be:
1. exported to one excel file with a separate tab for each outcome variable
2. for the exported results to not include the week fixed effects. Including the week fixed effects in the exported output makes the five regressions per outcome variable in a single sheet incredibly messy, so I'd like to avoid this if possible.
Any guidance on how to do this would be great. Thank you!
I would the results to be:
1. exported to one excel file with a separate tab for each outcome variable
2. for the exported results to not include the week fixed effects. Including the week fixed effects in the exported output makes the five regressions per outcome variable in a single sheet incredibly messy, so I'd like to avoid this if possible.
Any guidance on how to do this would be great. Thank you!
Code:
* open data (start from merged data) use "${inputdir}\matching", clear *local for outcome variables local outcomes rate_con_avg7day rate_rec_avg7day rate_dec_avg7day *locals for covariates local varList1 "pop_perkm2_2019" local varList2 "pop_perkm2_2019 per60_2011" local varList3 "pop_perkm2_2019 per60_2011 exphealth_percap1516" local varList4 "pop_perkm2_2019 per60_2011 hospital_beds_total" #delimit ; local varList5 deathrate_2019 pop_perkm2_2019 projpercturban_2019 povertyperct per60_2011 hospital_total hospital_beds_total icu_beds_total ventilators_total exphealth_percap1516 malariacase2018 denguecase2018 typoidtot_case2018 acuteresp_totcase2018 pneumoniatot_case2018 tb2018 influenzacase_2018 hepcases_2018 mentalillness_2011 ; #delimit cr foreach var of local outcomes { forvalues j = 1/5 { qui reg `var' `varList`j'' i.weeknum esttab using "${paperdir}\Tables\basic reg.xls", replace } } *Data sample input str50 state float(rate_con_avg7day pop_perkm2_2019 per60_2011) byte weeknum "Andaman and Nicobar Islands" .0025188916 48.12704 6.7 3 "Andaman and Nicobar Islands" .024469234 48.12704 6.7 4 "Andaman and Nicobar Islands" .026268443 48.12704 6.7 5 "Andaman and Nicobar Islands" .02806765 48.12704 6.7 6 "Andaman and Nicobar Islands" .04713926 48.12704 6.7 7 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 8 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 9 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 10 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 11 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 12 "Andaman and Nicobar Islands" .08312342 48.12704 6.7 13 "Andaman and Nicobar Islands" .08780137 48.12704 6.7 14 "Andaman and Nicobar Islands" .10759266 48.12704 6.7 15 "Andaman and Nicobar Islands" .13637999 48.12704 6.7 16 "Andaman and Nicobar Islands" .2400144 48.12704 6.7 17 "Andaman and Nicobar Islands" .3573228 48.12704 6.7 18 "Andaman and Nicobar Islands" .4303707 48.12704 6.7 19 "Andaman and Nicobar Islands" .55055773 48.12704 6.7 20 "Andaman and Nicobar Islands" .9913638 48.12704 6.7 21 "Andaman and Nicobar Islands" 2.338971 48.12704 6.7 22 "Andaman and Nicobar Islands" 4.445124 48.12704 6.7 23 "Andaman and Nicobar Islands" 6.372796 48.12704 6.7 24 "Andaman and Nicobar Islands" 7.401943 48.12704 6.7 25 "Andaman and Nicobar Islands" 7.967974 48.12704 6.7 26 "Andaman and Nicobar Islands" 8.549838 48.12704 6.7 27 "Andaman and Nicobar Islands" 9.005398 48.12704 6.7 28 "Andaman and Nicobar Islands" 9.310543 48.12704 6.7 29 "Andaman and Nicobar Islands" 9.619647 48.12704 6.7 30 "Andaman and Nicobar Islands" 9.869018 48.12704 6.7 31 "Andaman and Nicobar Islands" 10.16049 48.12704 6.7 32 "Andaman and Nicobar Islands" 10.441525 48.12704 6.7 33 "Andaman and Nicobar Islands" 10.762144 48.12704 6.7 34 "Andaman and Nicobar Islands" 11.014033 48.12704 6.7 35 "Andaman and Nicobar Islands" 11.281036 48.12704 6.7 36 "Andaman and Nicobar Islands" 11.517812 48.12704 6.7 37 "Andaman and Nicobar Islands" 11.74631 48.12704 6.7 38 "Andaman and Nicobar Islands" 11.88341 48.12704 6.7 39 "Andaman and Nicobar Islands" 12.028788 48.12704 6.7 40 "Andaman and Nicobar Islands" 12.190716 48.12704 6.7 41 "Andaman and Nicobar Islands" 12.323137 48.12704 6.7 42 "Andaman and Nicobar Islands" 12.426413 48.12704 6.7 43 "Andaman and Nicobar Islands" 12.471394 48.12704 6.7 44 "Andaman and Nicobar Islands" 12.512415 48.12704 6.7 45 "Andaman and Nicobar Islands" 12.564232 48.12704 6.7 46 "Andaman and Nicobar Islands" 12.578626 48.12704 6.7 47 "Andaman and Nicobar Islands" 3.5940986 48.12704 6.7 48 "Andhra Pradesh" 5.471253e-06 320.4234 10.1 1 "Andhra Pradesh" .00003009189 320.4234 10.1 2 "Andhra Pradesh" .00016413757 320.4234 10.1 3 "Andhra Pradesh" .0014526175 320.4234 10.1 4 "Andhra Pradesh" .005900746 320.4234 10.1 5 "Andhra Pradesh" .009243681 320.4234 10.1 6 "Andhra Pradesh" .014745026 320.4234 10.1 7 "Andhra Pradesh" .023928523 320.4234 10.1 8 "Andhra Pradesh" .03275092 320.4234 10.1 9 "Andhra Pradesh" .0401207 320.4234 10.1 10 "Andhra Pradesh" .04784063 320.4234 10.1 11 ****current output sample Source | SS df MS Number of obs = 1,626 -------------+---------------------------------- F(66, 1559) = 34.41 Model | 8.66731228 66 .131322913 Prob > F = 0.0000 Residual | 5.95009137 1,559 .003816608 R-squared = 0.5929 -------------+---------------------------------- Adj R-squared = 0.5757 Total | 14.6174036 1,625 .008995325 Root MSE = .06178 -------------------------------------------------------------------------------- rate_dec_avg~y | Coefficient Std. err. t P>|t| [95% conf. interval] ---------------+---------------------------------------------------------------- deathrate_2019 | -.0108108 .0032851 -3.29 0.001 -.0172545 -.004367 pop_perkm~2019 | .0000149 1.66e-06 8.95 0.000 .0000116 .0000182 | weeknum | 2 | .0101325 .0222101 0.46 0.648 -.0334323 .0536972 3 | .0120695 .0214848 0.56 0.574 -.0300726 .0542116 4 | .0187394 .0211607 0.89 0.376 -.022767 .0602457 5 | .022904 .0208902 1.10 0.273 -.0180718 .0638797 6 | .025013 .0208128 1.20 0.230 -.0158111 .0658371 7 | .0251296 .0208128 1.21 0.227 -.0156945 .0659536 8 | .0252696 .0208128 1.21 0.225 -.0155545 .0660937 9 | .0247383 .0207384 1.19 0.233 -.0159399 .0654165 ............................. 46 | .1591596 .0207384 7.67 0.000 .1184814 .1998378 47 | .1601583 .0207384 7.72 0.000 .1194801 .2008365 48 | .0630753 .0207384 3.04 0.002 .0223971 .1037535 | _cons | -.1326028 .0303772 -4.37 0.000 -.1921873 -.0730183 -------------------------------------------------------------------------------
Comment