--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- name: log: /private[example working directory]/analysis.log log type: text opened on: 13 Oct 2026, 16:45:25 . sysuse auto, clear (1978 automobile data) . describe price weight mpg Variable Storage Display Value name type format label Variable label --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- price int %8.0gc Price weight int %8.0gc Weight (lbs.) mpg int %8.0g Mileage (mpg) . summarize price weight mpg Variable | Obs Mean Std. dev. Min Max -------------+--------------------------------------------------------- price | 74 6165.257 2949.496 3291 15906 weight | 74 3019.459 777.1936 1760 4840 mpg | 74 21.2973 5.785503 12 41 . generate byte sample = !missing(price, weight, mpg) . tempname results . tempfile coefficients . postfile `results' str12 model str12 term double coefficient double standard_error double ci_lower double ci_upper double n double r_squared using `coefficients', replace (file /var/folders/gn/6h8ls08x1wn2btfqlhhb7qnh0000gn/T//St02978.000002 not found) . regress price weight if sample, vce(robust) 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 ------------------------------------------------------------------------------ . estimates store baseline . matrix T = r(table) . post `results' ("baseline") ("weight") (T[1,1]) (T[2,1]) (T[5,1]) (T[6,1]) (e(N)) (e(r2)) . post `results' ("baseline") ("_cons") (T[1,2]) (T[2,2]) (T[5,2]) (T[6,2]) (e(N)) (e(r2)) . regress price weight mpg if sample, vce(robust) 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 ------------------------------------------------------------------------------ . estimates store extended . matrix T = r(table) . post `results' ("extended") ("weight") (T[1,1]) (T[2,1]) (T[5,1]) (T[6,1]) (e(N)) (e(r2)) . post `results' ("extended") ("mpg") (T[1,2]) (T[2,2]) (T[5,2]) (T[6,2]) (e(N)) (e(r2)) . post `results' ("extended") ("_cons") (T[1,3]) (T[2,3]) (T[5,3]) (T[6,3]) (e(N)) (e(r2)) . postclose `results' . estimates table baseline extended, b(%9.3f) se(%9.3f) stats(N r2) -------------------------------------- Variable | baseline extended -------------+------------------------ weight | 2.044 1.747 | 0.390 0.778 mpg | -49.512 | 95.807 _cons | -6.707 1946.069 | 1032.394 4213.793 -------------+------------------------ N | 74 74 r2 | 0.290 0.293 -------------------------------------- Legend: b/se . * 用临时结果数据作图,随后恢复原数据;不把结果表误当作原始 auto。 . preserve . use `coefficients', clear . format coefficient standard_error ci_lower ci_upper %21.15g . export delimited using "coefficients.csv", replace (file coefficients.csv not found) file coefficients.csv saved . keep if term == "weight" (3 observations deleted) . generate byte model_order = cond(model == "baseline", 1, 2) . twoway (rcap ci_lower ci_upper model_order, horizontal lcolor(navy)) (scatter model_order coefficient, mcolor(navy)), ylabel(1 "Baseline" 2 "Add mpg", angle(0)) yscale(range(0.5 2.5)) ytitle("") xtitle("Weight coefficient: price per pound") xline(0, lpa > ttern(dash) lcolor(gs10)) title("Same sample, two regression models") subtitle("Robust standard errors; 95% confidence intervals; N = 74") legend(off) graphregion(color(white)) name(weight_ci, replace) . graph export "weight-ci.svg", replace (file weight-ci.svg not found) file weight-ci.svg saved as SVG format . graph export "weight-ci.png", width(1400) replace (file weight-ci.png not found) file weight-ci.png written in PNG format . restore . log close name: log: /private[example working directory]/analysis.log log type: text closed on: 13 Oct 2026, 16:45:27 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------