%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Intro to LaTeX and Template for Homework Assignments
%% Quantitative Methods in Political Science
%% University of Mannheim
%% Fall 2018
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% created by Marcel Neunhoeffer & Sebastian Sternberg
% This template and tutorial will help you to write up your homework. It will also help you to use Latex for other assignments than this course's homework.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Before we get started
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Make an account on overleaf.com and get started. No need to install anything.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Or if you want it the nerdy way...
% INSTALL LATEX: Before we can get started you need to install LaTeX on your computer.
% Windows: http://miktex.org/download
% Mac: http://www.tug.org/mactex/mactex-download.html
% There a many more different LaTeX editors out there for both operating systems. I use TeXworks because it looks the same on Windows and Mac.
% SAVE THE FILE: The first thing you need to do is to save your LaTeX file in a directory as a .tex file. You will not be able to do anything else unless your file is saved. I suggest to save the .tex file in the same folder with your .R script and where you will save your plots from R to. Let's call this file template_homework1.tex and save it in your Week 1 folder.
% COMPILE THE FILE: After setting up your file, using your LaTeX editor (texmaker, texshop), you can compile your document using PDFLaTeX.
% Compiling your file tells LaTeX to take the code you have written and create a pdf file
% After compiling your file, in your directory will appear four new files, including a .pdf file. This is your output document.
% It is good to compile your file regularly so that you can see how your code is translating into your document.
% ERRORS: If you get an error message, something is wrong in your code. Fix errors before they pile up!
% As with error messages in R, google the exact error message if you have a question!
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now again for everyone...
% COMMANDS:
% To do anything in LaTeX, you must use commands
% Commands tell LaTeX when to start your document, how you want your document to look, and how to format your document
% Commands ALWAYS begin with a backslash \
% Everything following the % sign is a comment and will not be used by Latex to compile your document.
% This is very similar to # comments in R.
% Every .tex file usually consists of four parts.
% 1. Document Class
% 2. Packages
% 3. Header
% 4. Your Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 1. Document Class
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The first command you will always have will declare your document class. This tells LaTeX what type of document you are creating (article, presentation, poster, etc).
% \documentclass is the command
% in {} you specify the type of document
% in [] you define additional parameters
\documentclass[a4paper,12pt]{article} % This defines the style of your paper
% We usually use the article type. The additional parameters are the format of the paper you want to print it on and the standard font size. For us this is a4paper and 12pt.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 2. Packages
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages are libraries of commands that LaTeX can call when compiling the document. With the specialized commands you can customize the formatting of your document.
% If the packages we call are not installed yet, TeXworks will ask you to install the necessary packages while compiling.
% First, we usually want to set the margins of our document. For this we use the package geometry. We call the package with the \usepackage command. The package goes in the {}, the parameters again go into the [].
\usepackage[top = 2.5cm, bottom = 2.5cm, left = 2.5cm, right = 2.5cm]{geometry}
% Unfortunately, LaTeX has a hard time interpreting German Umlaute. The following two lines and packages should help. If it doesn't work for you please let me know.
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
% The following two packages - multirow and booktabs - are needed to create nice looking tables.
\usepackage{multirow} % Multirow is for tables with multiple rows within one cell.
\usepackage{booktabs} % For even nicer tables.
% As we usually want to include some plots (.pdf files) we need a package for that.
\usepackage{graphicx}
% The default setting of LaTeX is to indent new paragraphs. This is useful for articles. But not really nice for homework problem sets. The following command sets the indent to 0.
\usepackage{setspace}
\setlength{\parindent}{0in}
% Package to place figures where you want them.
\usepackage{float}
% The fancyhdr package let's us create nice headers.
\usepackage{fancyhdr}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 3. Header (and Footer)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% To make our document nice we want a header and number the pages in the footer.
\pagestyle{fancy} % With this command we can customize the header style.
\fancyhf{} % This makes sure we do not have other information in our header or footer.
\lhead{\footnotesize QM: Homework 1}% \lhead puts text in the top left corner. \footnotesize sets our font to a smaller size.
%\rhead works just like \lhead (you can also use \chead)
\rhead{\footnotesize Lastname 1, Lastname 2 (\& Lastname 3)} %<---- Fill in your lastnames.
% Similar commands work for the footer (\lfoot, \cfoot and \rfoot).
% We want to put our page number in the center.
\cfoot{\footnotesize \thepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 4. Your document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Now, you need to tell LaTeX where your document starts. We do this with the \begin{document} command.
% Like brackets every \begin{} command needs a corresponding \end{} command. We come back to this later.
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Title section of the document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% For the title section we want to reproduce the title section of the Problem Set and add your names.
\thispagestyle{empty} % This command disables the header on the first page.
\begin{tabular}{p{15.5cm}} % This is a simple tabular environment to align your text nicely
{\large \bf Quantitative Methods in Political Science} \\
University of Mannheim \\ Fall 2018 \\ Traunm\"uller, Neunhoeffer \& Sternberg\\
\hline % \hline produces horizontal lines.
\\
\end{tabular} % Our tabular environment ends here.
\vspace*{0.3cm} % Now we want to add some vertical space in between the line and our title.
\begin{center} % Everything within the center environment is centered.
{\Large \bf Homework 1} % <---- Don't forget to put in the right number
\vspace{2mm}
% YOUR NAMES GO HERE
{\bf Name 1 (xx\%), Name 2 (xx\%) (\& Name 3 (xx\%))} % <---- Fill in your names here!
\end{center}
\vspace{0.4cm}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Up until this point you only have to make minor changes for every week (Number of the homework). Your write up essentially starts here.
This homework answers the problem set sequentially.
\begin{enumerate}
\item {\it Download the US Presidential Elections data set {\tt uspresidentialelections.dta} from the course ILIAS site. Load the data set in {\tt R}}. % <--- For future Homework sets you of course have to change the questions.
\begin{verbatim}
Copy your R Code to answer the question here.
\end{verbatim}
\item {\it Describe the dataset. What variables does it contain? How many observations are there? What time span does it cover?}
Please type your answer here.
\begin{verbatim}
Put the right R command here.
\end{verbatim}
\newpage % The \newpage command starts a new blank page.
\item {\it Compute measures of central tendency and variability of the variables {\tt vote} and {\tt growth} using {\tt R}. Use the numerical measures of central tendency and variability discussed in class. Describe them in your own words and make a nice table. Plot the distribution of both variables using a boxplot and histogram. Make sure to make your plots as nice-looking as possible. Especially, include a title and label the axes.}
Your answer goes here
\begin{verbatim}
3 R commands here
\end{verbatim}
Potentially, your answer continues here.
\begin{verbatim}
4 R commands here
\end{verbatim}
And more of your answer here.
\begin{verbatim}
And more space for your R commands.
\end{verbatim}
\begin{verbatim}
# This is the code to produce the first boxplot.
pdf(file = "box1.pdf")
boxplot(us_data$vote, horizontal = T,
main = "A Boxplot of the Variable Vote",
names = "Vote",
xlab = "Range of Votes")
dev.off()
\end{verbatim}
% Now we also want to include the graph in our write up.
\begin{figure}[H] % places figure environment here
\centering % Centers Graphic
\includegraphics[width=0.9\textwidth]{box1.pdf}
\caption{Boxplot of Incumbent Vote share} % Creates caption underneath graph
\end{figure}
% Now all we need to answer the question is a neat table. The easiest way to get a nice looking table is to browse to http://www.tablesgenerator.com. Generate your table just like in Word or any other WYSIWYG editor. Then copy and include the code here. I already did that for you.
\begin{table}[H]
\centering
\begin{tabular}{llllllll}
\multicolumn{1}{c}{\textbf{Variable}} & \multicolumn{1}{c}{\textit{Mean}} & \multicolumn{1}{c}{\textit{Median}} & \textit{Mode} & \textit{Var} & \textit{SD} & \textit{Range} & \textit{IQR} \\ \hline
Vote & x & x & x & x & x & x & x \\
Growth & x & x & x & x & x & x & x
\end{tabular}
\caption{Measures of central tendency and variability.}
\label{my-label}
\end{table}
% You just have to exchange the x for the right value.
\newpage
\item {\it Make a bar plot of the party affiliation of incumbent presidential candidates.}
Include the code for the bar plot and the plot here. % Don't forget to use the verbatim environment for the code.
\newpage
\item {\it During the presidential campaign in 1992, Bill Clinton's campaign coined the phrase ``It's the economy, stupid!" Let's investigate the relationship between the economy and electoral success. Generate a nice-looking scatterplot of economic growth and vote share. Label the data points with the year of the election. Describe the pattern that you see in your own words.}
Include the code for the scatterplot as well as the plot here.
Then, describe the pattern you see. In the scatterplot we can see that...
\end{enumerate}
\clearpage
\section*{R-Code}
\begin{verbatim}
Finally, copy and paste the entire script here.
\end{verbatim}
\end{document}