% prepared for statweave
% title: lesson01-outline-swv
% expansionState: 0,1,2,3,7,12,13,14,17,21,23,24,27,28,30,32,34,35,36


\section{Introduction}
\subsection{Introduction}

\begin{frame}
\frametitle{Introduction}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item This is just a small lesson for illustration

\begin{itemize}
\item Small is important
\end{itemize}
\item Most of what we need is already here

\item We'll add some code, add a figure, and move things around 
\end{itemize}
\end{frame}


\begin{frame}[fragile,]
\frametitle{Starting Up}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item We'll use the \stliteral{auto} dataset
\begin{Winput}
. sysuse auto
\end{Winput}

\mode
<article>
\begin{Woutput}
(1978 Automobile Data)
\end{Woutput}

\mode
<all>


\item As we all know, this is a US-centric dataset about old cars

\item We would like to make the dataset metric-friendly

\item We would like to model energy consumption of these ancient cars
\end{itemize}
\end{frame}



\section{Basics}
\subsection{Data Management and EDA}

\begin{frame}[fragile,]
\frametitle{\index{analysis|(}%
\index{metric system}Converting the Data to a Reasonable System}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item We'd like to make the dataset metric-friendly

\item We'll run the conversion code in the lesson, but show it only in the handouts
\mode
<article>
\begin{Winput}
. // Changing mpg to liter/100km
. ** 1 mile = 1.609 km; 1 gallon = 3.7854 liters
. gen lp100km = 100/(mpg*(1.609 / 3.7854))
. label var lp100km "Liters per 100km"
. 
. // Trunk size in liters
. rename trunk trunk_cuft
. ** 1 inch = 2.54 cm, 1 foot = 12 inches, 1000 cc = 1 liter
. gen trunk = (trunk_cuft*(12*2.54)^3)/1000
. label var trunk "Trunk capacity (liters)"
. 
. // Weight in Kilos
. ** 1kg = 2.205 lb
. rename weight weight_lb
. gen weight = weight_lb / 2.205
. label var weight "Weight in kg"
. 
. // Length in cm
. rename length length_in
. gen length_cm = length_in * 2.54
. label var length_cm "Length in cm"
. 
. // Turning radius in cm
. rename turn turn_circ_ft
. gen turn_rad = round((turn_circ_ft * 12 * 2.54)/(2*c(pi)))
. label var turn_rad "Turning radius in cm"
. 
. // Displacement in cc
. rename displacement displacement_cuin
. gen displacement = displacement_cuin * 2.54^3
. label var displacement "Displacement in cc"
\end{Winput}


\mode
<all>

\end{itemize}
\end{frame}


\begin{frame}[fragile,]
\frametitle{A Peek at the Dataset}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item Here is the structure of our new dataset
\begin{Winput}
. describe
\end{Winput}

\mode
<article>
\begin{Woutput}
Contains data from /Applications/Stata/ado/base/a/auto.dta
  obs:            74                          1978 Automobile Data
 vars:            18                          13 Apr 2014 17:45
 size:         4,958                          (_dta has notes)
--------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------------------------
make            str18   %-18s                 Make and Model
price           int     %8.0gc                Price
mpg             int     %8.0g                 Mileage (mpg)
rep78           int     %8.0g                 Repair Record 1978
headroom        float   %6.1f                 Headroom (in.)
trunk_cuft      int     %8.0g                 Trunk space (cu. ft.)
weight_lb       int     %8.0gc                Weight (lbs.)
length_in       int     %8.0g                 Length (in.)
turn_circ_ft    int     %8.0g                 Turn Circle (ft.)
displacement_~n int     %8.0g                 Displacement (cu. in.)
gear_ratio      float   %6.2f                 Gear Ratio
foreign         byte    %8.0g      origin     Car type
lp100km         float   %9.0g                 Liters per 100km
trunk           float   %9.0g                 Trunk capacity (liters)
weight          float   %9.0g                 Weight in kg
length_cm       float   %9.0g                 Length in cm
turn_rad        float   %9.0g                 Turning radius in cm
displacement    float   %9.0g                 Displacement in cc
--------------------------------------------------------------------------------
Sorted by: foreign
     Note: Dataset has changed since last saved.
\end{Woutput}

\mode
<all>


\item Here are the summary statistics
\begin{Winput}
. summarize
\end{Winput}

\mode
<article>
\begin{Woutput}
    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        make |          0
       price |         74    6165.257    2949.496       3291      15906
         mpg |         74     21.2973    5.785503         12         41
       rep78 |         69    3.405797    .9899323          1          5
    headroom |         74    2.993243    .8459948        1.5          5
-------------+---------------------------------------------------------
  trunk_cuft |         74    13.75676    4.277404          5         23
   weight_lb |         74    3019.459    777.1936       1760       4840
   length_in |         74    187.9324    22.26634        142        233
turn_circ_ft |         74    39.64865    4.399354         31         51
displaceme~n |         74    197.2973    91.83722         79        425
-------------+---------------------------------------------------------
  gear_ratio |         74    3.014865    .4562871       2.19       3.89
     foreign |         74    .2972973    .4601885          0          1
     lp100km |         74    11.80857    3.011042    5.73815   19.60534
       trunk |         74     389.548    121.1226   141.5842   651.2875
      weight |         74    1369.369    352.4687   798.1859   2195.011
-------------+---------------------------------------------------------
   length_cm |         74    477.3484     56.5565     360.68     591.82
    turn_rad |         74    192.4054    21.33934        150        247
displacement |         74    3233.123    1504.942   1294.578   6964.502
\end{Woutput}

\mode
<all>


\item We now should look closer
\end{itemize}
\end{frame}


\begin{frame}[fragile,]
\frametitle{A Graph Matrix}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item We can look at dependencies
\begin{Winput}
. graph matrix lp100km weight displacement foreign
\end{Winput}


% found a figure which wants to be output...

\mode
<presentation>

\begin{center}
{\includegraphics[height=\presgphht,keepaspectratio=TRUE]{\pathprefix/Graphics/grmat}
}

\end{center}
\mode
<all>
\mode
<article>

\begin{center}
{\includegraphics[height=\handgphht,keepaspectratio=TRUE]{\pathprefix/Graphics/grmat}
}
\end{center}
\mode
<all>

\end{itemize}
\end{frame}

\subsection{Basic Analysis}

\begin{frame}[fragile,]
\frametitle{A Simple Model}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item From our graph, it appears we should try
\begin{Winput}
. regress lp100km weight displacement foreign
\end{Winput}

\mode
<article>
\begin{Woutput}
      Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(3, 70)        =     76.33
       Model |  506.885959         3  168.961986   Prob > F        =    0.0000
    Residual |  154.959261        70  2.21370372   R-squared       =    0.7659
-------------+----------------------------------   Adj R-squared   =    0.7558
       Total |   661.84522        73  9.06637287   Root MSE        =    1.4879

------------------------------------------------------------------------------
     lp100km |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |    .007496   .0011156     6.72   0.000     .0052709    .0097211
displacement |   .0002677   .0002665     1.00   0.319    -.0002639    .0007993
     foreign |   1.575823   .4830161     3.26   0.002     .6124776    2.539168
       _cons |   .2097918   1.019557     0.21   0.838    -1.823651    2.243235
------------------------------------------------------------------------------
\end{Woutput}

\mode
<all>


\item The coefficient of weight is 0.00750 with a $p$-value of 0.00000000
\end{itemize}
\end{frame}


\begin{frame}
\frametitle{Some Great Explanations}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item Heavier cars use more gas

\begin{itemize}
\item After adjusting for engine size and place of manufacture
\end{itemize}
\item Non-US made cars use more gas

\begin{itemize}
\item After adjusting for weight and engine size
\end{itemize}
\item Engine size is not important

\begin{itemize}
\item After adjusting for weight and place of manufacture
\end{itemize}\end{itemize}\index{analysis|)}
\end{frame}



\section{Conclusion}
\subsection{Conclusion}

\begin{frame}
\frametitle{Conclusion}\stepcounter{handoutframe}\zlabel{\thisFileName:slide:\thehandoutframe}

\begin{itemize}
\item These results are interesting

\item We could make the results more interesting with more grant money
\end{itemize}
\end{frame}

