<> <> syntax [anything(name=detail)] <> <> set linesize 80 <> # A fuel consumption study of Stata's auto dataset We conduct a study of the fuel consumption of cars in Stata's auto dataset. ~~~~ <> sysuse auto, clear <> ~~~~ ## Perform data transformation We generate a variable, **fuel**, that measures the fuel consumption rate in the unit of Gallons per 100 Miles. ~~~~ <> generate fuel = 100/mpg label variable fuel "Fuel consumption (Gallons per 100 Miles)" <> ~~~~ <> The following explains why Gallons per 100 Mile is a better measurement than Miles per Gallon. Going from a 10 Miles per Gallon car to a 20 Miles per Gallon car saves 5 Gallons per 100 Miles when Miles per Gallon increases 10. Going from a 20 Miles per Gallon car to a 40 Miles per Gallon car *only* saves 2.5 Gallons per 100 Miles when Miles per Gallon increases 20. <> ## Examine the variables We examine variables for possible errors in the data. ~~~~ <> describe fuel weight <> ~~~~ <> assert fuel > 0 <> ~~~~ <> summarize weight <> ~~~~ The variable **weight** has minimum value <>, maximum value <>, and range <>. ## Plot fuel consumption and vehicle weight ~~~~ <> scatter fuel weight, mcolor(blue%50) <> ~~~~ <> ## Explore relationship between fuel consumption and vehicle weight - linear regression ~~~~ <> regress fuel weight <> ~~~~ <> matrix define eb = e(b) <> The regression shows that for every unit increase in weight, a <> unit increase in fuel consumption is predicted. ## Produce an HTML table from regression results <> _coef_table, markdown <> ## Produce a table from **estimates table** ~~~~ <> quietly regress fuel weight gear turn estimates store model1 quietly regress fuel weight gear turn foreign estimates store model2 estimates table model1 model2, b(%7.4f) stats(N r2_a) star <> ~~~~ <> estimates table model1 model2, varlabel b(%7.4f) stats(N r2_a) star markdown <> ## Produce a table from community-contributed **esttab** <> cap erase esttab_ex.html eststo clear <> ~~~~ <> eststo : quietly regress fuel weight gear turn eststo : quietly regress fuel weight gear turn foreign esttab using esttab_ex.html, label /// width(80%) nogaps /// mtitles("Model 1" "Model 2") /// title(Regression table using -esttab-) <> ~~~~~ <> <> cap erase esttab_ex.html <> The community-contributed **esttab** is available on the Boston College Statistical Software Components (SSC) archive; see [ssc install](https://www.stata.com/support/ssc-installation/) for details.