--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- name: log: /private[example working directory]/analysis.log log type: text opened on: 15 Oct 2026, 09:17:24 . sysuse auto, clear (1978 automobile data) . keep if !missing(price,weight,mpg) (0 observations deleted) . assert _N == 74 . file open csv using "coefficients.csv", write replace (file coefficients.csv not found) . file write csv "model,term,coefficient,standard_error,ci_lower,ci_upper,n,r_squared" _n . foreach model in baseline extended { 2. if "`model'" == "baseline" regress price weight, vce(robust) 3. else regress price weight mpg, vce(robust) 4. local terms "weight _cons" 5. if "`model'" == "extended" local terms "weight mpg _cons" 6. foreach term of local terms { 7. scalar low = _b[`term'] - invttail(e(df_r),.025)*_se[`term'] 8. scalar high = _b[`term'] + invttail(e(df_r),.025)*_se[`term'] 9. file write csv "`model',`term'," %21.15g (_b[`term']) "," %21.15g (_se[`term']) "," %21.15g (low) "," %21.15g (high) "," %12.0f (e(N)) "," %21.15g (e(r2)) _n 10. local `model'_`term'_b = strtrim(string(_b[`term'],"%9.3f")) 11. local `model'_`term'_se = strtrim(string(_se[`term'],"%9.3f")) 12. } 13. local `model'_n = strtrim(string(e(N),"%9.0f")) 14. local `model'_r2 = strtrim(string(e(r2),"%9.3f")) 15. } Linear regression Number of obs = 74 F(1, 72) = 27.51 Prob > F = 0.0000 R-squared = 0.2901 Root MSE = 2502.3 ------------------------------------------------------------------------------ | Robust price | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- weight | 2.044063 .3897465 5.24 0.000 1.267117 2.821008 _cons | -6.707353 1032.394 -0.01 0.995 -2064.747 2051.332 ------------------------------------------------------------------------------ Linear regression Number of obs = 74 F(2, 71) = 14.84 Prob > F = 0.0000 R-squared = 0.2934 Root MSE = 2514 ------------------------------------------------------------------------------ | Robust price | Coefficient std. err. t P>|t| [95% conf. interval] -------------+---------------------------------------------------------------- weight | 1.746559 .777837 2.25 0.028 .1955963 3.297522 mpg | -49.51222 95.8074 -0.52 0.607 -240.5468 141.5223 _cons | 1946.069 4213.793 0.46 0.646 -6455.995 10348.13 ------------------------------------------------------------------------------ . file close csv . capture putdocx clear . putdocx begin, pagesize(A4) font("Times New Roman",11) margin(all,2cm) . putdocx paragraph, style(Title) . putdocx text ("Regression model comparison"), font("Times New Roman",18,"000000") . putdocx paragraph . putdocx text ("Two OLS specifications estimated on the same 74 observations from Stata's bundled auto dataset. The dependent variable is price in US dollars; weight is in pounds and mpg is miles per gallon. Estimates are associations, not causal effects > .") . putdocx paragraph . putdocx table results = (9,3), width(100%) border(all,nil) . putdocx table results(1,1) = ("Variable / statistic"), bold . putdocx table results(1,2) = ("(1) Weight only"), bold . putdocx table results(1,3) = ("(2) Add mpg"), bold . putdocx table results(2,1) = ("Weight (pounds)") . putdocx table results(2,2) = ("`baseline_weight_b'") . putdocx table results(2,3) = ("`extended_weight_b'") . putdocx table results(3,2) = ("(`baseline_weight_se')") . putdocx table results(3,3) = ("(`extended_weight_se')") . putdocx table results(4,1) = ("Fuel efficiency (mpg)") . putdocx table results(4,2) = ("Not included") . putdocx table results(4,3) = ("`extended_mpg_b'") . putdocx table results(5,3) = ("(`extended_mpg_se')") . putdocx table results(6,1) = ("Constant") . putdocx table results(6,2) = ("`baseline__cons_b'") . putdocx table results(6,3) = ("`extended__cons_b'") . putdocx table results(7,2) = ("(`baseline__cons_se')") . putdocx table results(7,3) = ("(`extended__cons_se')") . putdocx table results(8,1) = ("Observations") . putdocx table results(8,2) = ("`baseline_n'") . putdocx table results(8,3) = ("`extended_n'") . putdocx table results(9,1) = ("R-squared") . putdocx table results(9,2) = ("`baseline_r2'") . putdocx table results(9,3) = ("`extended_r2'") . putdocx table results(.,2), halign(center) . putdocx table results(.,3), halign(center) . putdocx table results(1,.), border(top,single,"000000") border(bottom,single,"000000") shading("EEEEEE") . putdocx table results(9,.), border(bottom,single,"000000") . putdocx paragraph . putdocx text ("Notes: Heteroskedasticity-robust standard errors in parentheses. Both models use the complete-case sample for price, weight and mpg. Entries are rounded to three decimal places; the CSV retains calculation precision. Not included means th > e term is absent from that model, not a zero estimate. No significance stars are added.") . putdocx save "regression-table.docx", replace successfully created "/private[example working directory]/regression-table.docx" . display "WORD_TABLE_COMPLETED" WORD_TABLE_COMPLETED . log close name: log: /private[example working directory]/analysis.log log type: text closed on: 15 Oct 2026, 09:17:25 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------