#################################################
  ## POL269: POLITICAL DATA RESEARCH
## LECTURE 3: DOES SOCIAL PRESSURE INCREASE 
## PROBABILITY OF TURNING OUT TO VOTE?
#################################################

## STEP 1. Set the working directory
setwd("~/Desktop/POL269") # example for Mac 
setwd("C:/user/Desktop/POL269") # example for Windows

## STEP 2. Load the dataset
voting <- read.csv("voting.csv") # reads and stores data

## STEP 3. Look at the data
head(voting) # shows the first six observations
## what does each observation represent?
## what is the outcome variable?
## what is the treatment variable?

## STEP 4. Create binary treatment variable
## create variable pressure inside dataframe voting
voting$pressure <- # stores return values in new variable
  ifelse(voting$message=="yes", # logical test
         1, # return value if logical test is true
         0) # return value if logical test is false
## make sure variable was created correctly
head(voting) # shows first observations

## STEP 5. Compute the difference-in-means estimator 
## practice computing and interpreting means
mean(voting$voted) # calculates the mean of voted
## interpretation?
mean(voting$voted[voting$pressure==1]) # mean for treatment group
## interpretation?
mean(voting$voted[voting$pressure==0]) # mean for control group
## interpretation?

## difference−in−means estimator
mean(voting$voted[voting$pressure==1]) - 
	mean(voting$voted[voting$pressure==0])
## direction, size, and unit of measurement?
## conclusion statement?